Package com.ardor3d.util.export
Class ByteUtils
java.lang.Object
com.ardor3d.util.export.ByteUtils
ByteUtils
is a helper class for converting numeric primitives to and from byte representations.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
convertBooleanFromBytes
(byte[] byteArray) static boolean
convertBooleanFromBytes
(byte[] byteArray, int offset) static double
convertDoubleFromBytes
(byte[] bytes) static double
convertDoubleFromBytes
(byte[] bytes, int offset) static float
convertFloatFromBytes
(byte[] byteArray) static float
convertFloatFromBytes
(byte[] byteArray, int offset) static int
convertIntFromBytes
(byte[] byteArray) static int
convertIntFromBytes
(byte[] byteArray, int offset) static long
convertLongFromBytes
(byte[] bytes) static long
convertLongFromBytes
(byte[] bytes, int offset) static short
convertShortFromBytes
(byte[] byteArray) static short
convertShortFromBytes
(byte[] byteArray, int offset) static byte[]
convertToBytes
(boolean b) static byte[]
convertToBytes
(double n) static byte[]
convertToBytes
(float f) static byte[]
convertToBytes
(int integer) static byte[]
convertToBytes
(long n) static byte[]
convertToBytes
(short value) static byte[]
getByteContent
(InputStream inputStream) Takes an InputStream and returns the complete byte content of itstatic boolean
readBoolean
(InputStream inputStream) Read in a boolean from an InputStreamstatic double
readDouble
(InputStream inputStream) Read in a double from an InputStreamstatic float
readFloat
(InputStream inputStream) Read in a float from an InputStreamstatic int
readInt
(InputStream inputStream) Read in an integer from an InputStreamstatic long
readLong
(InputStream inputStream) Read in a long from an InputStreamstatic short
readShort
(InputStream inputStream) Read in a short from an InputStreamstatic byte[]
rightAlignBytes
(byte[] bytes, int width) static void
writeBoolean
(OutputStream outputStream, boolean bVal) Writes a boolean out to an OutputStream.static void
writeDouble
(OutputStream outputStream, double value) Writes a double out to an OutputStream.static void
writeFloat
(OutputStream outputStream, float fVal) Writes an float out to an OutputStream.static void
writeInt
(OutputStream outputStream, int integer) Writes an integer out to an OutputStream.static void
writeLong
(OutputStream outputStream, long value) Writes a long out to an OutputStream.static void
writeShort
(OutputStream outputStream, short value) Writes a short out to an OutputStream.
-
Constructor Details
-
ByteUtils
public ByteUtils()
-
-
Method Details
-
getByteContent
Takes an InputStream and returns the complete byte content of it- Parameters:
inputStream
- The input stream to read from- Returns:
- The byte array containing the data from the input stream
- Throws:
IOException
- thrown if there is a problem reading from the input stream provided
-
writeShort
Writes a short out to an OutputStream.- Parameters:
outputStream
- The OutputStream the short will be written tovalue
- The short to write- Throws:
IOException
- Thrown if there is a problem writing to the OutputStream
-
convertToBytes
public static byte[] convertToBytes(short value) -
readShort
Read in a short from an InputStream- Parameters:
inputStream
- The InputStream used to read the short- Returns:
- A short, which is the next 2 bytes converted from the InputStream
- Throws:
IOException
- Thrown if there is a problem reading from the InputStream
-
convertShortFromBytes
public static short convertShortFromBytes(byte[] byteArray) -
convertShortFromBytes
public static short convertShortFromBytes(byte[] byteArray, int offset) -
writeInt
Writes an integer out to an OutputStream.- Parameters:
outputStream
- The OutputStream the integer will be written tointeger
- The integer to write- Throws:
IOException
- Thrown if there is a problem writing to the OutputStream
-
convertToBytes
public static byte[] convertToBytes(int integer) -
readInt
Read in an integer from an InputStream- Parameters:
inputStream
- The InputStream used to read the integer- Returns:
- An int, which is the next 4 bytes converted from the InputStream
- Throws:
IOException
- Thrown if there is a problem reading from the InputStream
-
convertIntFromBytes
public static int convertIntFromBytes(byte[] byteArray) -
convertIntFromBytes
public static int convertIntFromBytes(byte[] byteArray, int offset) -
writeLong
Writes a long out to an OutputStream.- Parameters:
outputStream
- The OutputStream the long will be written tovalue
- The long to write- Throws:
IOException
- Thrown if there is a problem writing to the OutputStream
-
convertToBytes
public static byte[] convertToBytes(long n) -
readLong
Read in a long from an InputStream- Parameters:
inputStream
- The InputStream used to read the long- Returns:
- A long, which is the next 8 bytes converted from the InputStream
- Throws:
IOException
- Thrown if there is a problem reading from the InputStream
-
convertLongFromBytes
public static long convertLongFromBytes(byte[] bytes) -
convertLongFromBytes
public static long convertLongFromBytes(byte[] bytes, int offset) -
writeDouble
Writes a double out to an OutputStream.- Parameters:
outputStream
- The OutputStream the double will be written tovalue
- The double to write- Throws:
IOException
- Thrown if there is a problem writing to the OutputStream
-
convertToBytes
public static byte[] convertToBytes(double n) -
readDouble
Read in a double from an InputStream- Parameters:
inputStream
- The InputStream used to read the double- Returns:
- A double, which is the next 8 bytes converted from the InputStream
- Throws:
IOException
- Thrown if there is a problem reading from the InputStream
-
convertDoubleFromBytes
public static double convertDoubleFromBytes(byte[] bytes) -
convertDoubleFromBytes
public static double convertDoubleFromBytes(byte[] bytes, int offset) -
writeFloat
Writes an float out to an OutputStream.- Parameters:
outputStream
- The OutputStream the float will be written tofVal
- The float to write- Throws:
IOException
- Thrown if there is a problem writing to the OutputStream
-
convertToBytes
public static byte[] convertToBytes(float f) -
readFloat
Read in a float from an InputStream- Parameters:
inputStream
- The InputStream used to read the float- Returns:
- A float, which is the next 4 bytes converted from the InputStream
- Throws:
IOException
- Thrown if there is a problem reading from the InputStream
-
convertFloatFromBytes
public static float convertFloatFromBytes(byte[] byteArray) -
convertFloatFromBytes
public static float convertFloatFromBytes(byte[] byteArray, int offset) -
writeBoolean
Writes a boolean out to an OutputStream.- Parameters:
outputStream
- The OutputStream the boolean will be written tobVal
- The boolean to write- Throws:
IOException
- Thrown if there is a problem writing to the OutputStream
-
convertToBytes
public static byte[] convertToBytes(boolean b) -
readBoolean
Read in a boolean from an InputStream- Parameters:
inputStream
- The InputStream used to read the boolean- Returns:
- A boolean, which is the next byte converted from the InputStream (iow, byte != 0)
- Throws:
IOException
- Thrown if there is a problem reading from the InputStream
-
convertBooleanFromBytes
public static boolean convertBooleanFromBytes(byte[] byteArray) -
convertBooleanFromBytes
public static boolean convertBooleanFromBytes(byte[] byteArray, int offset) -
rightAlignBytes
public static byte[] rightAlignBytes(byte[] bytes, int width)
-