public class ByteUtils
extends java.lang.Object
ByteUtils is a helper class for converting numeric primitives
to and from byte representations.| Constructor and Description |
|---|
ByteUtils() |
| Modifier and Type | Method and Description |
|---|---|
static 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(java.io.InputStream inputStream)
Takes an InputStream and returns the complete byte content of it
|
static boolean |
readBoolean(java.io.InputStream inputStream)
Read in a boolean from an InputStream
|
static byte[] |
readData(byte[] store,
int bytes,
java.io.InputStream is)
Properly reads in data from the given stream until the specified number
of bytes have been read.
|
static double |
readDouble(java.io.InputStream inputStream)
Read in a double from an InputStream
|
static float |
readFloat(java.io.InputStream inputStream)
Read in a float from an InputStream
|
static int |
readInt(java.io.InputStream inputStream)
Read in an integer from an InputStream
|
static long |
readLong(java.io.InputStream inputStream)
Read in a long from an InputStream
|
static short |
readShort(java.io.InputStream inputStream)
Read in a short from an InputStream
|
static byte[] |
rightAlignBytes(byte[] bytes,
int width) |
static void |
writeBoolean(java.io.OutputStream outputStream,
boolean bVal)
Writes a boolean out to an OutputStream.
|
static void |
writeDouble(java.io.OutputStream outputStream,
double value)
Writes a double out to an OutputStream.
|
static void |
writeFloat(java.io.OutputStream outputStream,
float fVal)
Writes a float out to an OutputStream.
|
static void |
writeInt(java.io.OutputStream outputStream,
int integer)
Writes an integer out to an OutputStream.
|
static void |
writeLong(java.io.OutputStream outputStream,
long value)
Writes a long out to an OutputStream.
|
static void |
writeShort(java.io.OutputStream outputStream,
short value)
Writes a short out to an OutputStream.
|
public static byte[] getByteContent(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The input stream to read fromjava.io.IOException - thrown if there is a problem reading from the input stream
providedpublic static void writeShort(java.io.OutputStream outputStream,
short value)
throws java.io.IOException
outputStream - The OutputStream the short will be written tovalue - The short to writejava.io.IOException - Thrown if there is a problem writing to the OutputStreampublic static byte[] convertToBytes(short value)
public static short readShort(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The InputStream used to read the shortjava.io.IOException - Thrown if there is a problem reading from the InputStreampublic static short convertShortFromBytes(byte[] byteArray)
public static short convertShortFromBytes(byte[] byteArray,
int offset)
public static void writeInt(java.io.OutputStream outputStream,
int integer)
throws java.io.IOException
outputStream - The OutputStream the integer will be written tointeger - The integer to writejava.io.IOException - Thrown if there is a problem writing to the OutputStreampublic static byte[] convertToBytes(int integer)
public static int readInt(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The InputStream used to read the integerjava.io.IOException - Thrown if there is a problem reading from the InputStreampublic static int convertIntFromBytes(byte[] byteArray)
public static int convertIntFromBytes(byte[] byteArray,
int offset)
public static void writeLong(java.io.OutputStream outputStream,
long value)
throws java.io.IOException
outputStream - The OutputStream the long will be written tovalue - The long to writejava.io.IOException - Thrown if there is a problem writing to the OutputStreampublic static byte[] convertToBytes(long n)
public static long readLong(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The InputStream used to read the longjava.io.IOException - Thrown if there is a problem reading from the InputStreampublic static long convertLongFromBytes(byte[] bytes)
public static long convertLongFromBytes(byte[] bytes,
int offset)
public static void writeDouble(java.io.OutputStream outputStream,
double value)
throws java.io.IOException
outputStream - The OutputStream the double will be written tovalue - The double to writejava.io.IOException - Thrown if there is a problem writing to the OutputStreampublic static byte[] convertToBytes(double n)
public static double readDouble(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The InputStream used to read the doublejava.io.IOException - Thrown if there is a problem reading from the InputStreampublic static double convertDoubleFromBytes(byte[] bytes)
public static double convertDoubleFromBytes(byte[] bytes,
int offset)
public static void writeFloat(java.io.OutputStream outputStream,
float fVal)
throws java.io.IOException
outputStream - The OutputStream the float will be written tofVal - The float to writejava.io.IOException - Thrown if there is a problem writing to the OutputStreampublic static byte[] convertToBytes(float f)
public static float readFloat(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The InputStream used to read the floatjava.io.IOException - Thrown if there is a problem reading from the InputStreampublic static float convertFloatFromBytes(byte[] byteArray)
public static float convertFloatFromBytes(byte[] byteArray,
int offset)
public static void writeBoolean(java.io.OutputStream outputStream,
boolean bVal)
throws java.io.IOException
outputStream - The OutputStream the boolean will be written tobVal - The boolean to writejava.io.IOException - Thrown if there is a problem writing to the OutputStreampublic static byte[] convertToBytes(boolean b)
public static boolean readBoolean(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The InputStream used to read the booleanjava.io.IOException - Thrown if there is a problem reading from the InputStreampublic static boolean convertBooleanFromBytes(byte[] byteArray)
public static boolean convertBooleanFromBytes(byte[] byteArray,
int offset)
public static byte[] readData(byte[] store,
int bytes,
java.io.InputStream is)
throws java.io.IOException
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 fromjava.io.IOException - if an error occurs while reading from the streamjava.lang.ArrayIndexOutOfBoundsException - if bytes greater than the length of the store.public static byte[] rightAlignBytes(byte[] bytes,
int width)