Package com.jme3.export.binary
Class ByteUtils
java.lang.Object
com.jme3.export.binary.ByteUtils
ByteUtils is a helper class for converting numeric primitives
 to and from byte representations.- 
Method Summary
Modifier and TypeMethodDescriptionstatic booleanconvertBooleanFromBytes(byte[] byteArray) static booleanconvertBooleanFromBytes(byte[] byteArray, int offset) static doubleconvertDoubleFromBytes(byte[] bytes) static doubleconvertDoubleFromBytes(byte[] bytes, int offset) static floatconvertFloatFromBytes(byte[] byteArray) static floatconvertFloatFromBytes(byte[] byteArray, int offset) static intconvertIntFromBytes(byte[] byteArray) static intconvertIntFromBytes(byte[] byteArray, int offset) static longconvertLongFromBytes(byte[] bytes) static longconvertLongFromBytes(byte[] bytes, int offset) static shortconvertShortFromBytes(byte[] byteArray) static shortconvertShortFromBytes(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 booleanreadBoolean(InputStream inputStream) Read in a boolean from an InputStreamstatic byte[]readData(byte[] store, int bytes, InputStream is) Properly reads in data from the given stream until the specified number of bytes have been read.static doublereadDouble(InputStream inputStream) Read in a double from an InputStreamstatic floatreadFloat(InputStream inputStream) Read in a float from an InputStreamstatic intreadInt(InputStream inputStream) Read in an integer from an InputStreamstatic longreadLong(InputStream inputStream) Read in a long from an InputStreamstatic shortreadShort(InputStream inputStream) Read in a short from an InputStreamstatic byte[]rightAlignBytes(byte[] bytes, int width) static voidwriteBoolean(OutputStream outputStream, boolean bVal) Writes a boolean out to an OutputStream.static voidwriteDouble(OutputStream outputStream, double value) Writes a double out to an OutputStream.static voidwriteFloat(OutputStream outputStream, float fVal) Writes a float out to an OutputStream.static voidwriteInt(OutputStream outputStream, int integer) Writes an integer out to an OutputStream.static voidwriteLong(OutputStream outputStream, long value) Writes a long out to an OutputStream.static voidwriteShort(OutputStream outputStream, short value) Writes a short out to an OutputStream. 
- 
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 a 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)  - 
readData
Properly reads in data from the given stream until the specified number of bytes have been read.- Parameters:
 store- the byte array to store in. Array length must be greater than bytes param.bytes- the number of bytes to read.is- the stream to read from- Returns:
 - the store array for chaining purposes
 - Throws:
 IOException- if an error occurs while reading from the streamArrayIndexOutOfBoundsException- if bytes greater than the length of the store.
 - 
rightAlignBytes
public static byte[] rightAlignBytes(byte[] bytes, int width)  
 -