j3d.org Code

org.j3d.io
Class EndianConverter

java.lang.Object
  extended by org.j3d.io.EndianConverter

public class EndianConverter
extends java.lang.Object

Utility to convert little endian data to big endian data. Includes methods to read from an InputStream and write to an OutputStream.

Todo: extend to convert big endian to little endain data and write to OutputStream

Version:
$Revision: 1.1 $
Author:
Dipl. Ing. Paul Szawlowski - University of Vienna, Dept. of Medical Computer Sciences

Constructor Summary
EndianConverter()
           
 
Method Summary
static int convert(byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts bytes in little/big endian order in srcBuffer to big/little endian signed integer (4 bytes long) data.
static int convert(byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength, int mask)
          Converts bytes in little/big endian order in srcBuffer to big/little endian integer (4 bytes long) data.
static int convert(byte[] srcBuffer, long[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts bytes in little/big endian order in srcBuffer to big/little endian long (8 bytes long) data.
static int convert(byte[] srcBuffer, long[] destBuffer, int srcLength, int destOffset, int destLength, long mask)
          Converts bytes in little/big endian order in srcBuffer to big/little endian long (8 bytes long) data.
static int convert(byte[] srcBuffer, short[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts byte in little/big endian order in srcBuffer to big/little endian signed short (2 bytes long) data.
static int convert(byte[] srcBuffer, short[] destBuffer, int srcLength, int destOffset, int destLength, short mask)
          Converts bytes in little/big endian order in srcBuffer to big/little endian short (2 bytes long) data.
static int convert(int value)
          Convert a little/big endian signed integer to a big/little endian signed integer
static int convert(int blockSize, byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts bytes in little/big endian order in srcBuffer to big/little endian signed integer data with a user defined block size of 2, 3, or 4 bytes.
static int convert(int blockSize, byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength, int mask)
          Converts bytes in little/big endian order in srcBuffer to big/little endian signed integer data with a user defined block size of 2, 3, or 4 bytes.
static long convert(long value)
          Convert a little/big endian signed long to a big/little endian signed long
static short convert(short value)
          Convert a little/big endian signed short to a big/little endian signed short
static int convertLittleEndianToDouble(byte[] srcBuffer, double[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts bytes in srcBuffer in little endian order to double data.
static int convertLittleEndianToFloat(byte[] srcBuffer, float[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts bytes in srcBuffer in little endian order to float data.
static int convertToLittleEndian(double[] srcBuffer, byte[] destBuffer, int srcOffset, int srcLength)
          Converts double data in srcBuffer to bytes in little endian order.
static int convertToLittleEndian(float[] srcBuffer, byte[] destBuffer, int srcOffset, int srcLength)
          Converts float data in srcBuffer to bytes in little endian order.For the conversion the Float.floatToIntBits method is used.
static int convertToLittleEndian(int[] srcBuffer, byte[] destBuffer, int srcOffset, int srcLength)
          Converts signed int data in srcBuffer to bytes in little endian order.
static int convertToLittleEndian(int blockSize, int[] srcBuffer, byte[] destBuffer, int srcOffset, int srcLength)
          Converts signed int data in srcBuffer to bytes in little endian order with a user defined block size of 1, 2, 3 or 4 (1 is here for convinience).
static int convertToLittleEndian(long[] srcBuffer, byte[] destBuffer, int srcOffset, int srcLength)
          Converts signed long data in srcBuffer to bytes in little endian order.
static int convertToLittleEndian(short[] srcBuffer, byte[] destBuffer, int srcOffset, int srcLength)
          Converts signed short data in srcBuffer to bytes in little endian order.
static int read(byte[] readBuffer, int[] destBuffer, int destOffset, int destLength, java.io.InputStream stream)
          Reads little/big endian data from an InputStream and converts it to big/little endian signed int (4 bytes long) data.
static int read(byte[] readBuffer, int[] destBuffer, int destOffset, int destLength, java.io.InputStream stream, int mask)
          Reads little/big endian data from an InputStream and converts it to big/little endian int (4 bytes long) data.
static int read(byte[] readBuffer, short[] destBuffer, int destOffset, int destLength, java.io.InputStream stream)
          Reads little/big endian data from an InputStream and converts it to big/little endian signed short (2 bytes long) data.
static int read(byte[] readBuffer, short[] destBuffer, int destOffset, int destLength, java.io.InputStream stream, short mask)
          Reads little/big endian data from an InputStream and converts it to big/little endian short (2 bytes long) data.
static int read(int blockSize, byte[] readBuffer, int[] destBuffer, int destOffset, int destLength, java.io.InputStream stream)
          Reads little/big endian data from an InputStream and converts it to to big/little endian signed integer data with a user defined block size of 1, 2, 3, or 4 bytes (1 is here for conveniance).
static int read(int blockSize, byte[] readBuffer, int[] destBuffer, int destOffset, int destLength, java.io.InputStream stream, int mask)
          Reads little/big endian data from an InputStream and converts it to to big/little endian signed integer data with a user defined block size of 1, 2, 3, or 4 bytes (1 is here for conveniance).
static int read2ByteBlock(java.io.InputStream stream)
          Reads 2 bytes in little/big endian format and converts it to a big/little endian signed int.
static int read3ByteBlock(java.io.InputStream stream)
          Reads 3 bytes in little/big endian format and converts it to a big/little endian signed int.
static int read4ByteBlock(java.io.InputStream stream)
          Reads 4 bytes in little/big endian format and converts it to a big/little endian signed int.
static long read8ByteBlock(java.io.InputStream stream)
          Reads 8 bytes in little/big endian format and converts it to a big/little endian signed long.
static void writeLittleEndian(double[] srcBuffer, int srcOffset, int srcLength, java.io.OutputStream stream, byte[] tempBuffer)
          Writes double data in srcBuffer to stream in little endian order.
static void writeLittleEndian(float[] srcBuffer, int srcOffset, int srcLength, java.io.OutputStream stream, byte[] tempBuffer)
          Writes float data in srcBuffer to stream in little endian order.
static void writeLittleEndian(int[] srcBuffer, int srcOffset, int srcLength, java.io.OutputStream stream, byte[] tempBuffer)
          Writes signed int data in srcBuffer to stream in little endian order.
static void writeLittleEndian(int blockSize, int[] srcBuffer, int srcOffset, int srcLength, java.io.OutputStream stream, byte[] tempBuffer)
          Writes signed int data in srcBuffer to stream in little endian order.
static void writeLittleEndian(long[] srcBuffer, int srcOffset, int srcLength, java.io.OutputStream stream, byte[] tempBuffer)
          Writes signed long data in srcBuffer to stream in little endian order.
static void writeLittleEndian(java.io.OutputStream stream, int value)
          Writes signed int data to stream in little endian order.
static void writeLittleEndian(java.io.OutputStream stream, long value)
          Writes signed long data to stream in little endian order.
static void writeLittleEndian(java.io.OutputStream stream, short value)
          Writes signed short data to stream in little endian order.
static void writeLittleEndian(short[] srcBuffer, int srcOffset, int srcLength, java.io.OutputStream stream, byte[] tempBuffer)
          Writes signed short data in srcBuffer to stream in little endian order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EndianConverter

public EndianConverter()
Method Detail

convert

public static int convert(byte[] srcBuffer,
                          short[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength)
Converts byte in little/big endian order in srcBuffer to big/little endian signed short (2 bytes long) data.

Parameters:
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least 2.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
Returns:
(even) number of processed bytes of srcBuffer

convert

public static int convert(byte[] srcBuffer,
                          short[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength,
                          short mask)
Converts bytes in little/big endian order in srcBuffer to big/little endian short (2 bytes long) data. Significant bits can be masked, e. g. to get unsigned 7 bit values use 0x7f as mask.

Parameters:
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least 2.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
mask - Mask for significant bits. Set significant bits to 1.
Returns:
(even) number of processed bytes of srcBuffer

convert

public static int convert(byte[] srcBuffer,
                          int[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength)
Converts bytes in little/big endian order in srcBuffer to big/little endian signed integer (4 bytes long) data.

Parameters:
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least 4.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
Returns:
number of processed bytes of srcBuffer (multiple of 4 )

convert

public static int convert(byte[] srcBuffer,
                          int[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength,
                          int mask)
Converts bytes in little/big endian order in srcBuffer to big/little endian integer (4 bytes long) data. Significant bits can be masked, e. g. to get unsigned 31 bit values use 0x7fffffff as mask.

Parameters:
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least 4.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
mask - Mask for significant bits. Set significant bits to 1.
Returns:
number of processed bytes of srcBuffer (multiple of 4 )

convert

public static int convert(byte[] srcBuffer,
                          long[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength)
Converts bytes in little/big endian order in srcBuffer to big/little endian long (8 bytes long) data.

Parameters:
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least 8.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
Returns:
number of processed bytes of srcBuffer (multiple of 8 )

convert

public static int convert(byte[] srcBuffer,
                          long[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength,
                          long mask)
Converts bytes in little/big endian order in srcBuffer to big/little endian long (8 bytes long) data. Significant bits can be masked, e. g. to get unsigned 63 bit values use 0x7fffffffffffffff as mask.

Parameters:
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least 8.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
mask - Mask for significant bits. Set significant bits to 1.
Returns:
number of processed bytes of srcBuffer (multiple of 8 )

convert

public static short convert(short value)
Convert a little/big endian signed short to a big/little endian signed short

Parameters:
value - number to convert

convert

public static int convert(int value)
Convert a little/big endian signed integer to a big/little endian signed integer

Parameters:
value - number to convert

convert

public static long convert(long value)
Convert a little/big endian signed long to a big/little endian signed long

Parameters:
value - number to convert

convertLittleEndianToFloat

public static int convertLittleEndianToFloat(byte[] srcBuffer,
                                             float[] destBuffer,
                                             int srcLength,
                                             int destOffset,
                                             int destLength)
Converts bytes in srcBuffer in little endian order to float data.

Parameters:
srcBuffer - Bytes in little endian order which shall be converted. The size of the array must be at least 4.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
Returns:
number of processed bytes of srcBuffer (multiple of 4 )

convertLittleEndianToDouble

public static int convertLittleEndianToDouble(byte[] srcBuffer,
                                              double[] destBuffer,
                                              int srcLength,
                                              int destOffset,
                                              int destLength)
Converts bytes in srcBuffer in little endian order to double data.

Parameters:
srcBuffer - Bytes in little endian order which shall be converted. The size of the array must be at least 8.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
Returns:
number of processed bytes of srcBuffer (multiple of 8 )

convert

public static int convert(int blockSize,
                          byte[] srcBuffer,
                          int[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength)
Converts bytes in little/big endian order in srcBuffer to big/little endian signed integer data with a user defined block size of 2, 3, or 4 bytes.

Parameters:
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least blockSize.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
blockSize - May be 2, 3 or 4.
Returns:
number of processed bytes of srcBuffer (multiple of blockSize)

convert

public static int convert(int blockSize,
                          byte[] srcBuffer,
                          int[] destBuffer,
                          int srcLength,
                          int destOffset,
                          int destLength,
                          int mask)
Converts bytes in little/big endian order in srcBuffer to big/little endian signed integer data with a user defined block size of 2, 3, or 4 bytes. Significant bits can be masked, e. g. to get unsigned 16 bit values use 0xffff as mask.

Parameters:
blockSize - May be 2, 3 or 4.
srcBuffer - Bytes in little/big endian order which shall be converted. The size of the array must be at least blockSize.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
srcLength - Number of bytes of srcBuffer which shall be processed. Must be <= length of srcBuffer.
destOffset - Offset for writing converted data in destBuffer.
destLength - Maximum number of data to be written in destBuffer
mask - Mask for significant bits. Set significant bits to 1.
Returns:
number of processed bytes of srcBuffer (multiple of blockSize)

convertToLittleEndian

public static int convertToLittleEndian(short[] srcBuffer,
                                        byte[] destBuffer,
                                        int srcOffset,
                                        int srcLength)
Converts signed short data in srcBuffer to bytes in little endian order.

Parameters:
srcBuffer - Signed short data to be converted. The size of array must be at least srcOffset + srcLength.
destBuffer - Buffer to store the converted data bytes in little endian order. The first valid byte will start at 0. The size of the array must be at least 2.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
Returns:
number of processed short data from srcBuffer. Multiply by 2 to get the number of valid bytes in destBuffer.

convertToLittleEndian

public static int convertToLittleEndian(int[] srcBuffer,
                                        byte[] destBuffer,
                                        int srcOffset,
                                        int srcLength)
Converts signed int data in srcBuffer to bytes in little endian order.

Parameters:
srcBuffer - Signed int data to be converted. The size of array must be at least srcOffset + srcLength.
destBuffer - Buffer to store the converted data bytes in little endian order. The first valid byte will start at 0. The size of the array must be at least 4.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
Returns:
number of processed short data from srcBuffer. Multiply by 4 to get the number of valid bytes in destBuffer.

convertToLittleEndian

public static int convertToLittleEndian(int blockSize,
                                        int[] srcBuffer,
                                        byte[] destBuffer,
                                        int srcOffset,
                                        int srcLength)
Converts signed int data in srcBuffer to bytes in little endian order with a user defined block size of 1, 2, 3 or 4 (1 is here for convinience).

Parameters:
blockSize - May be 1, 2, 3 or 4.
srcBuffer - Signed int data to be converted. The size of array must be at least srcOffset + srcLength.
destBuffer - Buffer to store the converted data bytes in little endian order. The first valid byte will start at 0. The size of the array must be at least blockSize.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
Returns:
number of processed short data from srcBuffer. Multiply by blockSize to get the number of valid bytes in destBuffer.

convertToLittleEndian

public static int convertToLittleEndian(long[] srcBuffer,
                                        byte[] destBuffer,
                                        int srcOffset,
                                        int srcLength)
Converts signed long data in srcBuffer to bytes in little endian order.

Parameters:
srcBuffer - Signed long data to be converted. The size of array must be at least srcOffset + srcLength.
destBuffer - Buffer to store the converted data bytes in little endian order. The first valid byte will start at 0. The size of the array must be at least 8.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
Returns:
number of processed short data from srcBuffer. Multiply by 8 to get the number of valid bytes in destBuffer.

convertToLittleEndian

public static int convertToLittleEndian(float[] srcBuffer,
                                        byte[] destBuffer,
                                        int srcOffset,
                                        int srcLength)
Converts float data in srcBuffer to bytes in little endian order.For the conversion the Float.floatToIntBits method is used.

Parameters:
srcBuffer - Float data to be converted. The size of array must be at least srcOffset + srcLength.
destBuffer - Buffer to store the converted data bytes in little endian order. The first valid byte will start at 0. The size of the array must be at least 4.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
Returns:
number of processed short data from srcBuffer. Multiply by 4 to get the number of valid bytes in destBuffer.

convertToLittleEndian

public static int convertToLittleEndian(double[] srcBuffer,
                                        byte[] destBuffer,
                                        int srcOffset,
                                        int srcLength)
Converts double data in srcBuffer to bytes in little endian order. For the conversion the Double.doubleToLongBits method is used.

Parameters:
srcBuffer - Double data to be converted. The size of array must be at least srcOffset + srcLength.
destBuffer - Buffer to store the converted data bytes in little endian order. The first valid byte will start at 0. The size of the array must be at least 8.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
Returns:
number of processed short data from srcBuffer. Multiply by 8 to get the number of valid bytes in destBuffer.

read

public static int read(byte[] readBuffer,
                       short[] destBuffer,
                       int destOffset,
                       int destLength,
                       java.io.InputStream stream)
                throws java.io.IOException
Reads little/big endian data from an InputStream and converts it to big/little endian signed short (2 bytes long) data.

Parameters:
readBuffer - Auxilary Buffer to be used to read from stream. Choose an appropriate size (multiple of 2) depending on the size of the stream. The size of the array must be at least 2.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
stream - InputStream to read from.
Returns:
number of data elements written in destBuffer (will be <= destLength).
Throws:
java.io.IOException

read

public static int read(byte[] readBuffer,
                       short[] destBuffer,
                       int destOffset,
                       int destLength,
                       java.io.InputStream stream,
                       short mask)
                throws java.io.IOException
Reads little/big endian data from an InputStream and converts it to big/little endian short (2 bytes long) data. Significant bits can be masked, e. g. to get unsigned 7 bit values use 0x7f as mask.

Parameters:
readBuffer - Auxilary Buffer to be used to read from stream. Choose an appropriate size (multiple of 2) depending on the size of the stream. The size of the array must be at least 2.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
stream - InputStream to read from.
mask - Mask for significant bits. Set significant bits to 1.
Returns:
number of data elements written in destBuffer (will be <= destLength).
Throws:
java.io.IOException

read

public static int read(byte[] readBuffer,
                       int[] destBuffer,
                       int destOffset,
                       int destLength,
                       java.io.InputStream stream)
                throws java.io.IOException
Reads little/big endian data from an InputStream and converts it to big/little endian signed int (4 bytes long) data.

Parameters:
readBuffer - Auxilary Buffer to be used to read from stream. Choose an appropriate size (multiple of 4) depending on the size of the stream. The size of the array must be at least 4.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
stream - InputStream to read from.
Returns:
number of data elements written in destBuffer (will be <= destLength).
Throws:
java.io.IOException

read

public static int read(byte[] readBuffer,
                       int[] destBuffer,
                       int destOffset,
                       int destLength,
                       java.io.InputStream stream,
                       int mask)
                throws java.io.IOException
Reads little/big endian data from an InputStream and converts it to big/little endian int (4 bytes long) data. Significant bits can be masked, e. g. to get unsigned 31 bit values use 0x7fffffff as mask.

Parameters:
readBuffer - Auxilary Buffer to be used to read from stream. Choose an appropriate size (multiple of 4) depending on the size of the stream. The size of the array must be at least 4.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
stream - InputStream to read from.
mask - Mask for significant bits. Set significant bits to 1.
Returns:
number of data elements written in destBuffer (will be <= destLength).
Throws:
java.io.IOException

read

public static int read(int blockSize,
                       byte[] readBuffer,
                       int[] destBuffer,
                       int destOffset,
                       int destLength,
                       java.io.InputStream stream)
                throws java.io.IOException
Reads little/big endian data from an InputStream and converts it to to big/little endian signed integer data with a user defined block size of 1, 2, 3, or 4 bytes (1 is here for conveniance).

Parameters:
blockSize - May be 1, 2, 3 or 4.
readBuffer - Auxilary Buffer to be used to read from stream. Choose an appropriate size (multiple of blockSize) depending on the size of the stream. The size of the array must be at least blockSize.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
stream - InputStream to read from.
Returns:
number of data elements written in destBuffer (will be <= destLength).
Throws:
java.io.IOException

read

public static int read(int blockSize,
                       byte[] readBuffer,
                       int[] destBuffer,
                       int destOffset,
                       int destLength,
                       java.io.InputStream stream,
                       int mask)
                throws java.io.IOException
Reads little/big endian data from an InputStream and converts it to to big/little endian signed integer data with a user defined block size of 1, 2, 3, or 4 bytes (1 is here for conveniance). Significant bits can be masked, e. g. to get unsigned 16 bit values use 0xffff as mask.

Parameters:
blockSize - May be 1, 2, 3 or 4.
readBuffer - Auxilary Buffer to be used to read from stream. Choose an appropriate size (multiple of blockSize) depending on the size of the stream. The size of the array must be at least blockSize.
destBuffer - Buffer to store the converted data. The size of the array must be at least destOffset + destLength.
destOffset - Offset for writing converted data in destBuffer.
destLength - Max. number of data to be written in destBuffer
stream - InputStream to read from.
mask - Mask for significant bits. Set significant bits to 1.
Returns:
number of data elements written in destBuffer (will be <= destLength).
Throws:
java.io.IOException

read4ByteBlock

public static int read4ByteBlock(java.io.InputStream stream)
                          throws java.io.IOException
Reads 4 bytes in little/big endian format and converts it to a big/little endian signed int.

Throws:
java.io.IOException - if EOF occurs and only one, 2 or 3 bytes were read or if error during reading occurs

read2ByteBlock

public static int read2ByteBlock(java.io.InputStream stream)
                          throws java.io.IOException
Reads 2 bytes in little/big endian format and converts it to a big/little endian signed int.

To Convert it to an unsigned int & the result with 0xffff.

Throws:
java.io.IOException - if EOF occurs and only one bytes was read or if error during reading occurs

read3ByteBlock

public static int read3ByteBlock(java.io.InputStream stream)
                          throws java.io.IOException
Reads 3 bytes in little/big endian format and converts it to a big/little endian signed int.

To Convert it to an unsigned int & the result with 0xffffff.

Throws:
java.io.IOException - if EOF occurs and only one or 2 bytes were read or if error during reading occurs

read8ByteBlock

public static long read8ByteBlock(java.io.InputStream stream)
                           throws java.io.IOException
Reads 8 bytes in little/big endian format and converts it to a big/little endian signed long.

To Convert it to an unsigned int & the result with 0xffffff.

Throws:
java.io.IOException - if EOF occurs and only one or 2 bytes were read or if error during reading occurs

writeLittleEndian

public static void writeLittleEndian(short[] srcBuffer,
                                     int srcOffset,
                                     int srcLength,
                                     java.io.OutputStream stream,
                                     byte[] tempBuffer)
                              throws java.io.IOException
Writes signed short data in srcBuffer to stream in little endian order.

Parameters:
srcBuffer - Signed short data to be converted. The size of array must be at least srcOffset + srcLength.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
tempBuffer - Temporary buffer to store the converted data bytes in little endian order. The size of the array must be at least 2 and should be a multiple of 2. Use an appropriate size according to srcLength.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(int[] srcBuffer,
                                     int srcOffset,
                                     int srcLength,
                                     java.io.OutputStream stream,
                                     byte[] tempBuffer)
                              throws java.io.IOException
Writes signed int data in srcBuffer to stream in little endian order.

Parameters:
srcBuffer - Signed short data to be converted. The size of array must be at least srcOffset + srcLength.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
tempBuffer - Temporary buffer to store the converted data bytes in little endian order. The size of the array must be at least 4 and should be a multiple of 4. Use an appropriate size according to srcLength.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(long[] srcBuffer,
                                     int srcOffset,
                                     int srcLength,
                                     java.io.OutputStream stream,
                                     byte[] tempBuffer)
                              throws java.io.IOException
Writes signed long data in srcBuffer to stream in little endian order.

Parameters:
srcBuffer - Signed short data to be converted. The size of array must be at least srcOffset + srcLength.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
tempBuffer - Temporary buffer to store the converted data bytes in little endian order. The size of the array must be at least 8 and should be a multiple of 8. Use an appropriate size according to srcLength.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(int blockSize,
                                     int[] srcBuffer,
                                     int srcOffset,
                                     int srcLength,
                                     java.io.OutputStream stream,
                                     byte[] tempBuffer)
                              throws java.io.IOException
Writes signed int data in srcBuffer to stream in little endian order.

Parameters:
srcBuffer - Signed short data to be converted. The size of array must be at least srcOffset + srcLength.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
tempBuffer - Temporary buffer to store the converted data bytes in little endian order. The size of the array must be at least blockSize and should be a multiple of blockSize. Use an appropriate size according to srcLength.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(float[] srcBuffer,
                                     int srcOffset,
                                     int srcLength,
                                     java.io.OutputStream stream,
                                     byte[] tempBuffer)
                              throws java.io.IOException
Writes float data in srcBuffer to stream in little endian order. For the conversion the Float.floatToIntBits method is used.

Parameters:
srcBuffer - Signed short data to be converted. The size of array must be at least srcOffset + srcLength.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
tempBuffer - Temporary buffer to store the converted data bytes in little endian order. The size of the array must be at least 4 and should be a multiple of 4. Use an appropriate size according to srcLength.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(double[] srcBuffer,
                                     int srcOffset,
                                     int srcLength,
                                     java.io.OutputStream stream,
                                     byte[] tempBuffer)
                              throws java.io.IOException
Writes double data in srcBuffer to stream in little endian order. For the conversion the Double.doubleToLongBits method is used.

Parameters:
srcBuffer - Signed short data to be converted. The size of array must be at least srcOffset + srcLength.
srcOffset - Offset for reading data from srcBuffer.
srcLength - Max. Number of data to be processed from srcBuffer.
tempBuffer - Temporary buffer to store the converted data bytes in little endian order. The size of the array must be at least 8 and should be a multiple of 8. Use an appropriate size according to srcLength.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(java.io.OutputStream stream,
                                     short value)
                              throws java.io.IOException
Writes signed short data to stream in little endian order.

Parameters:
stream - OutputStream to write to.
value - Signed short data to be written.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(java.io.OutputStream stream,
                                     int value)
                              throws java.io.IOException
Writes signed int data to stream in little endian order.

Parameters:
stream - OutputStream to write to.
value - Signed int data to be written.
Throws:
java.io.IOException

writeLittleEndian

public static void writeLittleEndian(java.io.OutputStream stream,
                                     long value)
                              throws java.io.IOException
Writes signed long data to stream in little endian order.

Parameters:
stream - OutputStream to write to.
value - Signed long data to be written.
Throws:
java.io.IOException

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org