commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1291410 - in /commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan: common/ formats/jpeg/ formats/jpeg/exif/ formats/jpeg/iptc/ formats/jpeg/segments/ formats/jpeg/xmp/
Date Mon, 20 Feb 2012 18:53:24 GMT
Author: damjan
Date: Mon Feb 20 18:53:24 2012
New Revision: 1291410

URL: http://svn.apache.org/viewvc?rev=1291410&view=rev
Log:
Hide some arrays constants.

Jira issue key: SANSELAN-42


Added:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConstant.java
  (with props)
Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileFunctions.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileParser.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/iptc/IptcParser.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/JfifSegment.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegRewriter.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpParser.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConstant.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConstant.java?rev=1291410&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConstant.java
(added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConstant.java
Mon Feb 20 18:53:24 2012
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.sanselan.common;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
+
+public class BinaryConstant implements Cloneable {
+    private final byte[] value;
+    
+    public BinaryConstant(byte[] value) {
+        this.value = value.clone();
+    }
+    
+    @Override
+    public BinaryConstant clone() throws CloneNotSupportedException {
+        return new BinaryConstant(value);
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof BinaryConstant)) {
+            return false;
+        }
+        BinaryConstant other = (BinaryConstant)obj;
+        return equals(other.value);
+    }
+    
+    public boolean equals(byte[] bytes) {
+        return Arrays.equals(value, bytes);
+    }
+    
+    @Override
+    public int hashCode() {
+        return Arrays.hashCode(value);
+    }
+    
+    public byte get(int i) {
+        return value[i];
+    }
+    
+    public int size() {
+        return value.length;
+    }
+    
+    public byte[] toByteArray() {
+        return value.clone();
+    }
+    
+    public void writeTo(OutputStream os) throws IOException {
+        for (int i = 0; i < value.length; i++) {
+            os.write(value[i]);
+        }
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConstant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileFunctions.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileFunctions.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileFunctions.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileFunctions.java
Mon Feb 20 18:53:24 2012
@@ -116,7 +116,7 @@ public class BinaryFileFunctions impleme
         }
         return result;
     }
-
+    
     public final void readAndVerifyBytes(InputStream is, byte expected[],
             String exception) throws ImageReadException, IOException
     {
@@ -141,6 +141,22 @@ public class BinaryFileFunctions impleme
         }
     }
 
+    public final void readAndVerifyBytes(InputStream is, BinaryConstant expected,
+            String exception) throws ImageReadException, IOException
+    {
+        for (int i = 0; i < expected.size(); i++)
+        {
+            int data = is.read();
+            byte b = (byte) (0xff & data);
+
+            if (data < 0)
+                throw new ImageReadException("Unexpected EOF.");
+
+            if (b != expected.get(i))
+                throw new ImageReadException(exception);
+        }
+    }
+
     protected final void readAndVerifyBytes(String name, InputStream is,
             byte expected[], String exception) throws ImageReadException,
             IOException

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileParser.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileParser.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryFileParser.java
Mon Feb 20 18:53:24 2012
@@ -103,6 +103,17 @@ public class BinaryFileParser extends Bi
         return read2Bytes(name, is, exception, byteOrder);
     }
 
+    public static boolean byteArrayHasPrefix(byte bytes[], BinaryConstant prefix) {
+        if ((bytes == null) || (bytes.length < prefix.size()))
+            return false;
+
+        for (int i = 0; i < prefix.size(); i++)
+            if (bytes[i] != prefix.get(i))
+                return false;
+
+        return true;
+    }
+    
     public static boolean byteArrayHasPrefix(byte bytes[], byte prefix[])
     {
         if ((bytes == null) || (bytes.length < prefix.length))

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegConstants.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegConstants.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegConstants.java
Mon Feb 20 18:53:24 2012
@@ -16,33 +16,39 @@
  */
 package org.apache.commons.sanselan.formats.jpeg;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.sanselan.common.BinaryConstant;
+
 public interface JpegConstants
 {
     public static final int MAX_SEGMENT_SIZE = 0xffff;
 
-    public static final byte JFIF0_SIGNATURE[] = new byte[] { //
+    public static final BinaryConstant JFIF0_SIGNATURE = new BinaryConstant(new byte[] {
             0x4a, // J
             0x46, // F
             0x49, // I
             0x46, // F
             0x0, //
-    };
-    public static final byte JFIF0_SIGNATURE_ALTERNATIVE[] = new byte[] { //
+    });
+    public static final BinaryConstant JFIF0_SIGNATURE_ALTERNATIVE = new BinaryConstant(new
byte[] {
             0x4a, // J
             0x46, // F
             0x49, // I
             0x46, // F
             0x20, //
-    };
+    });
 
-    public static final byte EXIF_IDENTIFIER_CODE[] = { //
+    public static final BinaryConstant EXIF_IDENTIFIER_CODE = new BinaryConstant(new byte[]
{
             0x45, // E
             0x78, // x
             0x69, // i
             0x66, // f
-    };
+    });
 
-    public static final byte XMP_IDENTIFIER[] = { //
+    public static final BinaryConstant XMP_IDENTIFIER = new BinaryConstant(new byte[] {
             0x68, // h
             0x74, // t
             0x74, // t
@@ -72,17 +78,14 @@ public interface JpegConstants
             0x30, // 0
             0x2F, // /
             0, // 0-terminated us-ascii string.
-    };
+    });
 
-    public static final byte SOI[] = new byte[] { (byte) 0xff, (byte) 0xd8 };
-    public static final byte EOI[] = new byte[] { (byte) 0xff, (byte) 0xd9 };
+    public static final BinaryConstant SOI = new BinaryConstant(new byte[] { (byte) 0xff,
(byte) 0xd8 });
+    public static final BinaryConstant EOI = new BinaryConstant(new byte[] { (byte) 0xff,
(byte) 0xd9 });
 
     public static final int JPEG_APP0 = 0xE0;
-    // public static final int JPEG_APP1 = JPEG_APP0 + 1;
-    // public static final int JPEG_APP1_Marker = (0xff00) | JPEG_APP1;
     public static final int JPEG_APP0_Marker = (0xff00) | (JPEG_APP0);
     public static final int JPEG_APP1_Marker = (0xff00) | (JPEG_APP0 + 1);
-    // public static final int JPEG_APP2 = ;
     public static final int JPEG_APP2_Marker = (0xff00) | (JPEG_APP0 + 2);
     public static final int JPEG_APP13_Marker = (0xff00) | (JPEG_APP0 + 13);
     public static final int JPEG_APP14_Marker = (0xff00) | (JPEG_APP0 + 14);
@@ -112,19 +115,22 @@ public interface JpegConstants
     public static final int DNLMarker = 0xFFdc;
     public static final int COMMarker = 0xFFfe;
 
-    public static final int MARKERS[] = { JPEG_APP0,
-            JPEG_APP0_Marker, JPEG_APP1_Marker, JPEG_APP2_Marker,
+    public static final List<Integer> MARKERS = Collections.unmodifiableList(Arrays.asList(
+            JPEG_APP0, JPEG_APP0_Marker, JPEG_APP1_Marker, JPEG_APP2_Marker,
             JPEG_APP13_Marker, JPEG_APP14_Marker, JPEG_APP15_Marker,
             JFIFMarker, SOF0Marker, SOF1Marker, SOF2Marker, SOF3Marker,
             DHTMarker, SOF5Marker, SOF6Marker, SOF7Marker, SOF8Marker,
             SOF9Marker, SOF10Marker, SOF11Marker, DACMarker, SOF13Marker,
             SOF14Marker, SOF15Marker, EOIMarker, SOS_Marker,
-            DQTMarker, DNLMarker, COMMarker };
+            DQTMarker, DNLMarker, COMMarker ));
 
-    public static final byte icc_profile_label[] = { 0x49, 0x43, 0x43, 0x5F,
-            0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45, 0x0 };
+    public static final BinaryConstant icc_profile_label = new BinaryConstant(new byte[]
{
+            0x49, 0x43, 0x43, 0x5F,
+            0x50, 0x52, 0x4F, 0x46,
+            0x49, 0x4C, 0x45, 0x0
+    });
 
-    public static final byte PHOTOSHOP_IDENTIFICATION_STRING[] = { //
+    public static final BinaryConstant PHOTOSHOP_IDENTIFICATION_STRING = new BinaryConstant(new
byte[] {
             0x50, // P
             0x68, // h
             0x6F, // o
@@ -139,12 +145,11 @@ public interface JpegConstants
             0x2E, // .
             0x30, // 0
             0,
-    };
-    public static final byte CONST_8BIM[] = { //
+    });
+    public static final BinaryConstant CONST_8BIM = new BinaryConstant(new byte[] {
             0x38, // 8
             0x42, // B
             0x49, // I
             0x4D, // M
-    };
-
+    });
 }

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
Mon Feb 20 18:53:24 2012
@@ -471,7 +471,7 @@ public class ExifRewriter extends Binary
 
         try
         {
-            os.write(SOI);
+            SOI.writeTo(os);
 
             boolean hasExif = false;
 
@@ -565,7 +565,7 @@ public class ExifRewriter extends Binary
 
         if (includeEXIFPrefix)
         {
-            os.write(EXIF_IDENTIFIER_CODE);
+            EXIF_IDENTIFIER_CODE.writeTo(os);
             os.write(0);
             os.write(0);
         }

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/iptc/IptcParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/iptc/IptcParser.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/iptc/IptcParser.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/iptc/IptcParser.java
Mon Feb 20 18:53:24 2012
@@ -20,6 +20,7 @@ package org.apache.commons.sanselan.form
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
@@ -28,6 +29,7 @@ import java.util.Map;
 import org.apache.commons.sanselan.ImageReadException;
 import org.apache.commons.sanselan.ImageWriteException;
 import org.apache.commons.sanselan.SanselanConstants;
+import org.apache.commons.sanselan.common.BinaryFileFunctions;
 import org.apache.commons.sanselan.common.BinaryFileParser;
 import org.apache.commons.sanselan.common.BinaryInputStream;
 import org.apache.commons.sanselan.common.BinaryOutputStream;
@@ -45,16 +47,14 @@ public class IptcParser extends BinaryFi
 
     public boolean isPhotoshopJpegSegment(byte segmentData[])
     {
-        if (!compareByteArrays(segmentData, 0, PHOTOSHOP_IDENTIFICATION_STRING,
-                0, PHOTOSHOP_IDENTIFICATION_STRING.length))
+        if (!BinaryFileParser.byteArrayHasPrefix(segmentData, PHOTOSHOP_IDENTIFICATION_STRING))
             return false;
 
-        int index = PHOTOSHOP_IDENTIFICATION_STRING.length;
-        if (index + CONST_8BIM.length > segmentData.length)
+        int index = PHOTOSHOP_IDENTIFICATION_STRING.size();
+        if (index + CONST_8BIM.size() > segmentData.length)
             return false;
 
-        if (!compareByteArrays(segmentData, index, CONST_8BIM, 0,
-                CONST_8BIM.length))
+        if (!CONST_8BIM.equals(Arrays.copyOfRange(segmentData, index, index + CONST_8BIM.size())))
             return false;
 
         return true;
@@ -267,9 +267,9 @@ public class IptcParser extends BinaryFi
         // number of bytes (including the 1st byte, which is the size.)
 
         byte[] idString = bis.readByteArray(
-                PHOTOSHOP_IDENTIFICATION_STRING.length,
+                PHOTOSHOP_IDENTIFICATION_STRING.size(),
                 "App13 Segment missing identification string");
-        if (!compareByteArrays(idString, PHOTOSHOP_IDENTIFICATION_STRING))
+        if (!PHOTOSHOP_IDENTIFICATION_STRING.equals(idString))
             throw new ImageReadException("Not a Photoshop App13 Segment");
 
         // int index = PHOTOSHOP_IDENTIFICATION_STRING.length;
@@ -277,12 +277,12 @@ public class IptcParser extends BinaryFi
         while (true)
         {
             byte[] imageResourceBlockSignature = bis
-                    .readByteArray(CONST_8BIM.length,
+                    .readByteArray(CONST_8BIM.size(),
                             "App13 Segment missing identification string",
                             false, false);
             if (null == imageResourceBlockSignature)
                 break;
-            if (!compareByteArrays(imageResourceBlockSignature, CONST_8BIM))
+            if (!CONST_8BIM.equals(imageResourceBlockSignature))
                 throw new ImageReadException(
                         "Invalid Image Resource Block Signature");
 
@@ -351,14 +351,14 @@ public class IptcParser extends BinaryFi
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         BinaryOutputStream bos = new BinaryOutputStream(os);
 
-        bos.write(PHOTOSHOP_IDENTIFICATION_STRING);
+        PHOTOSHOP_IDENTIFICATION_STRING.writeTo(bos);
 
         List<IptcBlock> blocks = data.getRawBlocks();
         for (int i = 0; i < blocks.size(); i++)
         {
             IptcBlock block = blocks.get(i);
 
-            bos.write(CONST_8BIM);
+            CONST_8BIM.writeTo(bos);
 
             if (block.blockType < 0 || block.blockType > 0xffff)
                 throw new ImageWriteException("Invalid IPTC block type.");

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
Mon Feb 20 18:53:24 2012
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.sanselan.ImageReadException;
+import org.apache.commons.sanselan.common.BinaryFileParser;
 import org.apache.commons.sanselan.formats.jpeg.JpegImageParser;
 
 public class App2Segment extends AppnSegment implements Comparable<App2Segment>
@@ -39,7 +40,7 @@ public class App2Segment extends AppnSeg
     {
         super(marker, marker_length, is2);
 
-        if (startsWith(bytes, JpegImageParser.icc_profile_label))
+        if (BinaryFileParser.byteArrayHasPrefix(bytes, JpegImageParser.icc_profile_label))
         {
             InputStream is = new ByteArrayInputStream(bytes);
 
@@ -49,7 +50,7 @@ public class App2Segment extends AppnSeg
             cur_marker = readByte("cur_marker", is, "Not a valid App2 Marker");
             num_markers = readByte("num_markers", is, "Not a valid App2 Marker");
 
-            marker_length -= JpegImageParser.icc_profile_label.length;
+            marker_length -= JpegImageParser.icc_profile_label.size();
             marker_length -= (1 + 1);
 
             icc_bytes = readByteArray("App2 Data", marker_length, is,

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/JfifSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/JfifSegment.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/JfifSegment.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/JfifSegment.java
Mon Feb 20 18:53:24 2012
@@ -51,9 +51,9 @@ public class JfifSegment extends Segment
     {
         super(marker, marker_length);
 
-        byte signature[] = readBytes(is, JFIF0_SIGNATURE.length);
-        if (!compareByteArrays(signature, JFIF0_SIGNATURE)
-                && !compareByteArrays(signature, JFIF0_SIGNATURE_ALTERNATIVE))
+        byte signature[] = readBytes(is, JFIF0_SIGNATURE.size());
+        if (!JFIF0_SIGNATURE.equals(signature)
+                && !JFIF0_SIGNATURE_ALTERNATIVE.equals(signature))
             throw new ImageReadException(
                     "Not a Valid JPEG File: missing JFIF string");
 

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegRewriter.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegRewriter.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegRewriter.java
Mon Feb 20 18:53:24 2012
@@ -342,7 +342,7 @@ public class JpegRewriter extends Binary
     {
         try
         {
-            os.write(SOI);
+            SOI.writeTo(os);
 
             for (int i = 0; i < segments.size(); i++)
             {

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpParser.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpParser.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpParser.java
Mon Feb 20 18:53:24 2012
@@ -34,28 +34,17 @@ public class JpegXmpParser extends Binar
 
     public boolean isXmpJpegSegment(byte segmentData[])
     {
-        int index = 0;
-
-        if (segmentData.length < XMP_IDENTIFIER.length)
-            return false;
-        for (; index < XMP_IDENTIFIER.length; index++)
-            if (segmentData[index] < XMP_IDENTIFIER[index])
-                return false;
-
-        return true;
+        return BinaryFileParser.byteArrayHasPrefix(segmentData, XMP_IDENTIFIER);
     }
 
     public String parseXmpJpegSegment(byte segmentData[])
             throws ImageReadException
     {
-        int index = 0;
-
-        if (segmentData.length < XMP_IDENTIFIER.length)
+        if (!isXmpJpegSegment(segmentData)) {
             throw new ImageReadException("Invalid JPEG XMP Segment.");
-        for (; index < XMP_IDENTIFIER.length; index++)
-            if (segmentData[index] < XMP_IDENTIFIER[index])
-                throw new ImageReadException("Invalid JPEG XMP Segment.");
-
+        }
+        int index = XMP_IDENTIFIER.size();
+        
         try
         {
             // segment data is UTF-8 encoded xml.

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java?rev=1291410&r1=1291409&r2=1291410&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java
Mon Feb 20 18:53:24 2012
@@ -210,7 +210,7 @@ public class JpegXmpRewriter extends Jpe
     {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
 
-        os.write(XMP_IDENTIFIER);
+        XMP_IDENTIFIER.writeTo(os);
         os.write(xmpXmlData, start, length);
 
         return os.toByteArray();



Mime
View raw message