commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1441873 - in /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging: common/FastByteArrayOutputStream.java formats/jpeg/JpegConstants.java formats/jpeg/iptc/IptcParser.java
Date Sun, 03 Feb 2013 08:44:08 GMT
Author: damjan
Date: Sun Feb  3 08:44:07 2013
New Revision: 1441873

URL: http://svn.apache.org/viewvc?rev=1441873&view=rev
Log:
Cleanups.


Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java?rev=1441873&r1=1441872&r2=1441873&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java
Sun Feb  3 08:44:07 2013
@@ -48,7 +48,8 @@ public class FastByteArrayOutputStream e
             System.arraycopy(bytes, 0, result, 0, count);
             return result;
         }
-        return bytes;
+        final byte[] result = bytes;
+        return result;
     }
 
     public int getBytesWritten() {

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java?rev=1441873&r1=1441872&r2=1441873&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java
Sun Feb  3 08:44:07 2013
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.commons.imaging.common.BinaryConstant;
+import org.apache.commons.imaging.common.BinaryFunctions;
 
 public interface JpegConstants {
     public static final int MAX_SEGMENT_SIZE = 0xffff;
@@ -145,10 +146,5 @@ public interface JpegConstants {
                     0x2E, // .
                     0x30, // 0
                     0, });
-    public static final BinaryConstant CONST_8BIM = new BinaryConstant(
-            new byte[] { 0x38, // 8
-                    0x42, // B
-                    0x49, // I
-                    0x4D, // M
-            });
+    public static final int CONST_8BIM = BinaryFunctions.charsToQuad('8', 'B', 'I', 'M');
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java?rev=1441873&r1=1441872&r2=1441873&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
Sun Feb  3 08:44:07 2013
@@ -31,6 +31,7 @@ import org.apache.commons.imaging.Imagin
 import org.apache.commons.imaging.common.BinaryFileParser;
 import org.apache.commons.imaging.common.BinaryInputStream;
 import org.apache.commons.imaging.common.BinaryOutputStream;
+import org.apache.commons.imaging.common.ByteConversions;
 import org.apache.commons.imaging.common.ByteOrder;
 import org.apache.commons.imaging.util.Debug;
 import org.apache.commons.imaging.util.ParamMap;
@@ -49,15 +50,8 @@ public class IptcParser extends BinaryFi
         }
 
         final int index = PHOTOSHOP_IDENTIFICATION_STRING.size();
-        if (index + CONST_8BIM.size() > segmentData.length) {
-            return false;
-        }
-
-        if (!CONST_8BIM.equals(segmentData, index, CONST_8BIM.size())) {
-            return false;
-        }
-
-        return true;
+        return (index + 4) <= segmentData.length &&
+                ByteConversions.toInt(segmentData, APP13_BYTE_ORDER) == CONST_8BIM;
     }
 
     /*
@@ -282,15 +276,9 @@ public class IptcParser extends BinaryFi
             // int index = PHOTOSHOP_IDENTIFICATION_STRING.length;
     
             while (true) {
-                final byte[] imageResourceBlockSignature;
-                try {
-                    imageResourceBlockSignature = bis.readBytes(
-                            CONST_8BIM.size(),
-                            "App13 Segment missing identification string");
-                } catch (IOException ioEx) {
-                    break;
-                }
-                if (!CONST_8BIM.equals(imageResourceBlockSignature)) {
+                final int imageResourceBlockSignature = bis.read4Bytes(
+                        "App13 Segment missing identification string");
+                if (imageResourceBlockSignature != CONST_8BIM) {
                     throw new ImageReadException(
                             "Invalid Image Resource Block Signature");
                 }
@@ -384,7 +372,7 @@ public class IptcParser extends BinaryFi
         for (int i = 0; i < blocks.size(); i++) {
             final IptcBlock block = blocks.get(i);
 
-            CONST_8BIM.writeTo(bos);
+            bos.write4Bytes(CONST_8BIM);
 
             if (block.blockType < 0 || block.blockType > 0xffff) {
                 throw new ImageWriteException("Invalid IPTC block type.");



Mime
View raw message