j3d.org Code

org.j3d.loaders.stl
Class LittleEndianConverter

java.lang.Object
  extended by org.j3d.loaders.stl.LittleEndianConverter

public class LittleEndianConverter
extends java.lang.Object

Utility to convert little endain data to big endian data.

TODO: Extend to convert big endian to little endain data and write to OutputStream

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

Constructor Summary
LittleEndianConverter()
           
 
Method Summary
static int convertToBigEndian(byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts little endian data in srcBuffer to big endian signed integer (4 bytes long) data.
static int convertToBigEndian(byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength, int mask)
          Converts little endian data in srcBuffer to big endian integer (4 bytes long) data.
static int convertToBigEndian(byte[] srcBuffer, short[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts little endian data in srcBuffer to big endian signed short (2 bytes long) data.
static int convertToBigEndian(byte[] srcBuffer, short[] destBuffer, int srcLength, int destOffset, int destLength, short mask)
          Converts little endian data in srcBuffer to big endian short (2 bytes long) data.
static int convertToBigEndian(int blockSize, byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength)
          Converts little endian data in srcBuffer to big endian signed integer data with a user defined block size of 2, 3, or 4 bytes.
static int convertToBigEndian(int blockSize, byte[] srcBuffer, int[] destBuffer, int srcLength, int destOffset, int destLength, int mask)
          Converts little endian data in srcBuffer to big endian signed integer data with a user defined block size of 2, 3, or 4 bytes.
static int read(byte[] readBuffer, int[] destBuffer, int destOffset, int destLength, java.io.InputStream stream)
          Reads little endian data from an InputStream and converts it to big 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 endian data from an InputStream and converts it to big endian int (4 bytes long) data.
static int read(byte[] readBuffer, short[] destBuffer, int destOffset, int destLength, java.io.InputStream stream)
          Reads little endian data from an InputStream and converts it to big 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 endian data from an InputStream and converts it to big 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 endian data from an InputStream and converts it to to big 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 endian data from an InputStream and converts it to to big 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 endian format and converts it to a signed int.
static int read3ByteBlock(java.io.InputStream stream)
          Reads 3 bytes in little endian format and converts it to a signed int.
static int read4ByteBlock(java.io.InputStream stream)
          Reads 4 bytes in little endian format and converts it to a signed int.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LittleEndianConverter

public LittleEndianConverter()
Method Detail

convertToBigEndian

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

Parameters:
srcBuffer - Data in little endian format 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

convertToBigEndian

public static int convertToBigEndian(byte[] srcBuffer,
                                     short[] destBuffer,
                                     int srcLength,
                                     int destOffset,
                                     int destLength,
                                     short mask)
Converts little endian data in srcBuffer to big 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 - Data in little endian format 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

convertToBigEndian

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

Parameters:
srcBuffer - Data in little endian format 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 )

convertToBigEndian

public static int convertToBigEndian(byte[] srcBuffer,
                                     int[] destBuffer,
                                     int srcLength,
                                     int destOffset,
                                     int destLength,
                                     int mask)
Converts little endian data in srcBuffer to big 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 - Data in little endian format 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 )

convertToBigEndian

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

Parameters:
srcBuffer - Data in little endian format 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)

convertToBigEndian

public static int convertToBigEndian(int blockSize,
                                     byte[] srcBuffer,
                                     int[] destBuffer,
                                     int srcLength,
                                     int destOffset,
                                     int destLength,
                                     int mask)
Converts little endian data in srcBuffer to big 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 - Data in little endian format 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)

read

public static int read(byte[] readBuffer,
                       short[] destBuffer,
                       int destOffset,
                       int destLength,
                       java.io.InputStream stream)
                throws java.io.IOException
Reads little endian data from an InputStream and converts it to big 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 endian data from an InputStream and converts it to big 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 endian data from an InputStream and converts it to big 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 endian data from an InputStream and converts it to big 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 endian data from an InputStream and converts it to to big 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 4) 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 endian data from an InputStream and converts it to to big 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 4) 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 endian format and converts it to a 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 endian format and converts it to a 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 endian format and converts it to a 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

j3d.org Code

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