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 SummaryModifier 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- 
getByteContentTakes 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
 
- 
writeShortWrites a short out to an OutputStream.- Parameters:
- outputStream- The OutputStream the short will be written to
- value- The short to write
- Throws:
- IOException- Thrown if there is a problem writing to the OutputStream
 
- 
convertToBytespublic static byte[] convertToBytes(short value) 
- 
readShortRead 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
 
- 
convertShortFromBytespublic static short convertShortFromBytes(byte[] byteArray) 
- 
convertShortFromBytespublic static short convertShortFromBytes(byte[] byteArray, int offset) 
- 
writeIntWrites an integer out to an OutputStream.- Parameters:
- outputStream- The OutputStream the integer will be written to
- integer- The integer to write
- Throws:
- IOException- Thrown if there is a problem writing to the OutputStream
 
- 
convertToBytespublic static byte[] convertToBytes(int integer) 
- 
readIntRead 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
 
- 
convertIntFromBytespublic static int convertIntFromBytes(byte[] byteArray) 
- 
convertIntFromBytespublic static int convertIntFromBytes(byte[] byteArray, int offset) 
- 
writeLongWrites a long out to an OutputStream.- Parameters:
- outputStream- The OutputStream the long will be written to
- value- The long to write
- Throws:
- IOException- Thrown if there is a problem writing to the OutputStream
 
- 
convertToBytespublic static byte[] convertToBytes(long n) 
- 
readLongRead 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
 
- 
convertLongFromBytespublic static long convertLongFromBytes(byte[] bytes) 
- 
convertLongFromBytespublic static long convertLongFromBytes(byte[] bytes, int offset) 
- 
writeDoubleWrites a double out to an OutputStream.- Parameters:
- outputStream- The OutputStream the double will be written to
- value- The double to write
- Throws:
- IOException- Thrown if there is a problem writing to the OutputStream
 
- 
convertToBytespublic static byte[] convertToBytes(double n) 
- 
readDoubleRead 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
 
- 
convertDoubleFromBytespublic static double convertDoubleFromBytes(byte[] bytes) 
- 
convertDoubleFromBytespublic static double convertDoubleFromBytes(byte[] bytes, int offset) 
- 
writeFloatWrites a float out to an OutputStream.- Parameters:
- outputStream- The OutputStream the float will be written to
- fVal- The float to write
- Throws:
- IOException- Thrown if there is a problem writing to the OutputStream
 
- 
convertToBytespublic static byte[] convertToBytes(float f) 
- 
readFloatRead 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
 
- 
convertFloatFromBytespublic static float convertFloatFromBytes(byte[] byteArray) 
- 
convertFloatFromBytespublic static float convertFloatFromBytes(byte[] byteArray, int offset) 
- 
writeBooleanWrites a boolean out to an OutputStream.- Parameters:
- outputStream- The OutputStream the boolean will be written to
- bVal- The boolean to write
- Throws:
- IOException- Thrown if there is a problem writing to the OutputStream
 
- 
convertToBytespublic static byte[] convertToBytes(boolean b) 
- 
readBooleanRead 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
 
- 
convertBooleanFromBytespublic static boolean convertBooleanFromBytes(byte[] byteArray) 
- 
convertBooleanFromBytespublic static boolean convertBooleanFromBytes(byte[] byteArray, int offset) 
- 
readDataProperly 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 stream
- ArrayIndexOutOfBoundsException- if bytes greater than the length of the store.
 
- 
rightAlignBytespublic static byte[] rightAlignBytes(byte[] bytes, int width) 
 
-