commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1391794 [1/3] - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/common/ main/java/org/apache/commons/imaging/common/mylzw/ main/java/org/apache/commons/imaging/formats/bmp/ main/java/org/apache/commons/imaging/fo...
Date Sat, 29 Sep 2012 13:01:04 GMT
Author: damjan
Date: Sat Sep 29 13:01:01 2012
New Revision: 1391794

URL: http://svn.apache.org/viewvc?rev=1391794&view=rev
Log:
Make byte order an enum, and delete its predecessor BinaryConstants.
Complete BinaryConversions and start using it.


Added:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ByteOrder.java   (with props)
Removed:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConstants.java
Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.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/BinaryFileParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitOutputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.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/bmp/pixelparsers/PixelParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
    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/JpegUtils.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.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/jpeg/xmp/JpegRewriter.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.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/psd/datareaders/CompressedDataReader.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/DataReader.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeInfo.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.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/TiffHeader.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageData.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageMetadata.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReader.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldType.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/formats/tiff/fieldtypes/FieldTypeByte.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeDouble.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeFloat.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeLong.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeShort.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeUnknown.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfo.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoAscii.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoByte.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoByteOrShort.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoDouble.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoFloat.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoGpsText.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoLong.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoRational.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSByte.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSLong.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSRational.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShort.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoShort.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoShortOrLong.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoShortOrLongOrRational.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoShortOrRational.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoXpString.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossy.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputField.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputSet.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputSummary.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.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/util/UnicodeUtils.java
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/BinaryFileFunctionsTest.java
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/icns/IcnsRoundTripTest.java
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/ico/IcoRoundtripTest.java
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/tiff/TiffLzwTest.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java Sat Sep 29 13:01:01 2012
@@ -16,249 +16,382 @@
  */
 package org.apache.commons.imaging.common;
 
-public class BinaryConversions implements BinaryConstants {
-    public static byte[] convertToByteArray(short[] values, int byteOrder) {
-        return convertToByteArray(values, 0, values.length, byteOrder);
+/**
+ * Convenience methods for converting data types to and from
+ * byte arrays.
+ */
+public class BinaryConversions {
+    public static byte[] toBytes(short value, ByteOrder byteOrder) {
+        byte[] result = new byte[2];
+        toBytes(value, byteOrder, result, 0);
+        return result;
+    }
+    
+    public static byte[] toBytes(short[] values, ByteOrder byteOrder) {
+        return toBytes(values, 0, values.length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(short[] values, int length,
-            int byteOrder) {
-        return convertToByteArray(values, 0, length, byteOrder);
+    public static byte[] toBytes(short[] values, int length,
+            ByteOrder byteOrder) {
+        return toBytes(values, 0, length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(short[] values, int offset,
-            int length, int byteOrder) {
+    public static byte[] toBytes(short[] values, int offset,
+            int length, ByteOrder byteOrder) {
         byte[] result = new byte[length * 2];
         for (int i = 0; i < length; i++) {
-            short value = values[offset + i];
-            int start = i * 2;
-            if (byteOrder == BYTE_ORDER_MOTOROLA) {
-                result[start + 0] = (byte) (value >> 8);
-                result[start + 1] = (byte) (value >> 0);
-            } else {
-                result[start + 1] = (byte) (value >> 8);
-                result[start + 0] = (byte) (value >> 0);
-            }
+            toBytes(values[offset + i], byteOrder, result, i * 2);
         }
         return result;
     }
+    
+    public static void toBytes(short[] values, ByteOrder byteOrder,
+            byte[] result, int resultOffset) {
+        toBytes(values, 0, values.length, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(short[] values, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        toBytes(values, 0, valuesLength, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(short[] values, int valuesOffset, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        for (int i = 0; i < valuesLength; i++) {
+            toBytes(values[valuesOffset + i], byteOrder, result, resultOffset + i*2);
+        }
+    }
+    
+    public static void toBytes(short value, ByteOrder byteOrder,
+            byte[] result, int offset) {
+        if (byteOrder == ByteOrder.BIG_ENDIAN) {
+            result[offset + 0] = (byte) (value >> 8);
+            result[offset + 1] = (byte) (value >> 0);
+        } else {
+            result[offset + 1] = (byte) (value >> 8);
+            result[offset + 0] = (byte) (value >> 0);
+        }
+    }
 
-    public static byte[] convertToByteArray(int[] values, int byteOrder) {
-        return convertToByteArray(values, 0, values.length, byteOrder);
+    public static byte[] toBytes(int value, ByteOrder byteOrder) {
+        byte[] result = new byte[4];
+        toBytes(value, byteOrder, result, 0);
+        return result;
+    }
+    
+    public static byte[] toBytes(int[] values, ByteOrder byteOrder) {
+        return toBytes(values, 0, values.length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(int[] values, int length,
-            int byteOrder) {
-        return convertToByteArray(values, 0, length, byteOrder);
+    public static byte[] toBytes(int[] values, int length,
+            ByteOrder byteOrder) {
+        return toBytes(values, 0, length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(int[] values, int offset,
-            int length, int byteOrder) {
+    public static byte[] toBytes(int[] values, int offset,
+            int length, ByteOrder byteOrder) {
         byte[] result = new byte[length * 4];
         for (int i = 0; i < length; i++) {
-            int value = values[offset + i];
-            int start = i * 4;
-            if (byteOrder == BYTE_ORDER_MOTOROLA) {
-                result[start + 0] = (byte) (value >> 24);
-                result[start + 1] = (byte) (value >> 16);
-                result[start + 2] = (byte) (value >> 8);
-                result[start + 3] = (byte) (value >> 0);
-            } else {
-                result[start + 3] = (byte) (value >> 24);
-                result[start + 2] = (byte) (value >> 16);
-                result[start + 1] = (byte) (value >> 8);
-                result[start + 0] = (byte) (value >> 0);
-            }
+            toBytes(values[offset + i], byteOrder, result, i * 4);
         }
         return result;
     }
+    
+    public static void toBytes(int[] values, ByteOrder byteOrder,
+            byte[] result, int resultOffset) {
+        toBytes(values, 0, values.length, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(int[] values, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        toBytes(values, 0, valuesLength, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(int[] values, int valuesOffset, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        for (int i = 0; i < valuesLength; i++) {
+            toBytes(values[valuesOffset + i], byteOrder, result, resultOffset + i*4);
+        }
+    }
+    
+    public static void toBytes(int value, ByteOrder byteOrder,
+            byte[] result, int offset) {
+        if (byteOrder == ByteOrder.BIG_ENDIAN) {
+            result[offset + 0] = (byte) (value >> 24);
+            result[offset + 1] = (byte) (value >> 16);
+            result[offset + 2] = (byte) (value >> 8);
+            result[offset + 3] = (byte) (value >> 0);
+        } else {
+            result[offset + 3] = (byte) (value >> 24);
+            result[offset + 2] = (byte) (value >> 16);
+            result[offset + 1] = (byte) (value >> 8);
+            result[offset + 0] = (byte) (value >> 0);
+        }
+    }
 
-    public static byte[] convertToByteArray(float[] values, int byteOrder) {
-        return convertToByteArray(values, 0, values.length, byteOrder);
+    public static byte[] toBytes(float value, ByteOrder byteOrder) {
+        byte[] result = new byte[4];
+        toBytes(value, byteOrder, result, 0);
+        return result;
+    }
+    
+    public static byte[] toBytes(float[] values, ByteOrder byteOrder) {
+        return toBytes(values, 0, values.length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(float[] values, int length,
-            int byteOrder) {
-        return convertToByteArray(values, 0, length, byteOrder);
+    public static byte[] toBytes(float[] values, int length,
+            ByteOrder byteOrder) {
+        return toBytes(values, 0, length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(float[] values, int offset,
-            int length, int byteOrder) {
-        byte[] result = new byte[values.length * 4];
-        for (int i = 0; i < values.length; i++) {
-            float value = values[i];
-            int bits = Float.floatToRawIntBits(value);
-            int start = i * 4;
-            if (byteOrder == BYTE_ORDER_INTEL) {
-                result[start + 0] = (byte) (0xff & (bits >> 0));
-                result[start + 1] = (byte) (0xff & (bits >> 8));
-                result[start + 2] = (byte) (0xff & (bits >> 16));
-                result[start + 3] = (byte) (0xff & (bits >> 24));
-            } else {
-                result[start + 3] = (byte) (0xff & (bits >> 0));
-                result[start + 2] = (byte) (0xff & (bits >> 8));
-                result[start + 1] = (byte) (0xff & (bits >> 16));
-                result[start + 0] = (byte) (0xff & (bits >> 24));
-            }
+    public static byte[] toBytes(float[] values, int offset,
+            int length, ByteOrder byteOrder) {
+        byte[] result = new byte[length * 4];
+        for (int i = 0; i < length; i++) {
+            toBytes(values[offset + i], byteOrder, result, i * 4);
         }
         return result;
     }
+    
+    public static void toBytes(float[] values, ByteOrder byteOrder,
+            byte[] result, int resultOffset) {
+        toBytes(values, 0, values.length, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(float[] values, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        toBytes(values, 0, valuesLength, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(float[] values, int valuesOffset, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        for (int i = 0; i < valuesLength; i++) {
+            toBytes(values[valuesOffset + i], byteOrder, result, resultOffset + i*4);
+        }
+    }
+    
+    public static void toBytes(float value, ByteOrder byteOrder,
+            byte[] result, int offset) {
+        int bits = Float.floatToRawIntBits(value);
+        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
+            result[offset + 0] = (byte) (0xff & (bits >> 0));
+            result[offset + 1] = (byte) (0xff & (bits >> 8));
+            result[offset + 2] = (byte) (0xff & (bits >> 16));
+            result[offset + 3] = (byte) (0xff & (bits >> 24));
+        } else {
+            result[offset + 3] = (byte) (0xff & (bits >> 0));
+            result[offset + 2] = (byte) (0xff & (bits >> 8));
+            result[offset + 1] = (byte) (0xff & (bits >> 16));
+            result[offset + 0] = (byte) (0xff & (bits >> 24));
+        }
+    }
 
-    public static byte[] convertToByteArray(double[] values, int byteOrder) {
-        return convertToByteArray(values, 0, values.length, byteOrder);
+    public static byte[] toBytes(double value, ByteOrder byteOrder) {
+        byte[] result = new byte[8];
+        toBytes(value, byteOrder, result, 0);
+        return result;
+    }
+    
+    public static byte[] toBytes(double[] values, ByteOrder byteOrder) {
+        return toBytes(values, 0, values.length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(double[] values, int length,
-            int byteOrder) {
-        return convertToByteArray(values, 0, length, byteOrder);
+    public static byte[] toBytes(double[] values, int length,
+            ByteOrder byteOrder) {
+        return toBytes(values, 0, length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(double[] values, int offset,
-            int length, int byteOrder) {
+    public static byte[] toBytes(double[] values, int offset,
+            int length, ByteOrder byteOrder) {
         byte[] result = new byte[length * 8];
         for (int i = 0; i < length; i++) {
-            double value = values[offset + i];
-            long bits = Double.doubleToRawLongBits(value);
-            int start = i * 8;
-            if (byteOrder == BYTE_ORDER_INTEL) {
-                result[start + 0] = (byte) (0xff & (bits >> 0));
-                result[start + 1] = (byte) (0xff & (bits >> 8));
-                result[start + 2] = (byte) (0xff & (bits >> 16));
-                result[start + 3] = (byte) (0xff & (bits >> 24));
-                result[start + 4] = (byte) (0xff & (bits >> 32));
-                result[start + 5] = (byte) (0xff & (bits >> 40));
-                result[start + 6] = (byte) (0xff & (bits >> 48));
-                result[start + 7] = (byte) (0xff & (bits >> 56));
-            } else {
-                result[start + 7] = (byte) (0xff & (bits >> 0));
-                result[start + 6] = (byte) (0xff & (bits >> 8));
-                result[start + 5] = (byte) (0xff & (bits >> 16));
-                result[start + 4] = (byte) (0xff & (bits >> 24));
-                result[start + 3] = (byte) (0xff & (bits >> 32));
-                result[start + 2] = (byte) (0xff & (bits >> 40));
-                result[start + 1] = (byte) (0xff & (bits >> 48));
-                result[start + 0] = (byte) (0xff & (bits >> 56));
-            }
+            toBytes(values[offset + i], byteOrder, result, i * 8);
         }
         return result;
     }
+    
+    public static void toBytes(double[] values, ByteOrder byteOrder,
+            byte[] result, int resultOffset) {
+        toBytes(values, 0, values.length, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(double[] values, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        toBytes(values, 0, valuesLength, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(double[] values, int valuesOffset, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        for (int i = 0; i < valuesLength; i++) {
+            toBytes(values[valuesOffset + i], byteOrder, result, resultOffset + i*8);
+        }
+    }
+    
+    public static void toBytes(double value, ByteOrder byteOrder,
+            byte[] result, int offset) {
+        long bits = Double.doubleToRawLongBits(value);
+        if (byteOrder == ByteOrder.INTEL) {
+            result[offset + 0] = (byte) (0xff & (bits >> 0));
+            result[offset + 1] = (byte) (0xff & (bits >> 8));
+            result[offset + 2] = (byte) (0xff & (bits >> 16));
+            result[offset + 3] = (byte) (0xff & (bits >> 24));
+            result[offset + 4] = (byte) (0xff & (bits >> 32));
+            result[offset + 5] = (byte) (0xff & (bits >> 40));
+            result[offset + 6] = (byte) (0xff & (bits >> 48));
+            result[offset + 7] = (byte) (0xff & (bits >> 56));
+        } else {
+            result[offset + 7] = (byte) (0xff & (bits >> 0));
+            result[offset + 6] = (byte) (0xff & (bits >> 8));
+            result[offset + 5] = (byte) (0xff & (bits >> 16));
+            result[offset + 4] = (byte) (0xff & (bits >> 24));
+            result[offset + 3] = (byte) (0xff & (bits >> 32));
+            result[offset + 2] = (byte) (0xff & (bits >> 40));
+            result[offset + 1] = (byte) (0xff & (bits >> 48));
+            result[offset + 0] = (byte) (0xff & (bits >> 56));
+        }
+    }
 
-    public static byte[] convertToByteArray(RationalNumber[] values,
-            int byteOrder) {
-        return convertToByteArray(values, 0, values.length, byteOrder);
-    }
-
-    public static byte[] convertToByteArray(RationalNumber[] values,
-            int length, int byteOrder) {
-        return convertToByteArray(values, 0, length, byteOrder);
+    public static byte[] toBytes(RationalNumber value, ByteOrder byteOrder) {
+        byte[] result = new byte[8];
+        toBytes(value, byteOrder, result, 0);
+        return result;
+    }
+    
+    public static byte[] toBytes(RationalNumber[] values, ByteOrder byteOrder) {
+        return toBytes(values, 0, values.length, byteOrder);
+    }
+
+    public static byte[] toBytes(RationalNumber[] values, int length,
+            ByteOrder byteOrder) {
+        return toBytes(values, 0, length, byteOrder);
     }
 
-    public static byte[] convertToByteArray(RationalNumber[] values,
-            int offset, int length, int byteOrder) {
+    public static byte[] toBytes(RationalNumber[] values, int offset,
+            int length, ByteOrder byteOrder) {
         byte[] result = new byte[length * 8];
         for (int i = 0; i < length; i++) {
-            RationalNumber value = values[offset + i];
-            int start = i * 8;
-            if (byteOrder == BYTE_ORDER_MOTOROLA) {
-                result[start + 0] = (byte) (value.numerator >> 24);
-                result[start + 1] = (byte) (value.numerator >> 16);
-                result[start + 2] = (byte) (value.numerator >> 8);
-                result[start + 3] = (byte) (value.numerator >> 0);
-                result[start + 4] = (byte) (value.divisor >> 24);
-                result[start + 5] = (byte) (value.divisor >> 16);
-                result[start + 6] = (byte) (value.divisor >> 8);
-                result[start + 7] = (byte) (value.divisor >> 0);
-            } else {
-                result[start + 3] = (byte) (value.numerator >> 24);
-                result[start + 2] = (byte) (value.numerator >> 16);
-                result[start + 1] = (byte) (value.numerator >> 8);
-                result[start + 0] = (byte) (value.numerator >> 0);
-                result[start + 7] = (byte) (value.divisor >> 24);
-                result[start + 6] = (byte) (value.divisor >> 16);
-                result[start + 5] = (byte) (value.divisor >> 8);
-                result[start + 4] = (byte) (value.divisor >> 0);
-            }
+            toBytes(values[offset + i], byteOrder, result, i * 8);
         }
         return result;
     }
+    
+    public static void toBytes(RationalNumber[] values, ByteOrder byteOrder,
+            byte[] result, int resultOffset) {
+        toBytes(values, 0, values.length, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(RationalNumber[] values, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        toBytes(values, 0, valuesLength, byteOrder, result, resultOffset);
+    }
+    
+    public static void toBytes(RationalNumber[] values, int valuesOffset, int valuesLength,
+            ByteOrder byteOrder, byte[] result, int resultOffset) {
+        for (int i = 0; i < valuesLength; i++) {
+            toBytes(values[valuesOffset + i], byteOrder, result, resultOffset + i*8);
+        }
+    }
+    
+    public static void toBytes(RationalNumber value, ByteOrder byteOrder,
+            byte[] result, int offset) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
+            result[offset + 0] = (byte) (value.numerator >> 24);
+            result[offset + 1] = (byte) (value.numerator >> 16);
+            result[offset + 2] = (byte) (value.numerator >> 8);
+            result[offset + 3] = (byte) (value.numerator >> 0);
+            result[offset + 4] = (byte) (value.divisor >> 24);
+            result[offset + 5] = (byte) (value.divisor >> 16);
+            result[offset + 6] = (byte) (value.divisor >> 8);
+            result[offset + 7] = (byte) (value.divisor >> 0);
+        } else {
+            result[offset + 3] = (byte) (value.numerator >> 24);
+            result[offset + 2] = (byte) (value.numerator >> 16);
+            result[offset + 1] = (byte) (value.numerator >> 8);
+            result[offset + 0] = (byte) (value.numerator >> 0);
+            result[offset + 7] = (byte) (value.divisor >> 24);
+            result[offset + 6] = (byte) (value.divisor >> 16);
+            result[offset + 5] = (byte) (value.divisor >> 8);
+            result[offset + 4] = (byte) (value.divisor >> 0);
+        }
+    }
 
-    public static short convertToShort(byte[] bytes, int byteOrder) {
-        return convertToShort(bytes, 0, byteOrder);
+    public static short toShort(byte[] bytes, ByteOrder byteOrder) {
+        return toShort(bytes, 0, byteOrder);
     }
 
-    public static short convertToShort(byte[] bytes, int offset, int byteOrder) {
+    public static short toShort(byte[] bytes, int offset, ByteOrder byteOrder) {
         int byte0 = 0xff & bytes[offset + 0];
         int byte1 = 0xff & bytes[offset + 1];
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             return (short) ((byte0 << 8) | byte1);
         } else {
             return (short) ((byte1 << 8) | byte0);
         }
     }
 
-    public static short[] convertToShortArray(byte[] bytes, int byteOrder) {
-        return convertToShortArray(bytes, 0, bytes.length, byteOrder);
+    public static short[] toShorts(byte[] bytes, ByteOrder byteOrder) {
+        return toShorts(bytes, 0, bytes.length, byteOrder);
     }
 
-    public static short[] convertToShortArray(byte[] bytes, int length,
-            int byteOrder) {
-        return convertToShortArray(bytes, 0, length, byteOrder);
+    public static short[] toShorts(byte[] bytes, int length,
+            ByteOrder byteOrder) {
+        return toShorts(bytes, 0, length, byteOrder);
     }
 
-    public static short[] convertToShortArray(byte[] bytes, int offset,
-            int length, int byteOrder) {
+    public static short[] toShorts(byte[] bytes, int offset,
+            int length, ByteOrder byteOrder) {
         short[] result = new short[length / 2];
         for (int i = 0; i < result.length; i++) {
-            result[i] = convertToShort(bytes, offset + 2 * i, byteOrder);
+            result[i] = toShort(bytes, offset + 2 * i, byteOrder);
         }
         return result;
     }
 
-    public static int convertToInt(byte[] bytes, int byteOrder) {
-        return convertToInt(bytes, 0, byteOrder);
+    public static int toInt(byte[] bytes, ByteOrder byteOrder) {
+        return toInt(bytes, 0, byteOrder);
     }
 
-    public static int convertToInt(byte[] bytes, int offset, int byteOrder) {
+    public static int toInt(byte[] bytes, int offset, ByteOrder byteOrder) {
         int byte0 = 0xff & bytes[offset + 0];
         int byte1 = 0xff & bytes[offset + 1];
         int byte2 = 0xff & bytes[offset + 2];
         int byte3 = 0xff & bytes[offset + 3];
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             return (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3;
         } else {
             return (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0;
         }
     }
 
-    public static int[] convertToIntArray(byte[] bytes, int byteOrder) {
-        return convertToIntArray(bytes, 0, bytes.length, byteOrder);
+    public static int[] toInts(byte[] bytes, ByteOrder byteOrder) {
+        return toInts(bytes, 0, bytes.length, byteOrder);
     }
 
-    public static int[] convertToIntArray(byte[] bytes, int length,
-            int byteOrder) {
-        return convertToIntArray(bytes, 0, length, byteOrder);
+    public static int[] toInts(byte[] bytes, int length,
+            ByteOrder byteOrder) {
+        return toInts(bytes, 0, length, byteOrder);
     }
 
-    public static int[] convertToIntArray(byte[] bytes, int offset, int length,
-            int byteOrder) {
+    public static int[] toInts(byte[] bytes, int offset, int length,
+            ByteOrder byteOrder) {
         int[] result = new int[length / 4];
         for (int i = 0; i < result.length; i++) {
-            result[i] = convertToInt(bytes, offset + 4 * i, byteOrder);
+            result[i] = toInt(bytes, offset + 4 * i, byteOrder);
         }
         return result;
     }
 
-    public static float convertToFloat(byte[] bytes, int byteOrder) {
-        return convertToFloat(bytes, 0, byteOrder);
+    public static float toFloat(byte[] bytes, ByteOrder byteOrder) {
+        return toFloat(bytes, 0, byteOrder);
     }
 
-    public static float convertToFloat(byte[] bytes, int offset, int byteOrder) {
+    public static float toFloat(byte[] bytes, int offset, ByteOrder byteOrder) {
         int byte0 = 0xff & bytes[offset + 0];
         int byte1 = 0xff & bytes[offset + 1];
         int byte2 = 0xff & bytes[offset + 2];
         int byte3 = 0xff & bytes[offset + 3];
         int bits;
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             bits = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (byte3 << 0);
         } else {
             bits = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | (byte0 << 0);
@@ -266,29 +399,29 @@ public class BinaryConversions implement
         return Float.intBitsToFloat(bits);
     }
 
-    public static float[] convertToFloatArray(byte[] bytes, int byteOrder) {
-        return convertToFloatArray(bytes, 0, bytes.length, byteOrder);
+    public static float[] toFloats(byte[] bytes, ByteOrder byteOrder) {
+        return toFloats(bytes, 0, bytes.length, byteOrder);
     }
 
-    public static float[] convertToFloatArray(byte[] bytes, int length,
-            int byteOrder) {
-        return convertToFloatArray(bytes, 0, length, byteOrder);
+    public static float[] toFloats(byte[] bytes, int length,
+            ByteOrder byteOrder) {
+        return toFloats(bytes, 0, length, byteOrder);
     }
 
-    public static float[] convertToFloatArray(byte[] bytes, int offset,
-            int length, int byteOrder) {
+    public static float[] toFloats(byte[] bytes, int offset,
+            int length, ByteOrder byteOrder) {
         float[] result = new float[length / 4];
         for (int i = 0; i < result.length; i++) {
-            result[i] = convertToFloat(bytes, offset + 4 * i, byteOrder);
+            result[i] = toFloat(bytes, offset + 4 * i, byteOrder);
         }
         return result;
     }
 
-    public static double convertToDouble(byte[] bytes, int byteOrder) {
-        return convertToDouble(bytes, 0, byteOrder);
+    public static double toDouble(byte[] bytes, ByteOrder byteOrder) {
+        return toDouble(bytes, 0, byteOrder);
     }
 
-    public static double convertToDouble(byte[] bytes, int offset, int byteOrder) {
+    public static double toDouble(byte[] bytes, int offset, ByteOrder byteOrder) {
         long byte0 = 0xffL & bytes[offset + 0];
         long byte1 = 0xffL & bytes[offset + 1];
         long byte2 = 0xffL & bytes[offset + 2];
@@ -298,7 +431,7 @@ public class BinaryConversions implement
         long byte6 = 0xffL & bytes[offset + 6];
         long byte7 = 0xffL & bytes[offset + 7];
         long bits;
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             bits = (byte0 << 56) | (byte1 << 48) | (byte2 << 40)
                     | (byte3 << 32) | (byte4 << 24) | (byte5 << 16)
                     | (byte6 << 8) | (byte7 << 0);
@@ -310,30 +443,30 @@ public class BinaryConversions implement
         return Double.longBitsToDouble(bits);
     }
 
-    public static double[] convertToDoubleArray(byte[] bytes, int byteOrder) {
-        return convertToDoubleArray(bytes, 0, bytes.length, byteOrder);
+    public static double[] toDoubles(byte[] bytes, ByteOrder byteOrder) {
+        return toDoubles(bytes, 0, bytes.length, byteOrder);
     }
 
-    public static double[] convertToDoubleArray(byte[] bytes, int length,
-            int byteOrder) {
-        return convertToDoubleArray(bytes, 0, length, byteOrder);
+    public static double[] toDoubles(byte[] bytes, int length,
+            ByteOrder byteOrder) {
+        return toDoubles(bytes, 0, length, byteOrder);
     }
 
-    public static double[] convertToDoubleArray(byte[] bytes, int offset,
-            int length, int byteOrder) {
+    public static double[] toDoubles(byte[] bytes, int offset,
+            int length, ByteOrder byteOrder) {
         double[] result = new double[length / 8];
         for (int i = 0; i < result.length; i++) {
-            result[i] = convertToDouble(bytes, offset + 8 * i, byteOrder);
+            result[i] = toDouble(bytes, offset + 8 * i, byteOrder);
         }
         return result;
     }
 
-    public static RationalNumber convertToRational(byte[] bytes, int byteOrder) {
-        return convertToRational(bytes, 0, byteOrder);
+    public static RationalNumber toRational(byte[] bytes, ByteOrder byteOrder) {
+        return toRational(bytes, 0, byteOrder);
     }
 
-    public static RationalNumber convertToRational(byte[] bytes, int offset,
-            int byteOrder) {
+    public static RationalNumber toRational(byte[] bytes, int offset,
+            ByteOrder byteOrder) {
         int byte0 = 0xff & bytes[offset + 0];
         int byte1 = 0xff & bytes[offset + 1];
         int byte2 = 0xff & bytes[offset + 2];
@@ -344,7 +477,7 @@ public class BinaryConversions implement
         int byte7 = 0xff & bytes[offset + 7];
         int numerator;
         int divisor;
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             numerator = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3;
             divisor = (byte4 << 24) | (byte5 << 16) | (byte6 << 8) | byte7;
         } else {
@@ -354,21 +487,21 @@ public class BinaryConversions implement
         return new RationalNumber(numerator, divisor);
     }
 
-    public static RationalNumber[] convertToRationalArray(byte[] bytes,
-            int byteOrder) {
-        return convertToRationalArray(bytes, 0, bytes.length, byteOrder);
+    public static RationalNumber[] toRationals(byte[] bytes,
+            ByteOrder byteOrder) {
+        return toRationals(bytes, 0, bytes.length, byteOrder);
     }
 
-    public static RationalNumber[] convertToRationalArray(byte[] bytes,
-            int length, int byteOrder) {
-        return convertToRationalArray(bytes, 0, length, byteOrder);
+    public static RationalNumber[] toRationals(byte[] bytes,
+            int length, ByteOrder byteOrder) {
+        return toRationals(bytes, 0, length, byteOrder);
     }
 
-    public static RationalNumber[] convertToRationalArray(byte[] bytes,
-            int offset, int length, int byteOrder) {
+    public static RationalNumber[] toRationals(byte[] bytes,
+            int offset, int length, ByteOrder byteOrder) {
         RationalNumber[] result = new RationalNumber[length / 8];
         for (int i = 0; i < result.length; i++) {
-            result[i] = convertToRational(bytes, offset + 8 * i, byteOrder);
+            result[i] = toRational(bytes, offset + 8 * i, byteOrder);
         }
         return result;
     }

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=1391794&r1=1391793&r2=1391794&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 Sat Sep 29 13:01:01 2012
@@ -28,7 +28,7 @@ import java.nio.charset.Charset;
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.ImageWriteException;
 
-public class BinaryFileFunctions implements BinaryConstants {
+public class BinaryFileFunctions {
     protected boolean debug = false;
 
     public final void setDebug(boolean b) {
@@ -205,7 +205,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final RationalNumber[] convertByteArrayToRationalArray(
-            String name, byte bytes[], int start, int length, int byteOrder) {
+            String name, byte bytes[], int start, int length, ByteOrder byteOrder) {
         int expectedLength = start + length * 8;
 
         if (bytes.length < expectedLength) {
@@ -225,12 +225,12 @@ public class BinaryFileFunctions impleme
     }
 
     protected final RationalNumber convertByteArrayToRational(String name,
-            byte bytes[], int byteOrder) {
+            byte bytes[], ByteOrder byteOrder) {
         return convertByteArrayToRational(name, bytes, 0, byteOrder);
     }
 
     protected final RationalNumber convertByteArrayToRational(String name,
-            byte bytes[], int start, int byteOrder) {
+            byte bytes[], int start, ByteOrder byteOrder) {
         int numerator = convertByteArrayToInt(name, bytes, start + 0, byteOrder);
         int divisor = convertByteArrayToInt(name, bytes, start + 4, byteOrder);
 
@@ -238,12 +238,12 @@ public class BinaryFileFunctions impleme
     }
 
     protected final int convertByteArrayToInt(String name, byte bytes[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         return convertByteArrayToInt(name, bytes, 0, byteOrder);
     }
 
     protected final int convertByteArrayToInt(String name, byte bytes[],
-            int start, int byteOrder) {
+            int start, ByteOrder byteOrder) {
         byte byte0 = bytes[start + 0];
         byte byte1 = bytes[start + 1];
         byte byte2 = bytes[start + 2];
@@ -251,7 +251,7 @@ public class BinaryFileFunctions impleme
 
         int result;
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             result = ((0xff & byte0) << 24) | ((0xff & byte1) << 16)
                     | ((0xff & byte2) << 8) | ((0xff & byte3) << 0);
         } else {
@@ -267,7 +267,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final int[] convertByteArrayToIntArray(String name, byte bytes[],
-            int start, int length, int byteOrder) {
+            int start, int length, ByteOrder byteOrder) {
         int expectedLength = start + length * 4;
 
         if (bytes.length < expectedLength) {
@@ -287,8 +287,8 @@ public class BinaryFileFunctions impleme
     }
 
     protected final void writeIntInToByteArray(int value, byte bytes[],
-            int start, int byteOrder) {
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+            int start, ByteOrder byteOrder) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             bytes[start + 0] = (byte) (value >> 24);
             bytes[start + 1] = (byte) (value >> 16);
             bytes[start + 2] = (byte) (value >> 8);
@@ -301,8 +301,8 @@ public class BinaryFileFunctions impleme
         }
     }
 
-    protected static final byte[] int2ToByteArray(int value, int byteOrder) {
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+    protected static final byte[] int2ToByteArray(int value, ByteOrder byteOrder) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             return new byte[] { (byte) (value >> 8), (byte) (value >> 0), };
         } else {
             return new byte[] { (byte) (value >> 0), (byte) (value >> 8), };
@@ -310,7 +310,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final byte[] convertIntArrayToByteArray(int values[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         byte result[] = new byte[values.length * 4];
 
         for (int i = 0; i < values.length; i++) {
@@ -321,13 +321,13 @@ public class BinaryFileFunctions impleme
     }
 
     protected final byte[] convertShortArrayToByteArray(int values[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         byte result[] = new byte[values.length * 2];
 
         for (int i = 0; i < values.length; i++) {
             int value = values[i];
 
-            if (byteOrder == BYTE_ORDER_MOTOROLA) {
+            if (byteOrder == ByteOrder.MOTOROLA) {
                 result[i * 2 + 0] = (byte) (value >> 8);
                 result[i * 2 + 1] = (byte) (value >> 0);
             } else {
@@ -339,10 +339,10 @@ public class BinaryFileFunctions impleme
         return result;
     }
 
-    protected final byte[] convertShortToByteArray(int value, int byteOrder) {
+    protected final byte[] convertShortToByteArray(int value, ByteOrder byteOrder) {
         byte result[] = new byte[2];
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             result[0] = (byte) (value >> 8);
             result[1] = (byte) (value >> 0);
         } else {
@@ -354,7 +354,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final byte[] convertIntArrayToRationalArray(int numerators[],
-            int denominators[], int byteOrder) throws ImageWriteException {
+            int denominators[], ByteOrder byteOrder) throws ImageWriteException {
         if (numerators.length != denominators.length) {
             throw new ImageWriteException("numerators.length ("
                     + numerators.length + " != denominators.length ("
@@ -372,7 +372,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final byte[] convertRationalArrayToByteArray(
-            RationalNumber numbers[], int byteOrder) {
+            RationalNumber numbers[], ByteOrder byteOrder) {
         // Debug.debug("convertRationalArrayToByteArray 2");
         byte result[] = new byte[numbers.length * 8];
 
@@ -387,7 +387,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final byte[] convertRationalToByteArray(RationalNumber number,
-            int byteOrder) {
+            ByteOrder byteOrder) {
         byte result[] = new byte[8];
 
         writeIntInToByteArray(number.numerator, result, 0, byteOrder);
@@ -397,12 +397,12 @@ public class BinaryFileFunctions impleme
     }
 
     protected final int convertByteArrayToShort(String name, byte bytes[],
-            int byteOrder) throws ImageReadException {
+            ByteOrder byteOrder) throws ImageReadException {
         return convertByteArrayToShort(name, 0, bytes, byteOrder);
     }
 
     protected final int convertByteArrayToShort(String name, int index,
-            byte bytes[], int byteOrder) throws ImageReadException {
+            byte bytes[], ByteOrder byteOrder) throws ImageReadException {
         if (index + 1 >= bytes.length) {
             throw new ImageReadException("Index out of bounds. Array size: "
                     + bytes.length + ", index: " + index);
@@ -413,7 +413,7 @@ public class BinaryFileFunctions impleme
 
         int result;
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             result = (byte0 << 8) | byte1;
         } else {
             // intel, little endian
@@ -428,7 +428,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final int[] convertByteArrayToShortArray(String name,
-            byte bytes[], int start, int length, int byteOrder)
+            byte bytes[], int start, int length, ByteOrder byteOrder)
             throws ImageReadException
 
     {
@@ -605,7 +605,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final int read4Bytes(String name, InputStream is,
-            String exception, int byteOrder) throws IOException {
+            String exception, ByteOrder byteOrder) throws IOException {
         int size = 4;
         byte bytes[] = new byte[size];
 
@@ -623,14 +623,14 @@ public class BinaryFileFunctions impleme
     }
 
     protected final int read3Bytes(String name, InputStream is,
-            String exception, int byteOrder) throws IOException {
+            String exception, ByteOrder byteOrder) throws IOException {
         byte byte0 = (byte) is.read();
         byte byte1 = (byte) is.read();
         byte byte2 = (byte) is.read();
 
         int result;
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             result = ((0xff & byte0) << 16) | ((0xff & byte1) << 8)
                     | ((0xff & byte2) << 0);
         } else {
@@ -646,7 +646,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final int read2Bytes(String name, InputStream is,
-            String exception, int byteOrder) throws ImageReadException,
+            String exception, ByteOrder byteOrder) throws ImageReadException,
             IOException {
         int size = 2;
         byte bytes[] = new byte[size];
@@ -725,12 +725,12 @@ public class BinaryFileFunctions impleme
     }
 
     protected final float convertByteArrayToFloat(String name, byte bytes[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         return convertByteArrayToFloat(name, bytes, 0, byteOrder);
     }
 
     protected final float convertByteArrayToFloat(String name, byte bytes[],
-            int start, int byteOrder) {
+            int start, ByteOrder byteOrder) {
         // TODO: not tested; probably wrong.
 
         byte byte0 = bytes[start + 0];
@@ -740,7 +740,7 @@ public class BinaryFileFunctions impleme
 
         int bits;
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             bits = ((0xff & byte0) << 24) | ((0xff & byte1) << 16)
                     | ((0xff & byte2) << 8) | ((0xff & byte3) << 0);
         } else {
@@ -754,7 +754,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final float[] convertByteArrayToFloatArray(String name,
-            byte bytes[], int start, int length, int byteOrder) {
+            byte bytes[], int start, int length, ByteOrder byteOrder) {
         int expectedLength = start + length * 4;
 
         if (bytes.length < expectedLength) {
@@ -773,12 +773,12 @@ public class BinaryFileFunctions impleme
         return result;
     }
 
-    protected final byte[] convertFloatToByteArray(float value, int byteOrder) {
+    protected final byte[] convertFloatToByteArray(float value, ByteOrder byteOrder) {
         byte result[] = new byte[4];
 
         int bits = Float.floatToRawIntBits(value);
 
-        if (byteOrder == BYTE_ORDER_INTEL) {
+        if (byteOrder == ByteOrder.INTEL) {
             result[0] = (byte) (0xff & (bits >> 0));
             result[1] = (byte) (0xff & (bits >> 8));
             result[2] = (byte) (0xff & (bits >> 16));
@@ -793,66 +793,15 @@ public class BinaryFileFunctions impleme
         return result;
     }
 
-    protected final byte[] convertFloatArrayToByteArray(float values[],
-            int byteOrder) {
-        byte result[] = new byte[values.length * 4];
-        for (int i = 0; i < values.length; i++) {
-            float value = values[i];
-            int bits = Float.floatToRawIntBits(value);
-
-            int start = i * 4;
-            if (byteOrder == BYTE_ORDER_INTEL) {
-                result[start + 0] = (byte) (0xff & (bits >> 0));
-                result[start + 1] = (byte) (0xff & (bits >> 8));
-                result[start + 2] = (byte) (0xff & (bits >> 16));
-                result[start + 3] = (byte) (0xff & (bits >> 24));
-            } else {
-                result[start + 3] = (byte) (0xff & (bits >> 0));
-                result[start + 2] = (byte) (0xff & (bits >> 8));
-                result[start + 1] = (byte) (0xff & (bits >> 16));
-                result[start + 0] = (byte) (0xff & (bits >> 24));
-            }
-        }
-        return result;
-    }
-
-    protected final byte[] convertDoubleToByteArray(double value, int byteOrder) {
-        byte result[] = new byte[8];
-
-        long bits = Double.doubleToRawLongBits(value);
-
-        if (byteOrder == BYTE_ORDER_INTEL) {
-            result[0] = (byte) (0xff & (bits >> 0));
-            result[1] = (byte) (0xff & (bits >> 8));
-            result[2] = (byte) (0xff & (bits >> 16));
-            result[3] = (byte) (0xff & (bits >> 24));
-            result[4] = (byte) (0xff & (bits >> 32));
-            result[5] = (byte) (0xff & (bits >> 40));
-            result[6] = (byte) (0xff & (bits >> 48));
-            result[7] = (byte) (0xff & (bits >> 56));
-        } else {
-            result[7] = (byte) (0xff & (bits >> 0));
-            result[6] = (byte) (0xff & (bits >> 8));
-            result[5] = (byte) (0xff & (bits >> 16));
-            result[4] = (byte) (0xff & (bits >> 24));
-            result[3] = (byte) (0xff & (bits >> 32));
-            result[2] = (byte) (0xff & (bits >> 40));
-            result[1] = (byte) (0xff & (bits >> 48));
-            result[0] = (byte) (0xff & (bits >> 56));
-        }
-
-        return result;
-    }
-
     protected final byte[] convertDoubleArrayToByteArray(double values[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         byte result[] = new byte[values.length * 8];
         for (int i = 0; i < values.length; i++) {
             double value = values[i];
             long bits = Double.doubleToRawLongBits(value);
 
             int start = i * 8;
-            if (byteOrder == BYTE_ORDER_INTEL) {
+            if (byteOrder == ByteOrder.INTEL) {
                 result[start + 0] = (byte) (0xff & (bits >> 0));
                 result[start + 1] = (byte) (0xff & (bits >> 8));
                 result[start + 2] = (byte) (0xff & (bits >> 16));
@@ -876,12 +825,12 @@ public class BinaryFileFunctions impleme
     }
 
     protected final double convertByteArrayToDouble(String name, byte bytes[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         return convertByteArrayToDouble(name, bytes, 0, byteOrder);
     }
 
     protected final double convertByteArrayToDouble(String name, byte bytes[],
-            int start, int byteOrder) {
+            int start, ByteOrder byteOrder) {
         byte byte0 = bytes[start + 0];
         byte byte1 = bytes[start + 1];
         byte byte2 = bytes[start + 2];
@@ -893,7 +842,7 @@ public class BinaryFileFunctions impleme
 
         long bits;
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             bits = ((0xffL & byte0) << 56) | ((0xffL & byte1) << 48)
                     | ((0xffL & byte2) << 40) | ((0xffL & byte3) << 32)
                     | ((0xffL & byte4) << 24) | ((0xffL & byte5) << 16)
@@ -912,7 +861,7 @@ public class BinaryFileFunctions impleme
     }
 
     protected final double[] convertByteArrayToDoubleArray(String name,
-            byte bytes[], int start, int length, int byteOrder) {
+            byte bytes[], int start, int length, ByteOrder byteOrder) {
         int expectedLength = start + length * 8;
 
         if (bytes.length < expectedLength) {

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java Sat Sep 29 13:01:01 2012
@@ -22,7 +22,7 @@ import java.io.InputStream;
 import org.apache.commons.imaging.ImageReadException;
 
 public class BinaryFileParser extends BinaryFileFunctions {
-    public BinaryFileParser(int byteOrder) {
+    public BinaryFileParser(ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
     }
 
@@ -31,30 +31,15 @@ public class BinaryFileParser extends Bi
     }
 
     // default byte order for Java, many file formats.
-    private int byteOrder = BYTE_ORDER_NETWORK;
+    private ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
 
     // protected boolean BYTE_ORDER_reversed = true;
 
-    protected void setByteOrder(int a, int b) throws ImageReadException {
-        if (a != b) {
-            throw new ImageReadException("Byte Order bytes don't match (" + a
-                    + ", " + b + ").");
-        }
-
-        if (a == BYTE_ORDER_MOTOROLA) {
-            byteOrder = a;
-        } else if (a == BYTE_ORDER_INTEL) {
-            byteOrder = a;
-        } else {
-            throw new ImageReadException("Unknown Byte Order hint: " + a);
-        }
-    }
-
-    protected void setByteOrder(int byteOrder) {
+    protected void setByteOrder(ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
     }
 
-    public int getByteOrder() {
+    public ByteOrder getByteOrder() {
         return byteOrder;
     }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java Sat Sep 29 13:01:01 2012
@@ -23,7 +23,7 @@ import java.io.RandomAccessFile;
 
 import org.apache.commons.imaging.ImageReadException;
 
-public class BinaryInputStream extends InputStream implements BinaryConstants {
+public class BinaryInputStream extends InputStream {
     protected boolean debug = false;
 
     public final void setDebug(boolean b) {
@@ -36,12 +36,12 @@ public class BinaryInputStream extends I
 
     private final InputStream is;
 
-    public BinaryInputStream(byte bytes[], int byteOrder) {
+    public BinaryInputStream(byte bytes[], ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
         this.is = new ByteArrayInputStream(bytes);
     }
 
-    public BinaryInputStream(InputStream is, int byteOrder) {
+    public BinaryInputStream(InputStream is, ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
         this.is = is;
     }
@@ -51,28 +51,13 @@ public class BinaryInputStream extends I
     }
 
     // default byte order for Java, many file formats.
-    private int byteOrder = BYTE_ORDER_NETWORK;
+    private ByteOrder byteOrder = ByteOrder.NETWORK;
 
-    protected void setByteOrder(int a, int b) throws ImageReadException {
-        if (a != b) {
-            throw new ImageReadException("Byte Order bytes don't match (" + a
-                    + ", " + b + ").");
-        }
-
-        if (a == BYTE_ORDER_MOTOROLA) {
-            byteOrder = a;
-        } else if (a == BYTE_ORDER_INTEL) {
-            byteOrder = a;
-        } else {
-            throw new ImageReadException("Unknown Byte Order hint: " + a);
-        }
-    }
-
-    protected void setByteOrder(int byteOrder) {
+    protected void setByteOrder(ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
     }
 
-    protected int getByteOrder() {
+    protected ByteOrder getByteOrder() {
         return byteOrder;
     }
 
@@ -211,7 +196,7 @@ public class BinaryInputStream extends I
     }
 
     protected final RationalNumber[] convertByteArrayToRationalArray(
-            String name, byte bytes[], int start, int length, int byteOrder) {
+            String name, byte bytes[], int start, int length, ByteOrder byteOrder) {
         int expectedLength = start + length * 8;
 
         if (bytes.length < expectedLength) {
@@ -231,12 +216,12 @@ public class BinaryInputStream extends I
     }
 
     protected final RationalNumber convertByteArrayToRational(String name,
-            byte bytes[], int byteOrder) {
+            byte bytes[], ByteOrder byteOrder) {
         return convertByteArrayToRational(name, bytes, 0, byteOrder);
     }
 
     protected final RationalNumber convertByteArrayToRational(String name,
-            byte bytes[], int start, int byteOrder) {
+            byte bytes[], int start, ByteOrder byteOrder) {
         int numerator = convertByteArrayToInt(name, bytes, start + 0, 4,
                 byteOrder);
         int divisor = convertByteArrayToInt(name, bytes, start + 4, 4,
@@ -246,12 +231,12 @@ public class BinaryInputStream extends I
     }
 
     protected final int convertByteArrayToInt(String name, byte bytes[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         return convertByteArrayToInt(name, bytes, 0, 4, byteOrder);
     }
 
     protected final int convertByteArrayToInt(String name, byte bytes[],
-            int start, int length, int byteOrder) {
+            int start, int length, ByteOrder byteOrder) {
         byte byte0 = bytes[start + 0];
         byte byte1 = bytes[start + 1];
         byte byte2 = bytes[start + 2];
@@ -262,7 +247,7 @@ public class BinaryInputStream extends I
 
         int result;
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             result = ((0xff & byte0) << 24) + ((0xff & byte1) << 16)
                     + ((0xff & byte2) << 8) + ((0xff & byte3) << 0);
         } else {
@@ -278,7 +263,7 @@ public class BinaryInputStream extends I
     }
 
     protected final int[] convertByteArrayToIntArray(String name, byte bytes[],
-            int start, int length, int byteOrder) {
+            int start, int length, ByteOrder byteOrder) {
         int expectedLength = start + length * 4;
 
         if (bytes.length < expectedLength) {
@@ -298,18 +283,18 @@ public class BinaryInputStream extends I
     }
 
     protected final int convertByteArrayToShort(String name, byte bytes[],
-            int byteOrder) {
+            ByteOrder byteOrder) {
         return convertByteArrayToShort(name, 0, bytes, byteOrder);
     }
 
     protected final int convertByteArrayToShort(String name, int start,
-            byte bytes[], int byteOrder) {
+            byte bytes[], ByteOrder byteOrder) {
         byte byte0 = bytes[start + 0];
         byte byte1 = bytes[start + 1];
 
         int result;
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             result = ((0xff & byte0) << 8) + ((0xff & byte1) << 0);
         } else {
             result = ((0xff & byte1) << 8) + ((0xff & byte0) << 0);
@@ -323,7 +308,7 @@ public class BinaryInputStream extends I
     }
 
     protected final int[] convertByteArrayToShortArray(String name,
-            byte bytes[], int start, int length, int byteOrder) {
+            byte bytes[], int start, int length, ByteOrder byteOrder) {
         int expectedLength = start + length * 2;
 
         if (bytes.length < expectedLength) {
@@ -456,7 +441,7 @@ public class BinaryInputStream extends I
         return true;
     }
 
-    protected final int read4Bytes(String name, String exception, int byteOrder)
+    protected final int read4Bytes(String name, String exception, ByteOrder byteOrder)
             throws IOException {
         int size = 4;
         byte bytes[] = new byte[size];
@@ -474,7 +459,7 @@ public class BinaryInputStream extends I
         return convertByteArrayToInt(name, bytes, byteOrder);
     }
 
-    protected final int read3Bytes(String name, String exception, int byteOrder)
+    protected final int read3Bytes(String name, String exception, ByteOrder byteOrder)
             throws IOException {
         int size = 3;
         byte bytes[] = new byte[size];
@@ -493,7 +478,7 @@ public class BinaryInputStream extends I
 
     }
 
-    protected final int read2Bytes(String name, String exception, int byteOrder)
+    protected final int read2Bytes(String name, String exception, ByteOrder byteOrder)
             throws IOException {
         int size = 2;
         byte bytes[] = new byte[size];
@@ -529,7 +514,7 @@ public class BinaryInputStream extends I
             throw new ImageReadException(exception);
         }
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             return ((0xff & byte0) << 8) + ((0xff & byte1) << 0);
         } else {
             return ((0xff & byte1) << 8) + ((0xff & byte0) << 0);
@@ -546,7 +531,7 @@ public class BinaryInputStream extends I
             throw new ImageReadException(exception);
         }
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             return ((0xff & byte0) << 24) + ((0xff & byte1) << 16)
                     + ((0xff & byte2) << 8) + ((0xff & byte3) << 0);
         } else {

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java Sat Sep 29 13:01:01 2012
@@ -19,9 +19,7 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.OutputStream;
 
-import org.apache.commons.imaging.ImageWriteException;
-
-public class BinaryOutputStream extends OutputStream implements BinaryConstants {
+public class BinaryOutputStream extends OutputStream {
     protected boolean debug = false;
     private int count = 0;
 
@@ -35,7 +33,7 @@ public class BinaryOutputStream extends 
 
     private final OutputStream os;
 
-    public BinaryOutputStream(OutputStream os, int byteOrder) {
+    public BinaryOutputStream(OutputStream os, ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
         this.os = os;
     }
@@ -45,28 +43,13 @@ public class BinaryOutputStream extends 
     }
 
     // default byte order for Java, many file formats.
-    private int byteOrder = BYTE_ORDER_NETWORK;
-
-    protected void setByteOrder(int a, int b) throws ImageWriteException {
-        if (a != b) {
-            throw new ImageWriteException("Byte Order bytes don't match (" + a
-                    + ", " + b + ").");
-        }
-
-        if (a == BYTE_ORDER_MOTOROLA) {
-            byteOrder = a;
-        } else if (a == BYTE_ORDER_INTEL) {
-            byteOrder = a;
-        } else {
-            throw new ImageWriteException("Unknown Byte Order hint: " + a);
-        }
-    }
+    private ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
 
-    protected void setByteOrder(int byteOrder) {
+    protected void setByteOrder(ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
     }
 
-    public int getByteOrder() {
+    public ByteOrder getByteOrder() {
         return byteOrder;
     }
 
@@ -93,7 +76,7 @@ public class BinaryOutputStream extends 
     }
 
     public final void write4ByteInteger(int value) throws IOException {
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             write(0xff & (value >> 24));
             write(0xff & (value >> 16));
             write(0xff & (value >> 8));
@@ -107,7 +90,7 @@ public class BinaryOutputStream extends 
     }
 
     public final void write2ByteInteger(int value) throws IOException {
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             write(0xff & (value >> 8));
             write(0xff & value);
         } else {
@@ -124,7 +107,7 @@ public class BinaryOutputStream extends 
     private byte[] convertValueToByteArray(int value, int n) {
         byte result[] = new byte[n];
 
-        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+        if (byteOrder == ByteOrder.MOTOROLA) {
             for (int i = 0; i < n; i++) {
                 int b = 0xff & (value >> (8 * (n - i - 1)));
                 result[i] = (byte) b;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java Sat Sep 29 13:01:01 2012
@@ -19,12 +19,12 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.InputStream;
 
-public class BitInputStream extends InputStream implements BinaryConstants {
+public class BitInputStream extends InputStream {
 
     private final InputStream is;
-    private final int byteOrder;
+    private final ByteOrder byteOrder;
 
-    public BitInputStream(InputStream is, int byteOrder) {
+    public BitInputStream(InputStream is, ByteOrder byteOrder) {
         this.is = is;
         this.byteOrder = byteOrder;
     }
@@ -90,7 +90,7 @@ public class BitInputStream extends Inpu
          * the bytes in the end if its Big Endian.This is done because majority
          * (may be all) of the files will be of Little Endian.
          */
-        if (byteOrder == BYTE_ORDER_BIG_ENDIAN) {
+        if (byteOrder == ByteOrder.BIG_ENDIAN) {
             if (count == 16) {
                 bytes_read += 2;
                 return (is.read() << 8) | (is.read() << 0);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java Sat Sep 29 13:01:01 2012
@@ -19,8 +19,7 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.InputStream;
 
-public class BitInputStreamFlexible extends InputStream implements
-        BinaryConstants {
+public class BitInputStreamFlexible extends InputStream {
     // TODO should be byte order conscious, ie TIFF for reading
     // samples size<8 - shuoldn't that effect their order within byte?
     private final InputStream is;

Added: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ByteOrder.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ByteOrder.java?rev=1391794&view=auto
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ByteOrder.java (added)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ByteOrder.java Sat Sep 29 13:01:01 2012
@@ -0,0 +1,29 @@
+/*
+ * 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.imaging.common;
+
+/**
+ * Byte orders. 
+ */
+public enum ByteOrder {
+    LITTLE_ENDIAN,
+    BIG_ENDIAN;
+    
+    public static final ByteOrder MOTOROLA = BIG_ENDIAN;
+    public static final ByteOrder NETWORK = BIG_ENDIAN;
+    public static final ByteOrder INTEL = LITTLE_ENDIAN;
+}

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

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java Sat Sep 29 13:01:01 2012
@@ -27,7 +27,7 @@ import org.apache.commons.imaging.common
 public class Compression {
 
     public byte[] decompressLZW(byte compressed[], int LZWMinimumCodeSize,
-            int expectedSize, int byteOrder) throws IOException {
+            int expectedSize, ByteOrder byteOrder) throws IOException {
         InputStream is = new ByteArrayInputStream(compressed);
 
         MyLzwDecompressor decompressor = new MyLzwDecompressor(
@@ -38,13 +38,13 @@ public class Compression {
     }
 
     public byte[] decompressPackBits(byte compressed[], int expectedSize,
-            int byteOrder) throws ImageReadException {
+            ByteOrder byteOrder) throws ImageReadException {
         byte unpacked[] = new PackBits().decompress(compressed, expectedSize);
         return unpacked;
     }
 
     public byte[] compressLZW(byte src[], int LZWMinimumCodeSize,
-            int byteOrder, boolean earlyLimit) throws IOException
+            ByteOrder byteOrder, boolean earlyLimit) throws IOException
 
     {
         MyLzwCompressor compressor = new MyLzwCompressor(LZWMinimumCodeSize,

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java Sat Sep 29 13:01:01 2012
@@ -19,14 +19,14 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.commons.imaging.common.BinaryConstants;
+import org.apache.commons.imaging.common.ByteOrder;
 
-public class MyBitInputStream extends InputStream implements BinaryConstants {
+public class MyBitInputStream extends InputStream {
     private final InputStream is;
-    private final int byteOrder;
+    private final ByteOrder byteOrder;
     private boolean tiffLZWMode = false;
 
-    public MyBitInputStream(InputStream is, int byteOrder) {
+    public MyBitInputStream(InputStream is, ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
         this.is = is;
     }
@@ -58,12 +58,10 @@ public class MyBitInputStream extends In
 
             int newByte = (0xff & next);
 
-            if (byteOrder == BYTE_ORDER_NETWORK) {
+            if (byteOrder == ByteOrder.NETWORK) {
                 bitCache = (bitCache << 8) | newByte;
-            } else if (byteOrder == BYTE_ORDER_INTEL) {
-                bitCache = (newByte << bitsInCache) | bitCache;
             } else {
-                throw new IOException("Unknown byte order: " + byteOrder);
+                bitCache = (newByte << bitsInCache) | bitCache;
             }
 
             bytesRead++;
@@ -73,13 +71,11 @@ public class MyBitInputStream extends In
 
         int sample;
 
-        if (byteOrder == BYTE_ORDER_NETWORK) {
+        if (byteOrder == ByteOrder.NETWORK) {
             sample = sampleMask & (bitCache >> (bitsInCache - SampleBits));
-        } else if (byteOrder == BYTE_ORDER_INTEL) {
+        } else {
             sample = sampleMask & bitCache;
             bitCache >>= SampleBits;
-        } else {
-            throw new IOException("Unknown byte order: " + byteOrder);
         }
 
         int result = sample;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitOutputStream.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitOutputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitOutputStream.java Sat Sep 29 13:01:01 2012
@@ -19,13 +19,13 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.OutputStream;
 
-import org.apache.commons.imaging.common.BinaryConstants;
+import org.apache.commons.imaging.common.ByteOrder;
 
-public class MyBitOutputStream extends OutputStream implements BinaryConstants {
+public class MyBitOutputStream extends OutputStream {
     private final OutputStream os;
-    private final int byteOrder;
+    private final ByteOrder byteOrder;
 
-    public MyBitOutputStream(OutputStream os, int byteOrder) {
+    public MyBitOutputStream(OutputStream os, ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
         this.os = os;
     }
@@ -44,25 +44,23 @@ public class MyBitOutputStream extends O
         int sampleMask = (1 << SampleBits) - 1;
         value &= sampleMask;
 
-        if (byteOrder == BYTE_ORDER_NETWORK) {
+        if (byteOrder == ByteOrder.NETWORK) {
             // MSB, so add to right
             bitCache = (bitCache << SampleBits) | value;
-        } else if (byteOrder == BYTE_ORDER_INTEL) {
+        } else {
             // LSB, so add to left
             bitCache = bitCache | (value << bitsInCache);
-        } else {
-            throw new IOException("Unknown byte order: " + byteOrder);
         }
         bitsInCache += SampleBits;
 
         while (bitsInCache >= 8) {
-            if (byteOrder == BYTE_ORDER_NETWORK) {
+            if (byteOrder == ByteOrder.NETWORK) {
                 // MSB, so write from left
                 int b = 0xff & (bitCache >> (bitsInCache - 8));
                 actualWrite(b);
 
                 bitsInCache -= 8;
-            } else if (byteOrder == BYTE_ORDER_INTEL) {
+            } else {
                 // LSB, so write from right
                 int b = 0xff & bitCache;
                 actualWrite(b);
@@ -88,11 +86,11 @@ public class MyBitOutputStream extends O
             int bitMask = (1 << bitsInCache) - 1;
             int b = bitMask & bitCache;
 
-            if (byteOrder == BYTE_ORDER_NETWORK) { 
+            if (byteOrder == ByteOrder.NETWORK) { 
                 // MSB, so write from left
                 b <<= 8 - bitsInCache; // left align fragment.
                 os.write(b);
-            } else if (byteOrder == BYTE_ORDER_INTEL) {
+            } else {
                 // LSB, so write from right
                 os.write(b);
             }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java Sat Sep 29 13:01:01 2012
@@ -21,23 +21,25 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.imaging.common.ByteOrder;
+
 public class MyLzwCompressor {
     private int codeSize;
     private final int initialCodeSize;
     private int codes = -1;
 
-    private final int byteOrder;
+    private final ByteOrder byteOrder;
     private final boolean earlyLimit;
     private final int clearCode;
     private final int eoiCode;
     private final Listener listener;
 
-    public MyLzwCompressor(int initialCodeSize, int byteOrder,
+    public MyLzwCompressor(int initialCodeSize, ByteOrder byteOrder,
             boolean earlyLimit) {
         this(initialCodeSize, byteOrder, earlyLimit, null);
     }
 
-    public MyLzwCompressor(int initialCodeSize, int byteOrder,
+    public MyLzwCompressor(int initialCodeSize, ByteOrder byteOrder,
             boolean earlyLimit, Listener listener) {
         this.listener = listener;
         this.byteOrder = byteOrder;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java Sat Sep 29 13:01:01 2012
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.commons.imaging.common.ByteOrder;
+
 public final class MyLzwDecompressor {
     private static final int MAX_TABLE_SIZE = 1 << 12;
 
@@ -29,7 +31,7 @@ public final class MyLzwDecompressor {
     private final int initialCodeSize;
     private int codes = -1;
 
-    private final int byteOrder;
+    private final ByteOrder byteOrder;
 
     private final Listener listener;
 
@@ -39,11 +41,11 @@ public final class MyLzwDecompressor {
         public void init(int clearCode, int eoiCode);
     }
 
-    public MyLzwDecompressor(int initialCodeSize, int byteOrder) {
+    public MyLzwDecompressor(int initialCodeSize, ByteOrder byteOrder) {
         this(initialCodeSize, byteOrder, null);
     }
 
-    public MyLzwDecompressor(int initialCodeSize, int byteOrder,
+    public MyLzwDecompressor(int initialCodeSize, ByteOrder byteOrder,
             Listener listener) {
         this.listener = listener;
         this.byteOrder = byteOrder;

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=1391794&r1=1391793&r2=1391794&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 Sat Sep 29 13:01:01 2012
@@ -37,6 +37,7 @@ import org.apache.commons.imaging.ImageR
 import org.apache.commons.imaging.ImageWriteException;
 import org.apache.commons.imaging.PixelDensity;
 import org.apache.commons.imaging.common.BinaryOutputStream;
+import org.apache.commons.imaging.common.ByteOrder;
 import org.apache.commons.imaging.common.IImageMetadata;
 import org.apache.commons.imaging.common.ImageBuilder;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
@@ -55,7 +56,7 @@ import org.apache.commons.imaging.util.P
 public class BmpImageParser extends ImageParser {
 
     public BmpImageParser() {
-        super.setByteOrder(BYTE_ORDER_INTEL);
+        super.setByteOrder(ByteOrder.INTEL);
     }
 
     @Override
@@ -814,7 +815,7 @@ public class BmpImageParser extends Imag
         }
 
         byte imagedata[] = writer.getImageData(src);
-        BinaryOutputStream bos = new BinaryOutputStream(os, BYTE_ORDER_INTEL);
+        BinaryOutputStream bos = new BinaryOutputStream(os, ByteOrder.INTEL);
 
         // write BitmapFileHeader
         os.write(0x42); // B, Windows 3.1x, 95, NT, Bitmap

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java Sat Sep 29 13:01:01 2012
@@ -21,6 +21,7 @@ import java.io.IOException;
 
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.common.BinaryFileParser;
+import org.apache.commons.imaging.common.ByteOrder;
 import org.apache.commons.imaging.common.ImageBuilder;
 import org.apache.commons.imaging.formats.bmp.BmpHeaderInfo;
 
@@ -37,7 +38,7 @@ public abstract class PixelParser {
         this.colorTable = ColorTable;
         this.imageData = ImageData;
 
-        bfp = new BinaryFileParser(BinaryFileParser.BYTE_ORDER_INTEL);
+        bfp = new BinaryFileParser(ByteOrder.INTEL);
         is = new ByteArrayInputStream(ImageData);
     }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java?rev=1391794&r1=1391793&r2=1391794&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java Sat Sep 29 13:01:01 2012
@@ -35,6 +35,7 @@ import org.apache.commons.imaging.ImageR
 import org.apache.commons.imaging.ImageWriteException;
 import org.apache.commons.imaging.PixelDensity;
 import org.apache.commons.imaging.common.BinaryOutputStream;
+import org.apache.commons.imaging.common.ByteOrder;
 import org.apache.commons.imaging.common.IImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.common.bytesource.ByteSourceInputStream;
@@ -46,7 +47,7 @@ public class DcxImageParser extends Imag
     // See http://www.fileformat.info/format/pcx/egff.htm for documentation
 
     public DcxImageParser() {
-        super.setByteOrder(BYTE_ORDER_LSB);
+        super.setByteOrder(ByteOrder.INTEL);
     }
 
     @Override
@@ -249,7 +250,7 @@ public class DcxImageParser extends Imag
         final int headerSize = 4 + 1024 * 4;
 
         BinaryOutputStream bos = new BinaryOutputStream(os,
-                BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+                ByteOrder.INTEL);
         bos.write4Bytes(DcxHeader.DCX_ID);
         // Some apps may need a full 1024 entry table
         bos.write4Bytes(headerSize);



Mime
View raw message