commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1534492 - in /commons/proper/imaging/trunk/src: changes/ main/java/org/apache/commons/imaging/formats/jpeg/ main/java/org/apache/commons/imaging/formats/jpeg/segments/
Date Tue, 22 Oct 2013 04:52:07 GMT
Author: damjan
Date: Tue Oct 22 04:52:07 2013
New Revision: 1534492

URL: http://svn.apache.org/r1534492
Log:
Encapsulate GenericSegment's byte array.

Jira issue key: IMAGING-116


Modified:
    commons/proper/imaging/trunk/src/changes/changes.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App14Segment.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java

Modified: commons/proper/imaging/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1534492&r1=1534491&r2=1534492&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/changes/changes.xml (original)
+++ commons/proper/imaging/trunk/src/changes/changes.xml Tue Oct 22 04:52:07 2013
@@ -46,6 +46,9 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="1.0" date="TBA" description="TBA">
+      <action issue="IMAGING-116" dev="damjan" type="fix">
+        GenericSegment.bytes - public mutable array.
+      </action>
       <action issue="IMAGING-118" dev="damjan" type="fix">
         interface RgbeConstants contains mutable array.
       </action>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java?rev=1534492&r1=1534491&r2=1534492&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java
Tue Oct 22 04:52:07 2013
@@ -321,7 +321,7 @@ public class JpegImageParser extends Ima
     }
 
     public static boolean isExifAPP1Segment(final GenericSegment segment) {
-        return startsWith(segment.bytes, EXIF_IDENTIFIER_CODE);
+        return startsWith(segment.getSegmentData(), EXIF_IDENTIFIER_CODE);
     }
 
     private List<Segment> filterAPP1Segments(final List<Segment> v) {
@@ -384,7 +384,7 @@ public class JpegImageParser extends Ima
         }
 
         final GenericSegment segment = (GenericSegment) exifSegments.get(0);
-        final byte bytes[] = segment.bytes;
+        final byte bytes[] = segment.getSegmentData();
 
         // byte head[] = readBytearray("exif head", bytes, 0, 6);
         //

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java?rev=1534492&r1=1534491&r2=1534492&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
Tue Oct 22 04:52:07 2013
@@ -59,7 +59,7 @@ public class App13Segment extends AppnSe
     }
 
     public boolean isPhotoshopJpegSegment() {
-        return new IptcParser().isPhotoshopJpegSegment(bytes);
+        return new IptcParser().isPhotoshopJpegSegment(getSegmentData());
     }
 
     public PhotoshopApp13Data parsePhotoshopSegment(final Map<String,Object> params)
@@ -73,6 +73,6 @@ public class App13Segment extends AppnSe
             return null;
         }
 
-        return new IptcParser().parsePhotoshopSegment(bytes, params);
+        return new IptcParser().parsePhotoshopSegment(getSegmentData(), params);
     }
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App14Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App14Segment.java?rev=1534492&r1=1534491&r2=1534492&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App14Segment.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App14Segment.java
Tue Oct 22 04:52:07 2013
@@ -53,10 +53,10 @@ public class App14Segment extends AppnSe
     }
 
     public boolean isAdobeJpegSegment() {
-        return BinaryFileParser.startsWith(bytes, adobePrefix);
+        return BinaryFileParser.startsWith(getSegmentData(), adobePrefix);
     }
 
     public int getAdobeColorTransform() {
-        return 0xff & bytes[11];
+        return 0xff & segmentData[11];
     }
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java?rev=1534492&r1=1534491&r2=1534492&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java
Tue Oct 22 04:52:07 2013
@@ -37,9 +37,9 @@ public class App2Segment extends AppnSeg
             throws ImageReadException, IOException {
         super(marker, marker_length, is2);
 
-        if (BinaryFileParser.startsWith(bytes,
+        if (BinaryFileParser.startsWith(getSegmentData(),
                 JpegImageParser.icc_profile_label)) {
-            final InputStream is = new ByteArrayInputStream(bytes);
+            final InputStream is = new ByteArrayInputStream(getSegmentData());
 
             readAndVerifyBytes(is, JpegImageParser.icc_profile_label,
                     "Not a Valid App2 Segment: missing ICC Profile label");

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java?rev=1534492&r1=1534491&r2=1534492&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
Tue Oct 22 04:52:07 2013
@@ -16,43 +16,33 @@
  */
 package org.apache.commons.imaging.formats.jpeg.segments;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 
-public class ComSegment extends Segment {
-    private final byte[] comment;
-
+public class ComSegment extends GenericSegment {
     public ComSegment(final int marker, final byte segmentData[]) throws IOException {
-        this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
+        super(marker, segmentData);
     }
 
     public ComSegment(final int marker, final int marker_length, final InputStream is)
             throws IOException {
-        super(marker, marker_length);
-
-        if (getDebug()) {
-            System.out.println("ComSegment marker_length: " + marker_length);
-        }
-
-        comment = readBytes("Comment", is, marker_length,
-                "Error reading JPEG comment");
-
-        if (getDebug()) {
-            System.out.println("");
-        }
+        super(marker, marker_length, is);
     }
     
+    /**
+     * Returns a copy of the comment.
+     * @return a copy of the comment's bytes
+     */
     public byte[] getComment() {
-        return comment;
+        return getSegmentData();
     }
 
     @Override
     public String getDescription() {
         String commentString = "";
         try {
-            commentString = new String(comment, "UTF-8");
+            commentString = new String(segmentData, "UTF-8");
         } catch (final UnsupportedEncodingException cannotHappen) {
         }
         return "COM (" + commentString + ")";

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java?rev=1534492&r1=1534491&r2=1534492&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java
Tue Oct 22 04:52:07 2013
@@ -21,20 +21,20 @@ import java.io.InputStream;
 import java.io.PrintWriter;
 
 public abstract class GenericSegment extends Segment {
-    public final byte bytes[];
+    protected final byte segmentData[];
 
     public GenericSegment(final int marker, final int marker_length, final InputStream is)
             throws IOException {
         super(marker, marker_length);
 
-        bytes = readBytes("Segment Data", is, marker_length,
+        segmentData = readBytes("Segment Data", is, marker_length,
                 "Invalid Segment: insufficient data");
     }
 
     public GenericSegment(final int marker, final byte bytes[]) {
         super(marker, bytes.length);
 
-        this.bytes = bytes;
+        this.segmentData = bytes;
     }
 
     @Override
@@ -43,11 +43,21 @@ public abstract class GenericSegment ext
     }
 
     public void dump(final PrintWriter pw, final int start) {
-        for (int i = 0; (i < 50) && ((i + start) < bytes.length); i++) {
-            debugNumber(pw, "\t" + (i + start), bytes[i + start]);
+        for (int i = 0; (i < 50) && ((i + start) < segmentData.length); i++)
{
+            debugNumber(pw, "\t" + (i + start), segmentData[i + start]);
         }
     }
 
+    /**
+     * Returns a copy of the segment's contents,
+     * excluding the marker and length bytes at
+     * the beginning.
+     * @return the segment's contents
+     */
+    public byte[] getSegmentData() {
+        return segmentData.clone();
+    }
+
     // public String getDescription()
     // {
     // return "Unknown";



Mime
View raw message