commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1343020 - in /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging: ./ common/ formats/bmp/ formats/icns/ formats/jpeg/iptc/ formats/png/ formats/psd/ formats/tiff/ formats/tiff/fieldtypes/ icc/ palette/
Date Sun, 27 May 2012 09:58:40 GMT
Author: damjan
Date: Sun May 27 09:58:39 2012
New Revision: 1343020

URL: http://svn.apache.org/viewvc?rev=1343020&view=rev
Log:
Fix some Findbugs problems.


Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/ImageContents.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdHeaderInfo.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTagDataTypes.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/FormatCompliance.java
Sun May 27 09:58:39 2012
@@ -19,6 +19,7 @@ package org.apache.commons.imaging;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -62,7 +63,7 @@ public class FormatCompliance {
     }
 
     public void dump() {
-        dump(new PrintWriter(new OutputStreamWriter(System.out)));
+        dump(new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset())));
     }
 
     public void dump(PrintWriter pw) {

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java
Sun May 27 09:58:39 2012
@@ -20,8 +20,10 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.RandomAccessFile;
+import java.nio.charset.Charset;
 
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.ImageWriteException;
@@ -49,7 +51,7 @@ public class BinaryFileFunctions impleme
     }
 
     public final void debugNumber(String msg, int data, int bytes) {
-        PrintWriter pw = new PrintWriter(System.out);
+        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
         debugNumber(pw, msg, data, bytes);
         pw.flush();
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java
Sun May 27 09:58:39 2012
@@ -19,9 +19,8 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.OutputStream;
 
-public class MyByteArrayOutputStream extends OutputStream
-// some performace benefit, because not thread safe.
-{
+/// Some performance benefit, because not thread safe.
+public class MyByteArrayOutputStream extends OutputStream {
     private final byte bytes[];
 
     public MyByteArrayOutputStream(int length) {

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java
Sun May 27 09:58:39 2012
@@ -110,53 +110,59 @@ public class PackBits {
     }
 
     public byte[] compress(byte bytes[]) throws IOException {
-        MyByteArrayOutputStream baos = new MyByteArrayOutputStream(
-                bytes.length * 2); // max length 1 extra byte for every 128
-
-        int ptr = 0;
-        int count = 0;
-        while (ptr < bytes.length) {
-            count++;
-            int dup = findNextDuplicate(bytes, ptr);
-
-            if (dup == ptr) // write run length
-            {
-                int len = findRunLength(bytes, dup);
-                int actual_len = Math.min(len, 128);
-                baos.write(-(actual_len - 1));
-                baos.write(bytes[ptr]);
-                ptr += actual_len;
-            } else { // write literals
-                int len = dup - ptr;
-
-                if (dup > 0) {
-                    int runlen = findRunLength(bytes, dup);
-                    if (runlen < 3) // may want to discard next run.
-                    {
-                        int nextptr = ptr + len + runlen;
-                        int nextdup = findNextDuplicate(bytes, nextptr);
-                        if (nextdup != nextptr) // discard 2-byte run
+        MyByteArrayOutputStream baos = null;
+        try {
+            baos = new MyByteArrayOutputStream(
+                    bytes.length * 2); // max length 1 extra byte for every 128
+
+            int ptr = 0;
+            int count = 0;
+            while (ptr < bytes.length) {
+                count++;
+                int dup = findNextDuplicate(bytes, ptr);
+    
+                if (dup == ptr) // write run length
+                {
+                    int len = findRunLength(bytes, dup);
+                    int actual_len = Math.min(len, 128);
+                    baos.write(-(actual_len - 1));
+                    baos.write(bytes[ptr]);
+                    ptr += actual_len;
+                } else { // write literals
+                    int len = dup - ptr;
+    
+                    if (dup > 0) {
+                        int runlen = findRunLength(bytes, dup);
+                        if (runlen < 3) // may want to discard next run.
                         {
-                            dup = nextdup;
-                            len = dup - ptr;
+                            int nextptr = ptr + len + runlen;
+                            int nextdup = findNextDuplicate(bytes, nextptr);
+                            if (nextdup != nextptr) // discard 2-byte run
+                            {
+                                dup = nextdup;
+                                len = dup - ptr;
+                            }
                         }
                     }
-                }
-
-                if (dup < 0)
-                    len = bytes.length - ptr;
-                int actual_len = Math.min(len, 128);
-
-                baos.write(actual_len - 1);
-                for (int i = 0; i < actual_len; i++) {
-                    baos.write(bytes[ptr]);
-                    ptr++;
+    
+                    if (dup < 0)
+                        len = bytes.length - ptr;
+                    int actual_len = Math.min(len, 128);
+    
+                    baos.write(actual_len - 1);
+                    for (int i = 0; i < actual_len; i++) {
+                        baos.write(bytes[ptr]);
+                        ptr++;
+                    }
                 }
             }
+            byte result[] = baos.toByteArray();
+    
+            return result;
+        } finally {
+            if (baos != null) {
+                baos.close();
+            }
         }
-        byte result[] = baos.toByteArray();
-
-        return result;
-
     }
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
Sun May 27 09:58:39 2012
@@ -225,6 +225,15 @@ public class BmpImageParser extends Imag
             }
             if (bitmapHeaderSize >= 108) {
                 this.debugNumber("colorSpaceType", colorSpaceType, 4);
+                this.debugNumber("colorSpace.red.x", colorSpace.red.x);
+                this.debugNumber("colorSpace.red.y", colorSpace.red.y);
+                this.debugNumber("colorSpace.red.z", colorSpace.red.z);
+                this.debugNumber("colorSpace.green.x", colorSpace.green.x);
+                this.debugNumber("colorSpace.green.y", colorSpace.green.y);
+                this.debugNumber("colorSpace.green.z", colorSpace.green.z);
+                this.debugNumber("colorSpace.blue.x", colorSpace.blue.x);
+                this.debugNumber("colorSpace.blue.y", colorSpace.blue.y);
+                this.debugNumber("colorSpace.blue.z", colorSpace.blue.z);
                 this.debugNumber("gammaRed", gammaRed, 4);
                 this.debugNumber("gammaGreen", gammaGreen, 4);
                 this.debugNumber("gammaBlue", gammaBlue, 4);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java
Sun May 27 09:58:39 2012
@@ -176,6 +176,7 @@ public class IcnsType {
         try {
             bytes = type.getBytes("US-ASCII");
         } catch (UnsupportedEncodingException cannotHappen) {
+            throw new IllegalArgumentException("Your Java doesn't support US-ASCII");
         }
         if (bytes.length != 4)
             throw new IllegalArgumentException("Invalid ICNS type");

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=1343020&r1=1343019&r2=1343020&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 May 27 09:58:39 2012
@@ -254,84 +254,91 @@ public class IptcParser extends BinaryFi
             boolean strict) throws ImageReadException, IOException {
         List<IptcBlock> blocks = new ArrayList<IptcBlock>();
 
-        BinaryInputStream bis = new BinaryInputStream(bytes, APP13_BYTE_ORDER);
-
-        // Note that these are unsigned quantities. Name is always an even
-        // number of bytes (including the 1st byte, which is the size.)
-
-        byte[] idString = bis.readByteArray(
-                PHOTOSHOP_IDENTIFICATION_STRING.size(),
-                "App13 Segment missing identification string");
-        if (!PHOTOSHOP_IDENTIFICATION_STRING.equals(idString))
-            throw new ImageReadException("Not a Photoshop App13 Segment");
-
-        // int index = PHOTOSHOP_IDENTIFICATION_STRING.length;
-
-        while (true) {
-            byte[] imageResourceBlockSignature = bis
-                    .readByteArray(CONST_8BIM.size(),
-                            "App13 Segment missing identification string",
-                            false, false);
-            if (null == imageResourceBlockSignature)
-                break;
-            if (!CONST_8BIM.equals(imageResourceBlockSignature))
-                throw new ImageReadException(
-                        "Invalid Image Resource Block Signature");
-
-            int blockType = bis
-                    .read2ByteInteger("Image Resource Block missing type");
-            if (verbose)
-                Debug.debug("blockType",
-                        blockType + " (0x" + Integer.toHexString(blockType)
-                                + ")");
-
-            int blockNameLength = bis
-                    .read1ByteInteger("Image Resource Block missing name length");
-            if (verbose && blockNameLength > 0)
-                Debug.debug("blockNameLength", blockNameLength + " (0x"
-                        + Integer.toHexString(blockNameLength) + ")");
-            byte[] blockNameBytes;
-            if (blockNameLength == 0) {
-                bis.read1ByteInteger("Image Resource Block has invalid name");
-                blockNameBytes = new byte[0];
-            } else {
-                blockNameBytes = bis.readByteArray(blockNameLength,
-                        "Invalid Image Resource Block name", verbose, strict);
-                if (null == blockNameBytes)
+        BinaryInputStream bis = null;
+        try {
+            bis = new BinaryInputStream(bytes, APP13_BYTE_ORDER);
+
+            // Note that these are unsigned quantities. Name is always an even
+            // number of bytes (including the 1st byte, which is the size.)
+    
+            byte[] idString = bis.readByteArray(
+                    PHOTOSHOP_IDENTIFICATION_STRING.size(),
+                    "App13 Segment missing identification string");
+            if (!PHOTOSHOP_IDENTIFICATION_STRING.equals(idString))
+                throw new ImageReadException("Not a Photoshop App13 Segment");
+    
+            // int index = PHOTOSHOP_IDENTIFICATION_STRING.length;
+    
+            while (true) {
+                byte[] imageResourceBlockSignature = bis
+                        .readByteArray(CONST_8BIM.size(),
+                                "App13 Segment missing identification string",
+                                false, false);
+                if (null == imageResourceBlockSignature)
                     break;
-
-                if (blockNameLength % 2 == 0)
+                if (!CONST_8BIM.equals(imageResourceBlockSignature))
+                    throw new ImageReadException(
+                            "Invalid Image Resource Block Signature");
+    
+                int blockType = bis
+                        .read2ByteInteger("Image Resource Block missing type");
+                if (verbose)
+                    Debug.debug("blockType",
+                            blockType + " (0x" + Integer.toHexString(blockType)
+                                    + ")");
+    
+                int blockNameLength = bis
+                        .read1ByteInteger("Image Resource Block missing name length");
+                if (verbose && blockNameLength > 0)
+                    Debug.debug("blockNameLength", blockNameLength + " (0x"
+                            + Integer.toHexString(blockNameLength) + ")");
+                byte[] blockNameBytes;
+                if (blockNameLength == 0) {
+                    bis.read1ByteInteger("Image Resource Block has invalid name");
+                    blockNameBytes = new byte[0];
+                } else {
+                    blockNameBytes = bis.readByteArray(blockNameLength,
+                            "Invalid Image Resource Block name", verbose, strict);
+                    if (null == blockNameBytes)
+                        break;
+    
+                    if (blockNameLength % 2 == 0)
+                        bis.read1ByteInteger("Image Resource Block missing padding byte");
+                }
+    
+                int blockSize = bis
+                        .read4ByteInteger("Image Resource Block missing size");
+                if (verbose)
+                    Debug.debug("blockSize",
+                            blockSize + " (0x" + Integer.toHexString(blockSize)
+                                    + ")");
+    
+                /*
+                 * doesn't catch cases where blocksize is invalid but is still less
+                 * than bytes.length but will at least prevent OutOfMemory errors
+                 */
+                if (blockSize > bytes.length) {
+                    throw new ImageReadException("Invalid Block Size : "
+                            + blockSize + " > " + bytes.length);
+                }
+    
+                byte[] blockData = bis.readByteArray(blockSize,
+                        "Invalid Image Resource Block data", verbose, strict);
+                if (null == blockData)
+                    break;
+    
+                blocks.add(new IptcBlock(blockType, blockNameBytes, blockData));
+    
+                if ((blockSize % 2) != 0)
                     bis.read1ByteInteger("Image Resource Block missing padding byte");
             }
-
-            int blockSize = bis
-                    .read4ByteInteger("Image Resource Block missing size");
-            if (verbose)
-                Debug.debug("blockSize",
-                        blockSize + " (0x" + Integer.toHexString(blockSize)
-                                + ")");
-
-            /*
-             * doesn't catch cases where blocksize is invalid but is still less
-             * than bytes.length but will at least prevent OutOfMemory errors
-             */
-            if (blockSize > bytes.length) {
-                throw new ImageReadException("Invalid Block Size : "
-                        + blockSize + " > " + bytes.length);
+    
+            return blocks;
+        } finally {
+            if (bis != null) {
+                bis.close();
             }
-
-            byte[] blockData = bis.readByteArray(blockSize,
-                    "Invalid Image Resource Block data", verbose, strict);
-            if (null == blockData)
-                break;
-
-            blocks.add(new IptcBlock(blockType, blockNameBytes, blockData));
-
-            if ((blockSize % 2) != 0)
-                bis.read1ByteInteger("Image Resource Block missing padding byte");
         }
-
-        return blocks;
     }
 
     // private void writeIPTCRecord(BinaryOutputStream bos, )

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
Sun May 27 09:58:39 2012
@@ -317,6 +317,7 @@ public class PngWriter implements PngCon
                 result = (byte) value;
                 break;
             default:
+                result = 8;
             }
             switch (colorType) {
             case COLOR_TYPE_GREYSCALE:
@@ -330,6 +331,7 @@ public class PngWriter implements PngCon
                 result = (byte) Math.max(8, result);
                 break;
             default:
+                result = 8;
             }
         }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/ImageContents.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/ImageContents.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/ImageContents.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/ImageContents.java
Sun May 27 09:58:39 2012
@@ -16,7 +16,9 @@
  */
 package org.apache.commons.imaging.formats.psd;
 
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.Charset;
 
 public class ImageContents {
     public final PsdHeaderInfo header;
@@ -38,7 +40,7 @@ public class ImageContents {
     }
 
     public void dump() {
-        PrintWriter pw = new PrintWriter(System.out);
+        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
         dump(pw);
         pw.flush();
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdHeaderInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdHeaderInfo.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdHeaderInfo.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdHeaderInfo.java
Sun May 27 09:58:39 2012
@@ -16,7 +16,9 @@
  */
 package org.apache.commons.imaging.formats.psd;
 
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.Charset;
 
 public class PsdHeaderInfo {
     public final int Version;
@@ -40,7 +42,7 @@ public class PsdHeaderInfo {
     }
 
     public void dump() {
-        PrintWriter pw = new PrintWriter(System.out);
+        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
         dump(pw);
         pw.flush();
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
Sun May 27 09:58:39 2012
@@ -609,7 +609,7 @@ public class PsdImageParser extends Imag
                 ImageResourceBlock block = blocks.get(i);
                 pw.println("\t" + i + " (" + Integer.toHexString(block.id)
                         + ", " + "'"
-                        + new String(block.nameData)
+                        + new String(block.nameData, "ISO-8859-1")
                         + "' ("
                         + block.nameData.length
                         + "), "

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java
Sun May 27 09:58:39 2012
@@ -17,7 +17,9 @@
 package org.apache.commons.imaging.formats.tiff;
 
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.Charset;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -467,7 +469,7 @@ public class TiffField implements TiffCo
     }
 
     public void dump() {
-        PrintWriter pw = new PrintWriter(System.out);
+        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
         dump(pw);
         pw.flush();
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
Sun May 27 09:58:39 2012
@@ -84,6 +84,7 @@ public class FieldTypeAscii extends Fiel
             try {
                 bytes = ((String) o).getBytes("UTF-8");
             } catch (UnsupportedEncodingException cannotHappen) {
+                throw new IllegalArgumentException("Your Java doesn't support UTF-8");
             }
             byte result[] = new byte[bytes.length + 1];
             System.arraycopy(bytes, 0, result, 0, bytes.length);
@@ -97,6 +98,7 @@ public class FieldTypeAscii extends Fiel
                 try {
                     bytes = strings[i].getBytes("UTF-8");
                 } catch (UnsupportedEncodingException cannotHappen) {
+                    throw new IllegalArgumentException("Your Java doesn't support UTF-8");
                 }
                 totalLength += (bytes.length + 1);
             }
@@ -107,6 +109,7 @@ public class FieldTypeAscii extends Fiel
                 try {
                     bytes = strings[i].getBytes("UTF-8");
                 } catch (UnsupportedEncodingException cannotHappen) {
+                    throw new IllegalArgumentException("Your Java doesn't support UTF-8");
                 }
                 System.arraycopy(bytes, 0, result, position, bytes.length);
                 position += (bytes.length + 1);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java
Sun May 27 09:58:39 2012
@@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 
 import org.apache.commons.imaging.ImageReadException;
@@ -71,7 +72,7 @@ public class IccTag implements BinaryCon
     }
 
     public void dump(String prefix) throws ImageReadException, IOException {
-        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
+        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
 
         dump(pw, prefix);
 
@@ -84,10 +85,12 @@ public class IccTag implements BinaryCon
                 + "tag signature: "
                 + Integer.toHexString(signature)
                 + " ("
-                + new String(new byte[] { (byte) (0xff & (signature >> 24)),
+                + new String(new byte[] {
+                        (byte) (0xff & (signature >> 24)),
                         (byte) (0xff & (signature >> 16)),
                         (byte) (0xff & (signature >> 8)),
-                        (byte) (0xff & (signature >> 0)), }) + ")");
+                        (byte) (0xff & (signature >> 0)), }, "US-ASCII")
+                + ")");
 
         if (data == null)
             pw.println(prefix + "data: " + Arrays.toString(data));
@@ -102,7 +105,7 @@ public class IccTag implements BinaryCon
                             (byte) (0xff & (data_type_signature >> 24)),
                             (byte) (0xff & (data_type_signature >> 16)),
                             (byte) (0xff & (data_type_signature >> 8)),
-                            (byte) (0xff & (data_type_signature >> 0)), })
+                            (byte) (0xff & (data_type_signature >> 0)), }, "US-ASCII")
                     + ")");
 
             if (itdt == null)

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTagDataTypes.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTagDataTypes.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTagDataTypes.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTagDataTypes.java
Sun May 27 09:58:39 2012
@@ -40,7 +40,7 @@ public enum IccTagDataTypes implements I
                     "ICC: corrupt tag data");
 
             //            bis.readByteArray("ignore", bytes.length -12, "none");
-            String s = new String(bytes, 12, string_length - 1);
+            String s = new String(bytes, 12, string_length - 1, "US-ASCII");
             System.out.println(prefix + "s: '" + s + "'");
         }
 
@@ -92,8 +92,8 @@ public enum IccTagDataTypes implements I
                             (byte) (0xff & (thesignature >> 24)),
                             (byte) (0xff & (thesignature >> 16)),
                             (byte) (0xff & (thesignature >> 8)),
-                            (byte) (0xff & (thesignature >> 0)),
-                    }) + ")");
+                            (byte) (0xff & (thesignature >> 0)), }, "US-ASCII")
+                    + ")");
         }
 
     },
@@ -108,7 +108,7 @@ public enum IccTagDataTypes implements I
                     BinaryConstants.BYTE_ORDER_NETWORK);
             bis.read4Bytes("type_signature", "ICC: corrupt tag data");
             bis.read4Bytes("ignore", "ICC: corrupt tag data");
-            String s = new String(bytes, 8, bytes.length - 8);
+            String s = new String(bytes, 8, bytes.length - 8, "US-ASCII");
             System.out.println(prefix + "s: '" + s + "'");
         }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
Sun May 27 09:58:39 2012
@@ -16,7 +16,10 @@
  */
 package org.apache.commons.imaging.palette;
 
-class ColorSpaceSubset implements Comparable<ColorSpaceSubset> {
+import java.io.Serializable;
+import java.util.Comparator;
+
+class ColorSpaceSubset {
     public final int mins[], maxs[];
     public final int precision;
     public final int precision_mask;
@@ -154,14 +157,17 @@ class ColorSpaceSubset implements Compar
         }
     }
 
-    public int compareTo(ColorSpaceSubset other) {
-        return rgb - other.rgb;
-    }
-
     public int index;
 
     public final void setIndex(int i) {
         index = i;
     }
 
+    public static class RgbComparator implements Comparator<ColorSpaceSubset>, Serializable
{
+        public int compare(ColorSpaceSubset c1, ColorSpaceSubset c2) {
+            return c1.rgb - c2.rgb;
+        }
+    }
+    
+    public static final RgbComparator rgbComparator = new RgbComparator();
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java?rev=1343020&r1=1343019&r2=1343020&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
Sun May 27 09:58:39 2012
@@ -391,7 +391,7 @@ public class PaletteFactory {
                 subset.dump(i + ": ");
         }
 
-        Collections.sort(subsets);
+        Collections.sort(subsets, ColorSpaceSubset.rgbComparator);
 
         return new QuantizedPalette(subsets, precision);
     }



Mime
View raw message