public class BytesUtils extends Object
| Constructor and Description |
|---|
BytesUtils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
booleanToBytes(boolean value) |
static boolean |
bytesToBool(byte[] bytes) |
static int |
bytesToInt(byte[] bytes) |
static long |
bytesToLong(byte[] bytes) |
static int |
getWidthFromMaxInt(int bound)
give the number of bits needed to encode an int given the max value
|
static byte[] |
intToBytes(int value) |
static byte[] |
longToBytes(long value) |
static int |
paddedByteCountFromBits(int bitLength) |
static int |
readIntLittleEndian(byte[] in,
int offset)
reads an int in little endian at the given position
|
static int |
readIntLittleEndian(ByteBuffer in,
int offset)
reads an int in little endian at the given position
|
static int |
readIntLittleEndian(InputStream in) |
static int |
readIntLittleEndianOnOneByte(InputStream in) |
static int |
readIntLittleEndianOnThreeBytes(InputStream in) |
static int |
readIntLittleEndianOnTwoBytes(InputStream in) |
static int |
readIntLittleEndianPaddedOnBitWidth(InputStream in,
int bitWidth) |
static int |
readUnsignedVarInt(InputStream in) |
static long |
readUnsignedVarLong(InputStream in) |
static int |
readZigZagVarInt(InputStream in)
uses a trick mentioned in https://developers.google.com/protocol-buffers/docs/encoding to read zigZag encoded data
|
static long |
readZigZagVarLong(InputStream in)
uses a trick mentioned in https://developers.google.com/protocol-buffers/docs/encoding to read zigZag encoded data
TODO: the implementation is compatible with readZigZagVarInt.
|
static void |
writeIntLittleEndian(OutputStream out,
int v) |
static void |
writeIntLittleEndianOnOneByte(OutputStream out,
int v) |
static void |
writeIntLittleEndianOnThreeBytes(OutputStream out,
int v) |
static void |
writeIntLittleEndianOnTwoBytes(OutputStream out,
int v) |
static void |
writeIntLittleEndianPaddedOnBitWidth(OutputStream out,
int v,
int bitWidth)
Write a little endian int to out, using the the number of bytes required by
bit width
|
static void |
writeUnsignedVarInt(int value,
ByteBuffer dest) |
static void |
writeUnsignedVarInt(int value,
OutputStream out) |
static void |
writeUnsignedVarLong(long value,
OutputStream out) |
static void |
writeZigZagVarInt(int intValue,
OutputStream out) |
static void |
writeZigZagVarLong(long longValue,
OutputStream out) |
public static final Charset UTF8
public static int getWidthFromMaxInt(int bound)
bound - max int that we want to encodepublic static int readIntLittleEndian(ByteBuffer in, int offset) throws IOException
in - a byte bufferoffset - an offset into the byte bufferIOException - if there is an exception reading from the byte bufferpublic static int readIntLittleEndian(byte[] in,
int offset)
throws IOException
in - a byte arrayoffset - an offset into the byte arrayIOException - if there is an exception reading from the byte arraypublic static int readIntLittleEndian(InputStream in) throws IOException
IOExceptionpublic static int readIntLittleEndianOnOneByte(InputStream in) throws IOException
IOExceptionpublic static int readIntLittleEndianOnTwoBytes(InputStream in) throws IOException
IOExceptionpublic static int readIntLittleEndianOnThreeBytes(InputStream in) throws IOException
IOExceptionpublic static int readIntLittleEndianPaddedOnBitWidth(InputStream in, int bitWidth) throws IOException
IOExceptionpublic static void writeIntLittleEndianOnOneByte(OutputStream out, int v) throws IOException
IOExceptionpublic static void writeIntLittleEndianOnTwoBytes(OutputStream out, int v) throws IOException
IOExceptionpublic static void writeIntLittleEndianOnThreeBytes(OutputStream out, int v) throws IOException
IOExceptionpublic static void writeIntLittleEndian(OutputStream out, int v) throws IOException
IOExceptionpublic static void writeIntLittleEndianPaddedOnBitWidth(OutputStream out, int v, int bitWidth) throws IOException
out - an output streamv - an int valuebitWidth - bit width for paddingIOException - if there is an exception while writingpublic static int readUnsignedVarInt(InputStream in) throws IOException
IOExceptionpublic static int readZigZagVarInt(InputStream in) throws IOException
in - an input streamIOException - if there is an exception while readingpublic static void writeUnsignedVarInt(int value,
OutputStream out)
throws IOException
IOExceptionpublic static void writeUnsignedVarInt(int value,
ByteBuffer dest)
throws IOException
IOExceptionpublic static void writeZigZagVarInt(int intValue,
OutputStream out)
throws IOException
IOExceptionpublic static long readZigZagVarLong(InputStream in) throws IOException
in - an input streamIOException - if there is an exception while readingpublic static long readUnsignedVarLong(InputStream in) throws IOException
IOExceptionpublic static void writeUnsignedVarLong(long value,
OutputStream out)
throws IOException
IOExceptionpublic static void writeZigZagVarLong(long longValue,
OutputStream out)
throws IOException
IOExceptionpublic static int paddedByteCountFromBits(int bitLength)
bitLength - a count of bitspublic static byte[] intToBytes(int value)
public static int bytesToInt(byte[] bytes)
public static byte[] longToBytes(long value)
public static long bytesToLong(byte[] bytes)
public static byte[] booleanToBytes(boolean value)
public static boolean bytesToBool(byte[] bytes)
Copyright © 2018 The Apache Software Foundation. All rights reserved.