src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java

Print this page
rev 9292 : 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
Reviewed-by: darcy, prr

@@ -74,11 +74,11 @@
     int Xdensity;
     int Ydensity;
     int thumbWidth;
     int thumbHeight;
     JFIFThumbRGB thumb = null;  // If present
-    ArrayList extSegments = new ArrayList();
+    ArrayList<JFIFExtensionMarkerSegment> extSegments = new ArrayList<>();
     ICCMarkerSegment iccSegment = null; // optional ICC
     private static final int THUMB_JPEG = 0x10;
     private static final int THUMB_PALETTE = 0x11;
     private static final int THUMB_UNASSIGNED = 0x12;
     private static final int THUMB_RGB = 0x13;

@@ -152,22 +152,21 @@
     }
 
     /**
      * Returns a deep-copy clone of this object.
      */
-    protected Object clone() {
+    protected JFIFMarkerSegment clone() {
         JFIFMarkerSegment newGuy = (JFIFMarkerSegment) super.clone();
         if (!extSegments.isEmpty()) { // Clone the list with a deep copy
-            newGuy.extSegments = new ArrayList();
-            for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
-                JFIFExtensionMarkerSegment jfxx =
-                    (JFIFExtensionMarkerSegment) iter.next();
+            newGuy.extSegments = new ArrayList<>();
+            for (Iterator<JFIFExtensionMarkerSegment> iter = extSegments.iterator(); iter.hasNext();) {
+                JFIFExtensionMarkerSegment jfxx = iter.next();
                 newGuy.extSegments.add(jfxx.clone());
             }
         }
         if (iccSegment != null) {
-            newGuy.iccSegment = (ICCMarkerSegment) iccSegment.clone();
+            newGuy.iccSegment = iccSegment.clone();
         }
         return newGuy;
     }
 
     /**

@@ -228,13 +227,12 @@
         node.setAttribute("thumbWidth", Integer.toString(thumbWidth));
         node.setAttribute("thumbHeight", Integer.toString(thumbHeight));
         if (!extSegments.isEmpty()) {
             IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX");
             node.appendChild(JFXXnode);
-            for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
-                JFIFExtensionMarkerSegment seg =
-                    (JFIFExtensionMarkerSegment) iter.next();
+            for (Iterator<JFIFExtensionMarkerSegment> iter = extSegments.iterator(); iter.hasNext();) {
+                JFIFExtensionMarkerSegment seg = iter.next();
                 JFXXnode.appendChild(seg.getNativeNode());
             }
         }
         if (iccSegment != null) {
             node.appendChild(iccSegment.getNativeNode());

@@ -310,24 +308,22 @@
             if (index == 0) {
                 return thumb.getWidth();
             }
             index--;
         }
-        JFIFExtensionMarkerSegment jfxx =
-            (JFIFExtensionMarkerSegment) extSegments.get(index);
+        JFIFExtensionMarkerSegment jfxx = extSegments.get(index);
         return jfxx.thumb.getWidth();
     }
 
     int getThumbnailHeight(int index) {
         if (thumb != null) {
             if (index == 0) {
                 return thumb.getHeight();
             }
             index--;
         }
-        JFIFExtensionMarkerSegment jfxx =
-            (JFIFExtensionMarkerSegment) extSegments.get(index);
+        JFIFExtensionMarkerSegment jfxx = extSegments.get(index);
         return jfxx.thumb.getHeight();
     }
 
     BufferedImage getThumbnail(ImageInputStream iis,
                                int index,

@@ -338,12 +334,11 @@
                 ret = thumb.getThumbnail(iis, reader);
         } else {
             if (thumb != null) {
                 index--;
             }
-            JFIFExtensionMarkerSegment jfxx =
-                (JFIFExtensionMarkerSegment) extSegments.get(index);
+            JFIFExtensionMarkerSegment jfxx = extSegments.get(index);
             ret = jfxx.thumb.getThumbnail(iis, reader);
         }
         reader.thumbnailComplete();
         return ret;
     }

@@ -434,17 +429,17 @@
      * segments, if any, in order to determine how to encode the
      * thumbnails.  If there are more thumbnails than metadata segments,
      * default encoding is used for the extra thumbnails.
      */
     void writeWithThumbs(ImageOutputStream ios,
-                         List thumbnails,
+                         List<? extends BufferedImage> thumbnails,
                          JPEGImageWriter writer) throws IOException {
         if (thumbnails != null) {
             JFIFExtensionMarkerSegment jfxx = null;
             if (thumbnails.size() == 1) {
                 if (!extSegments.isEmpty()) {
-                    jfxx = (JFIFExtensionMarkerSegment) extSegments.get(0);
+                    jfxx = extSegments.get(0);
                 }
                 writeThumb(ios,
                            (BufferedImage) thumbnails.get(0),
                            jfxx,
                            0,

@@ -454,11 +449,11 @@
                 // All others write as separate JFXX segments
                 write(ios, writer);  // Just the header without any thumbnail
                 for (int i = 0; i < thumbnails.size(); i++) {
                     jfxx = null;
                     if (i < extSegments.size()) {
-                        jfxx = (JFIFExtensionMarkerSegment) extSegments.get(i);
+                        jfxx = extSegments.get(i);
                     }
                     writeThumb(ios,
                                (BufferedImage) thumbnails.get(i),
                                jfxx,
                                i,

@@ -603,11 +598,11 @@
      * If <code>iccProfile</code> is not <code>null</code>,
      * writes out the profile after the JFIF segment using as many APP2
      * marker segments as necessary.
      */
     static void writeDefaultJFIF(ImageOutputStream ios,
-                                 List thumbnails,
+                                 List<? extends BufferedImage> thumbnails,
                                  ICC_Profile iccProfile,
                                  JPEGImageWriter writer)
         throws IOException {
 
         JFIFMarkerSegment jfif = new JFIFMarkerSegment();

@@ -635,13 +630,12 @@
         System.out.print("Thumbnail Width: ");
         System.out.println(thumbWidth);
         System.out.print("Thumbnail Height: ");
         System.out.println(thumbHeight);
         if (!extSegments.isEmpty()) {
-            for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
-                JFIFExtensionMarkerSegment extSegment =
-                    (JFIFExtensionMarkerSegment) iter.next();
+            for (Iterator<JFIFExtensionMarkerSegment> iter = extSegments.iterator(); iter.hasNext();) {
+                JFIFExtensionMarkerSegment extSegment = iter.next();
                 extSegment.print();
             }
         }
         if (iccSegment != null) {
             iccSegment.print();

@@ -766,11 +760,11 @@
                 // Should never happen
                 throw new InternalError("Illegal thumb in setThumbnail!", e);
             }
         }
 
-        protected Object clone() {
+        protected JFIFExtensionMarkerSegment clone() {
             JFIFExtensionMarkerSegment newGuy =
                 (JFIFExtensionMarkerSegment) super.clone();
             if (thumb != null) {
                 newGuy.thumb = (JFIFThumb) thumb.clone();
             }

@@ -1371,11 +1365,11 @@
      * a profile larger than 64K is broken up into a series of chunks.
      * This inner class represents the complete profile as a single object,
      * combining chunks as necessary.
      */
     class ICCMarkerSegment extends MarkerSegment {
-        ArrayList chunks = null;
+        ArrayList<byte[]> chunks = null;
         byte [] profile = null; // The complete profile when it's fully read
                          // May remain null when writing
         private static final int ID_SIZE = 12;
         int chunksRead;
         int numChunks;

@@ -1426,11 +1420,11 @@
                 byte [] profileData = new byte[length];
                 // Now reduce the stored length by the
                 // two chunk numbering bytes
                 length -= 2;
                 buffer.readData(profileData);
-                chunks = new ArrayList();
+                chunks = new ArrayList<>();
                 chunks.add(profileData);
                 chunksRead = 1;
                 inICC = true;
             }
         }

@@ -1444,11 +1438,11 @@
                     profile = prof.getData();
                 }
             }
         }
 
-        protected Object clone () {
+        protected ICCMarkerSegment clone () {
             ICCMarkerSegment newGuy = (ICCMarkerSegment) super.clone();
             if (profile != null) {
                 newGuy.profile = profile.clone();
             }
             return newGuy;

@@ -1516,11 +1510,11 @@
 
                 int index = 0;
                 for (int i = 1; i <= numChunks; i++) {
                     boolean foundIt = false;
                     for (int chunk = 0; chunk < chunks.size(); chunk++) {
-                        byte [] chunkData = (byte []) chunks.get(chunk);
+                        byte [] chunkData = chunks.get(chunk);
                         if (chunkData[0] == i) { // Right one
                             System.arraycopy(chunkData, 2,
                                              profile, index,
                                              chunkData.length-2);
                             index += chunkData.length-2;