|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jlab.coda.jevio.ByteDataTransformer
public class ByteDataTransformer
This utility class contains methods for transforming a raw byte array into arrays of other types and vice versa as well as other handy methods.
Constructor Summary | |
---|---|
ByteDataTransformer()
|
Method Summary | |
---|---|
static int |
byteBitsToInt(byte byteVal)
Copies a 1-byte byte value into a 4-byte int while preserving bit pattern. |
static double[] |
getAsDoubleArray(byte[] bytes,
java.nio.ByteOrder byteOrder)
Converts a byte array into a double array. |
static float[] |
getAsFloatArray(byte[] bytes,
java.nio.ByteOrder byteOrder)
Converts a byte array into a float array. |
static int[] |
getAsIntArray(byte[] bytes,
java.nio.ByteOrder byteOrder)
Converts a byte array into an int array. |
static long[] |
getAsLongArray(byte[] bytes,
java.nio.ByteOrder byteOrder)
Converts a byte array into a long array. |
static short[] |
getAsShortArray(byte[] bytes,
java.nio.ByteOrder byteOrder)
Converts a byte array into an short array. |
static short[] |
getAsShortArray(byte[] bytes,
int padding,
java.nio.ByteOrder byteOrder)
Converts a byte array into an short array while accounting for padding. |
static void |
intToBytes(int intVal,
byte[] b,
int off)
Copies an integer value into 4 bytes of a byte array. |
static int |
shortBitsToInt(short shortVal)
Copies a 2-byte short value into a 4-byte int while preserving bit pattern. |
static void |
shortToBytes(short val,
byte[] b,
int off)
Copies a short value into 2 bytes of a byte array. |
static byte[] |
toBytes(double[] data,
java.nio.ByteOrder byteOrder)
Turn double array into byte array. |
static void |
toBytes(double[] data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn double array into byte array. |
static byte[] |
toBytes(double data,
java.nio.ByteOrder byteOrder)
Turn double into byte array. |
static void |
toBytes(double data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn double into byte array. |
static byte[] |
toBytes(float[] data,
java.nio.ByteOrder byteOrder)
Turn float array into byte array. |
static void |
toBytes(float[] data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn float array into byte array. |
static byte[] |
toBytes(float data,
java.nio.ByteOrder byteOrder)
Turn float into byte array. |
static void |
toBytes(float data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn float into byte array. |
static byte[] |
toBytes(int[] data,
java.nio.ByteOrder byteOrder)
Turn int array into byte array. |
static void |
toBytes(int[] data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn int array into byte array. |
static byte[] |
toBytes(int[] data,
int offset,
int length,
java.nio.ByteOrder byteOrder)
Turn int array into byte array. |
static byte[] |
toBytes(int data,
java.nio.ByteOrder byteOrder)
Turn int into byte array. |
static void |
toBytes(int data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn int into byte array. |
static byte[] |
toBytes(long[] data,
java.nio.ByteOrder byteOrder)
Turn long array into byte array. |
static void |
toBytes(long[] data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn long array into byte array. |
static byte[] |
toBytes(long data,
java.nio.ByteOrder byteOrder)
Turn long into byte array. |
static void |
toBytes(long data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn long into byte array. |
static byte[] |
toBytes(short[] data,
java.nio.ByteOrder byteOrder)
Turn short array into byte array. |
static void |
toBytes(short[] data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn short array into byte array. |
static byte[] |
toBytes(short data,
java.nio.ByteOrder byteOrder)
Turn short into byte array. |
static void |
toBytes(short data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn short into byte array. |
static byte[] |
toBytes2(double[] data,
java.nio.ByteOrder byteOrder)
Turn double array into byte array. |
static void |
toBytes2(double[] data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn double array into byte array. |
static byte[] |
toBytesStream(int[] data,
java.nio.ByteOrder byteOrder)
Turn int array into byte array. |
static double |
toDouble(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into a double. |
static double |
toDouble(byte b1,
byte b2,
byte b3,
byte b4,
byte b5,
byte b6,
byte b7,
byte b8,
java.nio.ByteOrder byteOrder)
Turn 8 bytes into a double. |
static double[] |
toDoubleArray(byte[] data,
java.nio.ByteOrder byteOrder)
Turn byte array into a double array. |
static void |
toDoubleArray(byte[] data,
java.nio.ByteOrder byteOrder,
double[] dest,
int off)
Turn byte array into an double array. |
static float |
toFloat(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into a float. |
static float |
toFloat(byte b1,
byte b2,
byte b3,
byte b4,
java.nio.ByteOrder byteOrder)
Turn 4 bytes into a float. |
static float[] |
toFloatArray(byte[] data,
java.nio.ByteOrder byteOrder)
Turn byte array into a float array. |
static void |
toFloatArray(byte[] data,
java.nio.ByteOrder byteOrder,
float[] dest,
int off)
Turn byte array into an float array. |
static int |
toInt(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into an int. |
static int |
toInt(byte b1,
byte b2,
byte b3,
byte b4,
java.nio.ByteOrder byteOrder)
Turn 4 bytes into an int. |
static int[] |
toIntArray(byte[] data,
java.nio.ByteOrder byteOrder)
Turn byte array into an int array. |
static void |
toIntArray(byte[] data,
java.nio.ByteOrder byteOrder,
int[] dest,
int off)
Turn byte array into an int array. |
static long |
toLong(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into a long. |
static long |
toLong(byte b1,
byte b2,
byte b3,
byte b4,
byte b5,
byte b6,
byte b7,
byte b8,
java.nio.ByteOrder byteOrder)
Turn 8 bytes into a long. |
static long[] |
toLongArray(byte[] data,
java.nio.ByteOrder byteOrder)
Turn byte array into a long array. |
static void |
toLongArray(byte[] data,
java.nio.ByteOrder byteOrder,
long[] dest,
int off)
Turn byte array into an long array. |
static short |
toShort(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into a short. |
static short |
toShort(byte b1,
byte b2,
java.nio.ByteOrder byteOrder)
Turn 2 bytes into a short. |
static short[] |
toShortArray(byte[] data,
java.nio.ByteOrder byteOrder)
Turn byte array into a short array. |
static void |
toShortArray(byte[] data,
java.nio.ByteOrder byteOrder,
short[] dest,
int off)
Turn byte array into an short array. |
static short[] |
toShortArray(byte[] data,
int padding,
java.nio.ByteOrder byteOrder)
Turn byte array into a short array while taking padding into account. |
static void |
toShortArray(byte[] data,
int padding,
java.nio.ByteOrder byteOrder,
short[] dest,
int off)
Turn byte array into a short array while taking padding into account. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteDataTransformer()
Method Detail |
---|
public static int[] getAsIntArray(byte[] bytes, java.nio.ByteOrder byteOrder)
toIntArray(byte[], java.nio.ByteOrder)
for better performance.
bytes
- the byte array.byteOrder
- the endianness of the data in the byte array,
ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
.
public static short[] getAsShortArray(byte[] bytes, java.nio.ByteOrder byteOrder)
toShortArray(byte[], java.nio.ByteOrder)
for better performance.
bytes
- the byte array.byteOrder
- the endianness of the data in the byte array,
ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
.
public static short[] getAsShortArray(byte[] bytes, int padding, java.nio.ByteOrder byteOrder)
toShortArray(byte[], int, java.nio.ByteOrder)
for better performance.
bytes
- the byte array.padding
- number of bytes at the end of the byte array to ignore.
Valid values are 0 and mulitples of 2 (though only 0 & 2 are used).byteOrder
- the endianness of the data in the byte array,
ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
.
public static long[] getAsLongArray(byte[] bytes, java.nio.ByteOrder byteOrder)
toLongArray(byte[], java.nio.ByteOrder)
for better performance.
bytes
- the byte array.byteOrder
- the endianness of the data in the byte array,
ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
.
public static double[] getAsDoubleArray(byte[] bytes, java.nio.ByteOrder byteOrder)
toDoubleArray(byte[], java.nio.ByteOrder)
for better performance.
bytes
- the byte array.byteOrder
- the endianness of the data in the byte array,
ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
.
public static float[] getAsFloatArray(byte[] bytes, java.nio.ByteOrder byteOrder)
toFloatArray(byte[], java.nio.ByteOrder)
for better performance.
bytes
- the byte array.byteOrder
- the endianness of the data in the byte array,
ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
.
public static final int shortBitsToInt(short shortVal)
shortVal
- short value considered to be unsigned
public static final int byteBitsToInt(byte byteVal)
byteVal
- byte value considered to be unsigned
public static final void intToBytes(int intVal, byte[] b, int off)
intVal
- integer valueb
- byte arrayoff
- offset into the byte arraypublic static final void shortToBytes(short val, byte[] b, int off)
val
- short valueb
- byte arrayoff
- offset into the byte arraypublic static byte[] toBytes(short data, java.nio.ByteOrder byteOrder)
data
- short to convertbyteOrder
- byte order of returned byte array (big endian if null)
public static void toBytes(short data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- short to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if dest is null or too small or offset negativepublic static byte[] toBytes(short[] data, java.nio.ByteOrder byteOrder)
data
- short array to convertbyteOrder
- byte order of returned bytes (big endian if null)
public static void toBytes(short[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- short array to convertbyteOrder
- byte order of written bytes (big endian if null)dest
- array in which to store written bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if data is null, dest is null or too small, or offset negativepublic static byte[] toBytes(int data, java.nio.ByteOrder byteOrder)
data
- int to convertbyteOrder
- byte order of returned byte array (big endian if null)
public static void toBytes(int data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- int to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if dest is null or too small or offset negativepublic static byte[] toBytes(int[] data, java.nio.ByteOrder byteOrder)
data
- int array to convertbyteOrder
- byte order of returned bytes (big endian if null)
public static byte[] toBytes(int[] data, int offset, int length, java.nio.ByteOrder byteOrder)
data
- int array to convertoffset
- into int arraylength
- number of integers to conver to bytesbyteOrder
- byte order of returned bytes (big endian if null)
public static void toBytes(int[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- int array to convertbyteOrder
- byte order of written bytes (big endian if null)dest
- array in which to store written bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if data is null, dest is null or too small, or offset negativepublic static byte[] toBytesStream(int[] data, java.nio.ByteOrder byteOrder)
data
- int array to convertbyteOrder
- byte order of returned bytes (big endian if null)
public static byte[] toBytes(long data, java.nio.ByteOrder byteOrder)
data
- long to convertbyteOrder
- byte order of returned byte array (big endian if null)
public static void toBytes(long data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- long to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if dest is null or too small or offset negativepublic static byte[] toBytes(long[] data, java.nio.ByteOrder byteOrder)
data
- long array to convertbyteOrder
- byte order of returned bytes (big endian if null)
public static void toBytes(long[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- long array to convertbyteOrder
- byte order of written bytes (big endian if null)dest
- array in which to store written bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if data is null, dest is null or too small, or offset negativepublic static byte[] toBytes(float data, java.nio.ByteOrder byteOrder)
data
- float to convertbyteOrder
- byte order of returned byte array (big endian if null)
public static void toBytes(float data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- float to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if dest is null or too small or offset negativepublic static byte[] toBytes(float[] data, java.nio.ByteOrder byteOrder)
data
- float array to convertbyteOrder
- byte order of returned bytes (big endian if null)
public static void toBytes(float[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- float array to convertbyteOrder
- byte order of written bytes (big endian if null)dest
- array in which to store written bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if data is null, dest is null or too small, or offset negativepublic static byte[] toBytes(double data, java.nio.ByteOrder byteOrder)
data
- double to convertbyteOrder
- byte order of returned byte array (big endian if null)
public static void toBytes(double data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- double to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if dest is null or too small or offset negativepublic static byte[] toBytes(double[] data, java.nio.ByteOrder byteOrder)
data
- double array to convertbyteOrder
- byte order of returned bytes (big endian if null)
public static void toBytes(double[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
data
- double array to convertbyteOrder
- byte order of written bytes (big endian if null)dest
- array in which to store written bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if data is null, dest is null or too small, or offset negativepublic static byte[] toBytes2(double[] data, java.nio.ByteOrder byteOrder)
toBytes(double[], ByteOrder)
.
Keep this around for completeness purposes - a record
of what was already tried and found wanting. Tried this
for all data types.
data
- double array to convertbyteOrder
- byte order of returned bytes (big endian if null)
public static void toBytes2(double[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off) throws EvioException
toBytes(double[], ByteOrder, byte[], int)
.
Keep this around for completeness purposes - a record
of what was already tried and found wanting. Tried this
for all data types.
data
- double array to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placed
EvioException
- if data is null, dest is null or too small, or offset negativepublic static short toShort(byte[] data, java.nio.ByteOrder byteOrder, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data array
EvioException
- if data is null or wrong size, or off is negativepublic static short toShort(byte b1, byte b2, java.nio.ByteOrder byteOrder)
b1
- 1st byteb2
- 2nd bytebyteOrder
- if big endian, 1st byte is most significant (big endian if null)
public static short[] toShortArray(byte[] data, java.nio.ByteOrder byteOrder) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)
EvioException
- if data is null or odd sizepublic static short[] toShortArray(byte[] data, int padding, java.nio.ByteOrder byteOrder) throws EvioException
data
- byte array to convertpadding
- number of bytes at the end of the byte array to ignore.
Valid values are 0 and 2byteOrder
- byte order of supplied bytes (big endian if null)
EvioException
- if data is null or odd size; padding not 0 or 2public static void toShortArray(byte[] data, int padding, java.nio.ByteOrder byteOrder, short[] dest, int off) throws EvioException
data
- byte array to convertpadding
- number of bytes at the end of the byte array to ignore.
Valid values are 0 and 2byteOrder
- byte order of supplied bytes (big endian if null)dest
- array in which to write converted bytesoff
- offset into dest array
EvioException
- if data is null or wrong size; dest is null, wrong size, or off < 0public static void toShortArray(byte[] data, java.nio.ByteOrder byteOrder, short[] dest, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)dest
- array in which to write converted bytesoff
- offset into dest array
EvioException
- if data is null or wrong size; dest is null, wrong size, or off < 0public static int toInt(byte[] data, java.nio.ByteOrder byteOrder, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data array
EvioException
- if data is null or wrong size, or off is negativepublic static int toInt(byte b1, byte b2, byte b3, byte b4, java.nio.ByteOrder byteOrder)
b1
- 1st byteb2
- 2nd byteb3
- 3rd byteb4
- 4th bytebyteOrder
- if big endian, 1st byte is most significant &
4th is least (big endian if null)
public static int[] toIntArray(byte[] data, java.nio.ByteOrder byteOrder) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)
EvioException
- if data is null or wrong sizepublic static void toIntArray(byte[] data, java.nio.ByteOrder byteOrder, int[] dest, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)dest
- array in which to write converted bytesoff
- offset into dest array
EvioException
- if data is null or wrong size; dest is null, wrong size, or off < 0public static long toLong(byte[] data, java.nio.ByteOrder byteOrder, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data array
EvioException
- if data is null or wrong size, or off is negativepublic static long toLong(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8, java.nio.ByteOrder byteOrder)
b1
- 1st byteb2
- 2nd byteb3
- 3rd byteb4
- 4th byteb5
- 5th byteb6
- 6th byteb7
- 7th byteb8
- 8th bytebyteOrder
- if big endian, 1st byte is most significant &
8th least (big endian if null)
public static long[] toLongArray(byte[] data, java.nio.ByteOrder byteOrder) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)
EvioException
- if data is null or wrong sizepublic static void toLongArray(byte[] data, java.nio.ByteOrder byteOrder, long[] dest, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)dest
- array in which to write converted bytesoff
- offset into dest array
EvioException
- if data is null or wrong size; dest is null, wrong size, or off < 0public static float toFloat(byte[] data, java.nio.ByteOrder byteOrder, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data array
EvioException
- if data is null or wrong size, or off is negativepublic static float toFloat(byte b1, byte b2, byte b3, byte b4, java.nio.ByteOrder byteOrder)
b1
- 1st byteb2
- 2nd byteb3
- 3rd byteb4
- 4th bytebyteOrder
- if big endian, 1st byte is most significant &
4th least (big endian if null)
public static float[] toFloatArray(byte[] data, java.nio.ByteOrder byteOrder) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)
EvioException
- if data is null or wrong sizepublic static void toFloatArray(byte[] data, java.nio.ByteOrder byteOrder, float[] dest, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)dest
- array in which to write converted bytesoff
- offset into dest array
EvioException
- if data is null or wrong size; dest is null, wrong size, or off < 0public static double toDouble(byte[] data, java.nio.ByteOrder byteOrder, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data array
EvioException
- if data is null or wrong size, or off is negativepublic static double toDouble(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8, java.nio.ByteOrder byteOrder)
b1
- 1st byteb2
- 2nd byteb3
- 3rd byteb4
- 4th byteb5
- 5th byteb6
- 6th byteb7
- 7th byteb8
- 8th bytebyteOrder
- if big endian, 1st byte is most significant &
8th least (big endian if null)
public static double[] toDoubleArray(byte[] data, java.nio.ByteOrder byteOrder) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)
EvioException
- if data is null or wrong sizepublic static void toDoubleArray(byte[] data, java.nio.ByteOrder byteOrder, double[] dest, int off) throws EvioException
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)dest
- array in which to write converted bytesoff
- offset into dest array
EvioException
- if data is null or wrong size; dest is null, wrong size, or off < 0
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |