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(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 int |
readZigZagVarInt(InputStream in)
uses a trick mentioned in https://developers.google.com/protocol-buffers/docs/encoding to read zigZag encoded data
|
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,
OutputStream out) |
static void |
writeZigZagVarInt(int intValue,
OutputStream out) |
public static final Charset UTF8
public static int getWidthFromMaxInt(int bound)
bound
- max int that we want to encodepublic static int readIntLittleEndian(byte[] in, int offset) throws IOException
in
- offset
- IOException
public static int readIntLittleEndian(InputStream in) throws IOException
IOException
public static int readIntLittleEndianOnOneByte(InputStream in) throws IOException
IOException
public static int readIntLittleEndianOnTwoBytes(InputStream in) throws IOException
IOException
public static int readIntLittleEndianOnThreeBytes(InputStream in) throws IOException
IOException
public static int readIntLittleEndianPaddedOnBitWidth(InputStream in, int bitWidth) throws IOException
IOException
public static void writeIntLittleEndianOnOneByte(OutputStream out, int v) throws IOException
IOException
public static void writeIntLittleEndianOnTwoBytes(OutputStream out, int v) throws IOException
IOException
public static void writeIntLittleEndianOnThreeBytes(OutputStream out, int v) throws IOException
IOException
public static void writeIntLittleEndian(OutputStream out, int v) throws IOException
IOException
public static void writeIntLittleEndianPaddedOnBitWidth(OutputStream out, int v, int bitWidth) throws IOException
IOException
public static int readUnsignedVarInt(InputStream in) throws IOException
IOException
public static int readZigZagVarInt(InputStream in) throws IOException
in
- IOException
public static void writeUnsignedVarInt(int value, OutputStream out) throws IOException
IOException
public static void writeZigZagVarInt(int intValue, OutputStream out) throws IOException
IOException
public 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 © 2015. All rights reserved.