public class NativeData
extends java.lang.Object
These routines are used by class HDFArray to pass data to and from the HDF5 library.
Methods copyXxxToByte() convert a Java array of primitive numbers (int, short, ...) to a Java array of bytes. Methods copyByteToXxx() convert from a Java array of bytes into a Java array of primitive numbers (int, short, ...)
Variant interfaces convert only a sub-array.
The class has optimized methods using jni-libraries for some common platforms and a pure-java
implementation (called javamode if the jni-libraries are not available). If you want to
enforce javamode, you need to pass the property nativedata.javamode=true
to
the JRE.
Modifier and Type | Class and Description |
---|---|
static class |
NativeData.ByteOrder
Byte Order enumeration.
|
Modifier and Type | Field and Description |
---|---|
static int |
CHAR_SIZE
Size of a
char value in byte s. |
static int |
DOUBLE_SIZE
Size of a
double value in byte s. |
static int |
FLOAT_SIZE
Size of a
float value in byte s. |
static int |
INT_SIZE
Size of an
int value in byte s. |
static int |
LONG_SIZE
Size of a
long value in byte s. |
static int |
SHORT_SIZE
Size of a
short value in byte s. |
Constructor and Description |
---|
NativeData() |
Modifier and Type | Method and Description |
---|---|
static char[] |
byteToChar(byte[] byteArr,
NativeData.ByteOrder byteOrder)
Converts a
byte[] array into a char[] array. |
static char[] |
byteToChar(byte[] byteArr,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
byte[] array into a char[] array. |
static double[] |
byteToDouble(byte[] byteArr,
NativeData.ByteOrder byteOrder)
Converts a
byte[] array into a double[] array. |
static double[] |
byteToDouble(byte[] byteArr,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
byte[] array into a double[] array. |
static float[] |
byteToFloat(byte[] byteArr,
NativeData.ByteOrder byteOrder)
Converts a
byte[] array into a float[] array. |
static float[] |
byteToFloat(byte[] byteArr,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
byte[] array into a float[] array. |
static int[] |
byteToInt(byte[] byteArr,
NativeData.ByteOrder byteOrder)
Converts a
byte[] array into an int[] array. |
static int[] |
byteToInt(byte[] byteArr,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
byte[] array into an int[] array. |
static long[] |
byteToLong(byte[] byteArr,
NativeData.ByteOrder byteOrder)
Converts a
byte[] array into a long[] array. |
static long[] |
byteToLong(byte[] byteArr,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
byte[] array into a long[] array. |
static short[] |
byteToShort(byte[] byteArr,
NativeData.ByteOrder byteOrder)
Converts a
byte[] array into a short[] array. |
static short[] |
byteToShort(byte[] byteArr,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
byte[] array into a short[] array. |
static char |
changeByteOrder(char c)
Changes the byte order of the bytes constituting c.
|
static double |
changeByteOrder(double d)
Changes the byte order of the bytes constituting d.
|
static float |
changeByteOrder(float f)
Changes the byte order of the bytes constituting f.
|
static int |
changeByteOrder(int i)
Changes the byte order of the bytes constituting i.
|
static long |
changeByteOrder(long l)
Changes the byte order of the bytes constituting l.
|
static short |
changeByteOrder(short s)
Changes the byte order of the bytes constituting s.
|
static byte[] |
charToByte(char[] data,
NativeData.ByteOrder byteOrder)
Converts a
char[] array to a byte[] array. |
static byte[] |
charToByte(char[] data,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
char[] array to a byte[] array. |
static void |
copyByteToChar(byte[] inData,
int inStart,
char[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
byte into an array of char . |
static void |
copyByteToDouble(byte[] inData,
int inStart,
double[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
byte into an array of double . |
static void |
copyByteToFloat(byte[] inData,
int inStart,
float[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
byte into an array of float . |
static void |
copyByteToInt(byte[] inData,
int inStart,
int[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
byte into an array of int . |
static void |
copyByteToLong(byte[] inData,
int inStart,
long[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
byte into an array of long . |
static void |
copyByteToShort(byte[] inData,
int inStart,
short[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
byte into an array of short . |
static void |
copyCharToByte(char[] inData,
int inStart,
byte[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
char into an array of byte . |
static void |
copyDoubleToByte(double[] inData,
int inStart,
byte[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
double into an array of byte . |
static void |
copyFloatToByte(float[] inData,
int inStart,
byte[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
float into an array of byte . |
static void |
copyIntToByte(int[] inData,
int inStart,
byte[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
int into an array of byte . |
static void |
copyLongToByte(long[] inData,
int inStart,
byte[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
long into an array of byte . |
static void |
copyShortToByte(short[] inData,
int inStart,
byte[] outData,
int outStart,
int len,
NativeData.ByteOrder byteOrder)
Copies a range from an array of
short into an array of byte . |
static byte[] |
doubleToByte(double[] data,
NativeData.ByteOrder byteOrder)
Converts a
double[] array to a byte[] array. |
static byte[] |
doubleToByte(double[] data,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
double[] array to a byte[] array. |
static void |
ensureNativeLibIsLoaded()
Call to ensure that the native library is loaded.
|
static byte[] |
floatToByte(float[] data,
NativeData.ByteOrder byteOrder)
Converts a
float[] array to a byte[] array. |
static byte[] |
floatToByte(float[] data,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
float[] array to a byte[] array. |
static NativeData.ByteOrder |
getNativeByteOrder()
Returns the native byte order of the host running this JRE.
|
static byte[] |
intToByte(int[] data,
NativeData.ByteOrder byteOrder)
Converts a
int[] array to a byte[] array. |
static byte[] |
intToByte(int[] data,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
int[] array to a byte[] array. |
static boolean |
isUseNativeLib()
Returns
true , if this class uses the native library and false
otherwise. |
static byte[] |
longToByte(long[] data,
NativeData.ByteOrder byteOrder)
Converts a
long[] array to a byte[] array. |
static byte[] |
longToByte(long[] data,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
long[] array to a byte[] array. |
static byte[] |
shortToByte(short[] data,
NativeData.ByteOrder byteOrder)
Converts a
short[] array to a byte[] array. |
static byte[] |
shortToByte(short[] data,
NativeData.ByteOrder byteOrder,
int start,
int len)
Converts a
short[] array to a byte[] array. |
public static final int SHORT_SIZE
short
value in byte
s.public static final int CHAR_SIZE
char
value in byte
s.public static final int INT_SIZE
int
value in byte
s.public static final int LONG_SIZE
long
value in byte
s.public static final int FLOAT_SIZE
float
value in byte
s.public static final int DOUBLE_SIZE
double
value in byte
s.public static void ensureNativeLibIsLoaded()
public static boolean isUseNativeLib()
true
, if this class uses the native library and false
otherwise.public static NativeData.ByteOrder getNativeByteOrder()
public static short changeByteOrder(short s)
public static char changeByteOrder(char c)
public static int changeByteOrder(int i)
public static float changeByteOrder(float f)
public static long changeByteOrder(long l)
public static double changeByteOrder(double d)
public static void copyIntToByte(int[] inData, int inStart, byte[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
int
into an array of byte
.inData
- The input array of int
values.inStart
- The position in the input array inData
of int
to
startoutData
- The output array of byte
values.outStart
- The start in the output array byteData
of byte
to
startlen
- The number of int
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyByteToInt(byte[] inData, int inStart, int[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
byte
into an array of int
.inData
- The input array of byte
values.inStart
- The position in the input array inData
of byte
to
startoutData
- The output array of int
values.outStart
- The start in the output array byteData
of int
to
startlen
- The number of int
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyLongToByte(long[] inData, int inStart, byte[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
long
into an array of byte
.inData
- The input array of long
values.inStart
- The position in the input array inData
of long
to
startoutData
- The output array of byte
values.outStart
- The start in the output array byteData
of byte
to
startlen
- The number of long
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyByteToLong(byte[] inData, int inStart, long[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
byte
into an array of long
.inData
- The input array of byte
values.inStart
- The position in the input array inData
of byte
to
startoutData
- The output array of long
values.outStart
- The start in the output array byteData
of long
to
startlen
- The number of long
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyShortToByte(short[] inData, int inStart, byte[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
short
into an array of byte
.inData
- The input array of short
values.inStart
- The position in the input array inData
of short
to
startoutData
- The output array of byte
values.outStart
- The start in the output array byteData
of byte
to
startlen
- The number of short
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyCharToByte(char[] inData, int inStart, byte[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
char
into an array of byte
.inData
- The input array of char
values.inStart
- The position in the input array inData
of char
to
startoutData
- The output array of byte
values.outStart
- The start in the output array byteData
of byte
to
startlen
- The number of char
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyByteToShort(byte[] inData, int inStart, short[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
byte
into an array of short
.inData
- The input array of byte
values.inStart
- The position in the input array inData
of byte
to
startoutData
- The output array of short
values.outStart
- The start in the output array byteData
of short
to
startlen
- The number of short
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyByteToChar(byte[] inData, int inStart, char[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
byte
into an array of char
.inData
- The input array of byte
values.inStart
- The position in the input array inData
of byte
to
startoutData
- The output array of short
values.outStart
- The start in the output array byteData
of short
to
startlen
- The number of short
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyFloatToByte(float[] inData, int inStart, byte[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
float
into an array of byte
.inData
- The input array of float
values.inStart
- The position in the input array inData
of float
to
startoutData
- The output array of byte
values.outStart
- The start in the output array byteData
of byte
to
startlen
- The number of float
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyByteToFloat(byte[] inData, int inStart, float[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
byte
into an array of float
.inData
- The input array of byte
values.inStart
- The position in the input array inData
of byte
to
startoutData
- The output array of float
values.outStart
- The start in the output array byteData
of float
to
startlen
- The number of float
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyDoubleToByte(double[] inData, int inStart, byte[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
double
into an array of byte
.inData
- The input array of double
values.inStart
- The position in the input array inData
of double
to
startoutData
- The output array of byte
values.outStart
- The start in the output array byteData
of byte
to
startlen
- The number of double
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static void copyByteToDouble(byte[] inData, int inStart, double[] outData, int outStart, int len, NativeData.ByteOrder byteOrder)
byte
into an array of double
.inData
- The input array of byte
values.inStart
- The position in the input array inData
of byte
to
startoutData
- The output array of double
values.outStart
- The start in the output array byteData
of double
to
startlen
- The number of double
to copybyteOrder
- The NativeData.ByteOrder
, encoding what byte order the outData
should be in.public static char[] byteToChar(byte[] byteArr, NativeData.ByteOrder byteOrder, int start, int len)
byte[]
array into a char[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.start
- The position in the byteArr to start the conversion.len
- The number of short
values to convert.char[]
array.public static char[] byteToChar(byte[] byteArr, NativeData.ByteOrder byteOrder)
byte[]
array into a char[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.char[]
array.public static short[] byteToShort(byte[] byteArr, NativeData.ByteOrder byteOrder, int start, int len)
byte[]
array into a short[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.start
- The position in the byteArr to start the conversion.len
- The number of short
values to convert.short[]
array.public static short[] byteToShort(byte[] byteArr, NativeData.ByteOrder byteOrder)
byte[]
array into a short[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.short[]
array.public static byte[] shortToByte(short[] data, NativeData.ByteOrder byteOrder, int start, int len)
short[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.start
- The position in data to start the conversion.len
- The number of short
values to convert.byte[]
array.public static byte[] shortToByte(short[] data, NativeData.ByteOrder byteOrder)
short[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.byte[]
array.public static byte[] charToByte(char[] data, NativeData.ByteOrder byteOrder, int start, int len)
char[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.start
- The position in data to start the conversion.len
- The number of char
values to convert.byte[]
array.public static byte[] charToByte(char[] data, NativeData.ByteOrder byteOrder)
char[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.byte[]
array.public static int[] byteToInt(byte[] byteArr, NativeData.ByteOrder byteOrder, int start, int len)
byte[]
array into an int[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.start
- The position in the byteArr to start the conversion.len
- The number of int
values to convert.int[]
array.public static int[] byteToInt(byte[] byteArr, NativeData.ByteOrder byteOrder)
byte[]
array into an int[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.int[]
array.public static byte[] intToByte(int[] data, NativeData.ByteOrder byteOrder, int start, int len)
int[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.start
- The position in data to start the conversion.len
- The number of int
values to convert.byte[]
array.public static byte[] intToByte(int[] data, NativeData.ByteOrder byteOrder)
int[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.byte[]
array.public static long[] byteToLong(byte[] byteArr, NativeData.ByteOrder byteOrder, int start, int len)
byte[]
array into a long[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.start
- The position in the byteArr to start the conversion.len
- The number of long
values to convert.long[]
array.public static long[] byteToLong(byte[] byteArr, NativeData.ByteOrder byteOrder)
byte[]
array into a long[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.long[]
array.public static byte[] longToByte(long[] data, NativeData.ByteOrder byteOrder, int start, int len)
long[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.start
- The position in data to start the conversion.len
- The number of long
values to convert.byte[]
array.public static byte[] longToByte(long[] data, NativeData.ByteOrder byteOrder)
long[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.byte[]
array.public static float[] byteToFloat(byte[] byteArr, NativeData.ByteOrder byteOrder, int start, int len)
byte[]
array into a float[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.start
- The position in the byteArr to start the conversion.len
- The number of float
values to convert.float[]
array.public static float[] byteToFloat(byte[] byteArr, NativeData.ByteOrder byteOrder)
byte[]
array into a float[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.float[]
array.public static byte[] floatToByte(float[] data, NativeData.ByteOrder byteOrder, int start, int len)
float[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.start
- The position in data to start the conversion.len
- The number of float
values to convert.byte[]
array.public static byte[] floatToByte(float[] data, NativeData.ByteOrder byteOrder)
float[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.byte[]
array.public static double[] byteToDouble(byte[] byteArr, NativeData.ByteOrder byteOrder, int start, int len)
byte[]
array into a double[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.start
- The position in the byteArr to start the conversion.len
- The number of double
values to convert.double[]
array.public static double[] byteToDouble(byte[] byteArr, NativeData.ByteOrder byteOrder)
byte[]
array into a double[]
array.byteArr
- The byte[]
to convert.byteOrder
- The byte order of byteArr.double[]
array.public static byte[] doubleToByte(double[] data, NativeData.ByteOrder byteOrder, int start, int len)
double[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.start
- The position in data to start the conversion.len
- The number of double
values to convert.byte[]
array.public static byte[] doubleToByte(double[] data, NativeData.ByteOrder byteOrder)
double[]
array to a byte[]
array.data
- The array to convert.byteOrder
- The byte order of the returned byte[]
.byte[]
array.