|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.jzos.ByteUtil
public class ByteUtil
Helper methods for converting to/from raw byte array data
Constructor Summary | |
---|---|
ByteUtil()
|
Method Summary | |
---|---|
static int |
bytesAsInt(byte[] bytes)
Convert up to 4 bytes into an int (big endian). |
static int |
bytesAsInt(byte[] bytes,
int offset,
int length)
Return an int from big endian bytes. |
static long |
bytesAsLong(byte[] bytes)
Convert up to 8 bytes into an long (big endian). |
static long |
bytesAsLong(byte[] bytes,
int offset,
int length)
Return a long from big endian bytes. |
static java.lang.String |
bytesAsString(byte[] bytes,
int offset,
int length,
java.lang.String encoding)
Return a String from a byte array using the supplied encoding. |
static void |
dumpHex(java.lang.String label,
byte[] bytes,
int offset,
int len,
int bytesPerLine,
java.io.Writer writer)
Dump a byte array in hex to Writer. |
static void |
dumpHex(java.lang.String label,
byte[] bytes,
java.io.OutputStream ostream)
Dump a byte array in hex to an OutputStream. |
static void |
dumpHex(java.lang.String label,
byte[] bytes,
java.io.OutputStream ostream,
java.lang.String encoding)
Dump a byte array in hex to an OutputStream. |
static void |
dumpHex(java.lang.String label,
byte[] bytes,
java.io.Writer writer)
Dump a byte array in hex to Writer. |
static byte[] |
intAsBytes(int i)
Convert an int to four bytes (big-endian). |
static byte[] |
longAsBytes(long l)
Convert a long to eight bytes (big-endian). |
static void |
putInt(int i,
byte[] bytes,
int offset)
Convert an int to four bytes (big-endian) and put into a byte array |
static void |
putLong(long l,
byte[] bytes,
int offset)
Convert a long to eight bytes (big-endian) and put into a byte array. |
static void |
putLong(long l,
byte[] bytes,
int offset,
int len)
Convert a long to eight bytes (big-endian) and put into a byte array. |
static int |
putString(java.lang.String str,
byte[] bytes,
int offset,
int length,
java.lang.String encoding)
Convert a String into a byte array using the supplied encoding. |
static java.lang.String |
toHexString(byte[] bytes)
Return a hex string encoding of a byte array. |
static java.lang.String |
toHexString(byte[] bytes,
int offset,
int len)
Return a hex string encoding of a byte array. |
static java.lang.String |
toHexString(int i,
int numDigits)
Return a hex string encoding of an integer to a given width. |
static long |
unpackLong(byte[] bytes,
int offset,
int length,
boolean isSigned)
Unpack length bytes from the supplied byte array starting at offset. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteUtil()
Method Detail |
---|
public static byte[] intAsBytes(int i)
public static byte[] longAsBytes(long l)
public static void putInt(int i, byte[] bytes, int offset)
public static void putLong(long l, byte[] bytes, int offset, int len)
public static void putLong(long l, byte[] bytes, int offset)
public static int putString(java.lang.String str, byte[] bytes, int offset, int length, java.lang.String encoding)
str
- the String to construct the byte array frombytes
- the byte[] to receive the Stringoffset
- the starting offset in the byte arraylength
- the number of bytes to create. Must be >= str.length()encoding
- the character encoding
java.io.UnsupportedEncodingException
- on invalid encodingpublic static int bytesAsInt(byte[] bytes)
public static int bytesAsInt(byte[] bytes, int offset, int length)
public static long bytesAsLong(byte[] bytes)
public static long bytesAsLong(byte[] bytes, int offset, int length)
public static java.lang.String bytesAsString(byte[] bytes, int offset, int length, java.lang.String encoding)
bytes
- the byte array to construct the String fromoffset
- the offset in the byte arraylength
- the number of bytes to convert
java.io.UnsupportedEncodingException
- on invalid encodingpublic static long unpackLong(byte[] bytes, int offset, int length, boolean isSigned)
public static void dumpHex(java.lang.String label, byte[] bytes, java.io.OutputStream ostream) throws java.io.IOException
label
- a String to write as a header before the dumpbytes
- the byte array to dumpostream
- the java.io.OutputStream to write the dump to, using the default file.encoding
java.io.IOException
public static void dumpHex(java.lang.String label, byte[] bytes, java.io.OutputStream ostream, java.lang.String encoding) throws java.io.IOException
label
- a String to write as a header before the dumpbytes
- the byte array to dumpostream
- the java.io.OutputStream to write the dump toencoding
- the name of the encoding used to encode the OutputStream writer
java.io.IOException
public static void dumpHex(java.lang.String label, byte[] bytes, java.io.Writer writer) throws java.io.IOException
label
- a String to write as a header before the dumpbytes
- the byte array to dumpwriter
- the java.io.Writer to write the dump to
java.io.IOException
public static void dumpHex(java.lang.String label, byte[] bytes, int offset, int len, int bytesPerLine, java.io.Writer writer) throws java.io.IOException
label
- a String to write as a header before the dumpbytes
- the byte array to dumpoffset
- the 0-based offset into bytes to start dumpinglen
- the number of bytes to dumpbytesPerLine
- the number of bytes to dump per linewriter
- the java.io.Writer to write the dump to
java.io.IOException
public static java.lang.String toHexString(int i, int numDigits)
public static java.lang.String toHexString(byte[] bytes)
public static java.lang.String toHexString(byte[] bytes, int offset, int len)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |