org.apache.sanselan.common
Class BinaryFileFunctions

java.lang.Object
  extended by org.apache.sanselan.common.BinaryFileFunctions
All Implemented Interfaces:
BinaryConstants
Direct Known Subclasses:
BinaryFileParser, ByteSource, FieldType, ZLibUtils

public class BinaryFileFunctions
extends java.lang.Object
implements BinaryConstants


Field Summary
protected  boolean debug
           
 
Fields inherited from interface org.apache.sanselan.common.BinaryConstants
BYTE_ORDER_BIG_ENDIAN, BYTE_ORDER_INTEL, BYTE_ORDER_LEAST_SIGNIFICANT_BYTE, BYTE_ORDER_LITTLE_ENDIAN, BYTE_ORDER_LSB, BYTE_ORDER_MOST_SIGNIFICANT_BYTE, BYTE_ORDER_MOTOROLA, BYTE_ORDER_MSB, BYTE_ORDER_NETWORK
 
Constructor Summary
BinaryFileFunctions()
           
 
Method Summary
static int CharsToQuad(char c1, char c2, char c3, char c4)
           
 boolean compareByteArrays(byte[] a, byte[] b)
           
 boolean compareByteArrays(byte[] a, int aStart, byte[] b, int bStart, int length)
           
static boolean compareBytes(byte[] a, byte[] b)
           
static boolean compareBytes(byte[] a, int aStart, byte[] b, int bStart, int length)
           
protected  double convertByteArrayToDouble(java.lang.String name, byte[] bytes, int byteOrder)
           
protected  double convertByteArrayToDouble(java.lang.String name, byte[] bytes, int start, int byteOrder)
           
protected  double[] convertByteArrayToDoubleArray(java.lang.String name, byte[] bytes, int start, int length, int byteOrder)
           
protected  float convertByteArrayToFloat(java.lang.String name, byte[] bytes, int byteOrder)
           
protected  float convertByteArrayToFloat(java.lang.String name, byte[] bytes, int start, int byteOrder)
           
protected  float[] convertByteArrayToFloatArray(java.lang.String name, byte[] bytes, int start, int length, int byteOrder)
           
protected  int convertByteArrayToInt(java.lang.String name, byte[] bytes, int byteOrder)
           
protected  int convertByteArrayToInt(java.lang.String name, byte[] bytes, int start, int byteOrder)
           
protected  int[] convertByteArrayToIntArray(java.lang.String name, byte[] bytes, int start, int length, int byteOrder)
           
protected  RationalNumber convertByteArrayToRational(java.lang.String name, byte[] bytes, int byteOrder)
           
protected  RationalNumber convertByteArrayToRational(java.lang.String name, byte[] bytes, int start, int byteOrder)
           
protected  RationalNumber[] convertByteArrayToRationalArray(java.lang.String name, byte[] bytes, int start, int length, int byteOrder)
           
protected  int convertByteArrayToShort(java.lang.String name, byte[] bytes, int byteOrder)
           
protected  int convertByteArrayToShort(java.lang.String name, int index, byte[] bytes, int byteOrder)
           
protected  int[] convertByteArrayToShortArray(java.lang.String name, byte[] bytes, int start, int length, int byteOrder)
           
protected  byte[] convertDoubleArrayToByteArray(double[] values, int byteOrder)
           
protected  byte[] convertDoubleToByteArray(double value, int byteOrder)
           
protected  byte[] convertFloatArrayToByteArray(float[] values, int byteOrder)
           
protected  byte[] convertFloatToByteArray(float value, int byteOrder)
           
protected  byte[] convertIntArrayToByteArray(int[] values, int byteOrder)
           
protected  byte[] convertIntArrayToRationalArray(int[] numerators, int[] denominators, int byteOrder)
           
protected  byte[] convertRationalArrayToByteArray(RationalNumber[] numbers, int byteOrder)
           
protected  byte[] convertRationalToByteArray(RationalNumber number, int byteOrder)
           
protected  byte[] convertShortArrayToByteArray(int[] values, int byteOrder)
           
protected  byte[] convertShortToByteArray(int value, int byteOrder)
           
 void copyStreamToStream(java.io.InputStream is, java.io.OutputStream os)
           
 void debugByteArray(java.lang.String name, byte[] bytes)
           
 void debugNumber(java.io.PrintWriter pw, java.lang.String msg, int data)
           
 void debugNumber(java.io.PrintWriter pw, java.lang.String msg, int data, int bytes)
           
 void debugNumber(java.lang.String msg, int data)
           
 void debugNumber(java.lang.String msg, int data, int bytes)
           
protected  void debugNumberArray(java.lang.String name, int[] numbers, int length)
           
 int findNull(byte[] src)
           
 int findNull(byte[] src, int start)
           
protected  byte[] getBytearrayHead(java.lang.String name, byte[] bytes, int count)
           
protected  byte[] getByteArrayTail(java.lang.String name, byte[] bytes, int count)
           
 boolean getDebug()
           
protected  byte[] getRAFBytes(java.io.RandomAccessFile raf, long pos, int length, java.lang.String exception)
           
 byte[] getStreamBytes(java.io.InputStream is)
           
static byte[] head(byte[] bytes, int count)
           
protected static byte[] int2ToByteArray(int value, int byteOrder)
           
protected  void printByteBits(java.lang.String msg, byte i)
           
protected  void printCharQuad(java.io.PrintWriter pw, java.lang.String msg, int i)
           
protected  void printCharQuad(java.lang.String msg, int i)
           
protected  int read2Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, int byteOrder)
           
protected  int read3Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, int byteOrder)
           
protected  int read4Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, int byteOrder)
           
 void readAndVerifyBytes(java.io.InputStream is, byte[] expected, java.lang.String exception)
           
protected  void readAndVerifyBytes(java.lang.String name, java.io.InputStream is, byte[] expected, java.lang.String exception)
           
 byte readByte(java.lang.String name, java.io.InputStream is, java.lang.String exception)
           
 byte[] readBytearray(java.lang.String name, byte[] bytes, int start, int count)
           
 byte[] readByteArray(java.lang.String name, int length, java.io.InputStream is)
           
 byte[] readByteArray(java.lang.String name, int length, java.io.InputStream is, java.lang.String exception)
           
 byte[] readBytes(java.io.InputStream is, int count)
           
protected  void readRandomBytes(java.io.InputStream is)
           
protected  void scanForByte(java.io.InputStream is, byte value)
           
 void setDebug(boolean b)
           
protected  void skipBytes(java.io.InputStream is, int length)
           
 void skipBytes(java.io.InputStream is, int length, java.lang.String exception)
           
static byte[] slice(byte[] bytes, int start, int count)
           
 boolean startsWith(byte[] haystack, byte[] needle)
           
static byte[] tail(byte[] bytes, int count)
           
protected  void writeIntInToByteArray(int value, byte[] bytes, int start, int byteOrder)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected boolean debug
Constructor Detail

BinaryFileFunctions

public BinaryFileFunctions()
Method Detail

setDebug

public final void setDebug(boolean b)

getDebug

public final boolean getDebug()

readRandomBytes

protected final void readRandomBytes(java.io.InputStream is)
                              throws ImageReadException,
                                     java.io.IOException
Throws:
ImageReadException
java.io.IOException

debugNumber

public final void debugNumber(java.lang.String msg,
                              int data)

debugNumber

public final void debugNumber(java.lang.String msg,
                              int data,
                              int bytes)

debugNumber

public final void debugNumber(java.io.PrintWriter pw,
                              java.lang.String msg,
                              int data)

debugNumber

public final void debugNumber(java.io.PrintWriter pw,
                              java.lang.String msg,
                              int data,
                              int bytes)

startsWith

public final boolean startsWith(byte[] haystack,
                                byte[] needle)

readBytes

public final byte[] readBytes(java.io.InputStream is,
                              int count)
                       throws ImageReadException,
                              java.io.IOException
Throws:
ImageReadException
java.io.IOException

readAndVerifyBytes

public final void readAndVerifyBytes(java.io.InputStream is,
                                     byte[] expected,
                                     java.lang.String exception)
                              throws ImageReadException,
                                     java.io.IOException
Throws:
ImageReadException
java.io.IOException

readAndVerifyBytes

protected final void readAndVerifyBytes(java.lang.String name,
                                        java.io.InputStream is,
                                        byte[] expected,
                                        java.lang.String exception)
                                 throws ImageReadException,
                                        java.io.IOException
Throws:
ImageReadException
java.io.IOException

skipBytes

public final void skipBytes(java.io.InputStream is,
                            int length,
                            java.lang.String exception)
                     throws java.io.IOException
Throws:
java.io.IOException

scanForByte

protected final void scanForByte(java.io.InputStream is,
                                 byte value)
                          throws java.io.IOException
Throws:
java.io.IOException

readByte

public final byte readByte(java.lang.String name,
                           java.io.InputStream is,
                           java.lang.String exception)
                    throws ImageReadException,
                           java.io.IOException
Throws:
ImageReadException
java.io.IOException

convertByteArrayToRationalArray

protected final RationalNumber[] convertByteArrayToRationalArray(java.lang.String name,
                                                                 byte[] bytes,
                                                                 int start,
                                                                 int length,
                                                                 int byteOrder)

convertByteArrayToRational

protected final RationalNumber convertByteArrayToRational(java.lang.String name,
                                                          byte[] bytes,
                                                          int byteOrder)

convertByteArrayToRational

protected final RationalNumber convertByteArrayToRational(java.lang.String name,
                                                          byte[] bytes,
                                                          int start,
                                                          int byteOrder)

convertByteArrayToInt

protected final int convertByteArrayToInt(java.lang.String name,
                                          byte[] bytes,
                                          int byteOrder)

convertByteArrayToInt

protected final int convertByteArrayToInt(java.lang.String name,
                                          byte[] bytes,
                                          int start,
                                          int byteOrder)

convertByteArrayToIntArray

protected final int[] convertByteArrayToIntArray(java.lang.String name,
                                                 byte[] bytes,
                                                 int start,
                                                 int length,
                                                 int byteOrder)

writeIntInToByteArray

protected final void writeIntInToByteArray(int value,
                                           byte[] bytes,
                                           int start,
                                           int byteOrder)

int2ToByteArray

protected static final byte[] int2ToByteArray(int value,
                                              int byteOrder)

convertIntArrayToByteArray

protected final byte[] convertIntArrayToByteArray(int[] values,
                                                  int byteOrder)

convertShortArrayToByteArray

protected final byte[] convertShortArrayToByteArray(int[] values,
                                                    int byteOrder)

convertShortToByteArray

protected final byte[] convertShortToByteArray(int value,
                                               int byteOrder)

convertIntArrayToRationalArray

protected final byte[] convertIntArrayToRationalArray(int[] numerators,
                                                      int[] denominators,
                                                      int byteOrder)
                                               throws ImageWriteException
Throws:
ImageWriteException

convertRationalArrayToByteArray

protected final byte[] convertRationalArrayToByteArray(RationalNumber[] numbers,
                                                       int byteOrder)
                                                throws ImageWriteException
Throws:
ImageWriteException

convertRationalToByteArray

protected final byte[] convertRationalToByteArray(RationalNumber number,
                                                  int byteOrder)
                                           throws ImageWriteException
Throws:
ImageWriteException

convertByteArrayToShort

protected final int convertByteArrayToShort(java.lang.String name,
                                            byte[] bytes,
                                            int byteOrder)
                                     throws ImageReadException
Throws:
ImageReadException

convertByteArrayToShort

protected final int convertByteArrayToShort(java.lang.String name,
                                            int index,
                                            byte[] bytes,
                                            int byteOrder)
                                     throws ImageReadException
Throws:
ImageReadException

convertByteArrayToShortArray

protected final int[] convertByteArrayToShortArray(java.lang.String name,
                                                   byte[] bytes,
                                                   int start,
                                                   int length,
                                                   int byteOrder)
                                            throws ImageReadException
Throws:
ImageReadException

readByteArray

public final byte[] readByteArray(java.lang.String name,
                                  int length,
                                  java.io.InputStream is)
                           throws java.io.IOException
Throws:
java.io.IOException

readByteArray

public final byte[] readByteArray(java.lang.String name,
                                  int length,
                                  java.io.InputStream is,
                                  java.lang.String exception)
                           throws java.io.IOException
Throws:
java.io.IOException

debugByteArray

public final void debugByteArray(java.lang.String name,
                                 byte[] bytes)

debugNumberArray

protected final void debugNumberArray(java.lang.String name,
                                      int[] numbers,
                                      int length)

readBytearray

public final byte[] readBytearray(java.lang.String name,
                                  byte[] bytes,
                                  int start,
                                  int count)
                           throws ImageReadException
Throws:
ImageReadException

getByteArrayTail

protected final byte[] getByteArrayTail(java.lang.String name,
                                        byte[] bytes,
                                        int count)
                                 throws ImageReadException
Throws:
ImageReadException

getBytearrayHead

protected final byte[] getBytearrayHead(java.lang.String name,
                                        byte[] bytes,
                                        int count)
                                 throws ImageReadException
Throws:
ImageReadException

slice

public static final byte[] slice(byte[] bytes,
                                 int start,
                                 int count)

tail

public static final byte[] tail(byte[] bytes,
                                int count)

head

public static final byte[] head(byte[] bytes,
                                int count)

compareByteArrays

public final boolean compareByteArrays(byte[] a,
                                       byte[] b)

compareByteArrays

public final boolean compareByteArrays(byte[] a,
                                       int aStart,
                                       byte[] b,
                                       int bStart,
                                       int length)

compareBytes

public static final boolean compareBytes(byte[] a,
                                         byte[] b)

compareBytes

public static final boolean compareBytes(byte[] a,
                                         int aStart,
                                         byte[] b,
                                         int bStart,
                                         int length)

read4Bytes

protected final int read4Bytes(java.lang.String name,
                               java.io.InputStream is,
                               java.lang.String exception,
                               int byteOrder)
                        throws ImageReadException,
                               java.io.IOException
Throws:
ImageReadException
java.io.IOException

read3Bytes

protected final int read3Bytes(java.lang.String name,
                               java.io.InputStream is,
                               java.lang.String exception,
                               int byteOrder)
                        throws ImageReadException,
                               java.io.IOException
Throws:
ImageReadException
java.io.IOException

read2Bytes

protected final int read2Bytes(java.lang.String name,
                               java.io.InputStream is,
                               java.lang.String exception,
                               int byteOrder)
                        throws ImageReadException,
                               java.io.IOException
Throws:
ImageReadException
java.io.IOException

printCharQuad

protected final void printCharQuad(java.lang.String msg,
                                   int i)

printCharQuad

protected final void printCharQuad(java.io.PrintWriter pw,
                                   java.lang.String msg,
                                   int i)

printByteBits

protected final void printByteBits(java.lang.String msg,
                                   byte i)

CharsToQuad

public static final int CharsToQuad(char c1,
                                    char c2,
                                    char c3,
                                    char c4)

findNull

public final int findNull(byte[] src)

findNull

public final int findNull(byte[] src,
                          int start)

getRAFBytes

protected final byte[] getRAFBytes(java.io.RandomAccessFile raf,
                                   long pos,
                                   int length,
                                   java.lang.String exception)
                            throws java.io.IOException
Throws:
java.io.IOException

convertByteArrayToFloat

protected final float convertByteArrayToFloat(java.lang.String name,
                                              byte[] bytes,
                                              int byteOrder)

convertByteArrayToFloat

protected final float convertByteArrayToFloat(java.lang.String name,
                                              byte[] bytes,
                                              int start,
                                              int byteOrder)

convertByteArrayToFloatArray

protected final float[] convertByteArrayToFloatArray(java.lang.String name,
                                                     byte[] bytes,
                                                     int start,
                                                     int length,
                                                     int byteOrder)

convertFloatToByteArray

protected final byte[] convertFloatToByteArray(float value,
                                               int byteOrder)

convertFloatArrayToByteArray

protected final byte[] convertFloatArrayToByteArray(float[] values,
                                                    int byteOrder)

convertDoubleToByteArray

protected final byte[] convertDoubleToByteArray(double value,
                                                int byteOrder)

convertDoubleArrayToByteArray

protected final byte[] convertDoubleArrayToByteArray(double[] values,
                                                     int byteOrder)

convertByteArrayToDouble

protected final double convertByteArrayToDouble(java.lang.String name,
                                                byte[] bytes,
                                                int byteOrder)

convertByteArrayToDouble

protected final double convertByteArrayToDouble(java.lang.String name,
                                                byte[] bytes,
                                                int start,
                                                int byteOrder)

convertByteArrayToDoubleArray

protected final double[] convertByteArrayToDoubleArray(java.lang.String name,
                                                       byte[] bytes,
                                                       int start,
                                                       int length,
                                                       int byteOrder)

skipBytes

protected void skipBytes(java.io.InputStream is,
                         int length)
                  throws java.io.IOException
Throws:
java.io.IOException

copyStreamToStream

public final void copyStreamToStream(java.io.InputStream is,
                                     java.io.OutputStream os)
                              throws java.io.IOException
Throws:
java.io.IOException

getStreamBytes

public final byte[] getStreamBytes(java.io.InputStream is)
                            throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2007-2009. All Rights Reserved.