public final class ByteUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Charset |
ASCII_CHARSET
ASCII character set.
|
static Charset |
DEFAULT_CHARSET
Default character set for bytes is UTF-8.
|
Modifier and Type | Method and Description |
---|---|
static int |
readInt(InputStream in)
Reads 4-bytes from the input stream and converts to a 32-bit integer.
|
static long |
readLong(InputStream in)
Reads 8-bytes from the input stream and converts to a 64-bit long integer.
|
static byte[] |
toArray(ByteBuffer buffer)
Converts a byte buffer into a byte array.
|
static ByteBuffer |
toByteBuffer(String s)
Converts a string into bytes in the UTF-8 character set.
|
static byte[] |
toBytes(int value)
Converts an integer into a 4-byte big endian array.
|
static void |
toBytes(int value,
byte[] output,
int offset)
Converts an integer into a 4-byte big endian array.
|
static byte[] |
toBytes(long value)
Converts a long integer into an 8-byte big endian array.
|
static void |
toBytes(long value,
byte[] output,
int offset)
Converts an integer into an 8-byte big endian array.
|
static byte[] |
toBytes(String s)
Converts a string into bytes in the UTF-8 character set.
|
static CharBuffer |
toCharBuffer(ByteBuffer buffer)
Converts a byte buffer into a character buffer.
|
static int |
toInt(byte unsigned)
Converts an unsigned byte into an integer.
|
static int |
toInt(byte[] data)
Converts the big-endian representation of a 32-bit integer to the equivalent integer value.
|
static long |
toLong(byte[] data)
Converts the big-endian representation of a 64-bit integer to the equivalent long value.
|
static String |
toString(byte[] bytes)
Converts a byte array into a string in the UTF-8 character set.
|
static String |
toString(byte[] bytes,
int offset,
int length)
Converts a portion of a byte array into a string in the UTF-8 character set.
|
static String |
toString(ByteBuffer buffer)
Converts a byte buffer into a string in the UTF-8 character set.
|
static byte |
toUnsignedByte(int b)
Converts an integer into an unsigned byte.
|
public static final Charset DEFAULT_CHARSET
public static final Charset ASCII_CHARSET
public static int toInt(byte[] data)
data
- 4-byte array in big-endian format.public static int toInt(byte unsigned)
unsigned
- Unsigned byte.public static int readInt(InputStream in) throws StreamException
in
- Stream from which to read 4 bytes.StreamException
- on stream IO errors.public static long toLong(byte[] data)
data
- 8-byte array in big-endian format.public static long readLong(InputStream in) throws StreamException
in
- Stream from which to read 8 bytes.StreamException
- on stream IO errors.public static byte[] toBytes(int value)
value
- Integer value to convert.public static void toBytes(int value, byte[] output, int offset)
value
- Integer value to convert.output
- Array into which bytes are placed.offset
- Offset into output array at which output bytes start.public static byte[] toBytes(long value)
value
- Long integer value to convert.public static void toBytes(long value, byte[] output, int offset)
value
- Long value to convert.output
- Array into which bytes are placed.offset
- Offset into output array at which output bytes start.public static String toString(byte[] bytes)
bytes
- Byte array to convert.public static String toString(byte[] bytes, int offset, int length)
bytes
- Byte array to convert.offset
- Offset into byte array where string content begins.length
- Total number of bytes to convert.public static String toString(ByteBuffer buffer)
buffer
- Byte buffer to convert.public static CharBuffer toCharBuffer(ByteBuffer buffer)
buffer
- Byte buffer to convert.public static ByteBuffer toByteBuffer(String s)
s
- String to convert.public static byte[] toBytes(String s)
s
- String to convert.public static byte toUnsignedByte(int b)
b
- Integer value.public static byte[] toArray(ByteBuffer buffer)
buffer
- Byte buffer to convert.Copyright © 2003-2024 Virginia Tech. All Rights Reserved.