Package org.apache.parquet.bytes
Class BytesUtils
- java.lang.Object
-
- org.apache.parquet.bytes.BytesUtils
-
public class BytesUtils extends Object
utility methods to deal with bytes
-
-
Field Summary
Fields Modifier and Type Field Description static Charset
UTF8
Deprecated.UseStandardCharsets.UTF_8
instead
-
Constructor Summary
Constructors Constructor Description BytesUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 valuestatic 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 positionstatic int
readIntLittleEndian(InputStream in)
static int
readIntLittleEndian(ByteBuffer in, int offset)
reads an int in little endian at the given positionstatic 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 datastatic 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 widthstatic void
writeUnsignedVarInt(int value, OutputStream out)
static void
writeUnsignedVarInt(int value, ByteBuffer dest)
static void
writeUnsignedVarLong(long value, OutputStream out)
static void
writeZigZagVarInt(int intValue, OutputStream out)
static void
writeZigZagVarLong(long longValue, OutputStream out)
-
-
-
Field Detail
-
UTF8
@Deprecated public static final Charset UTF8
Deprecated.UseStandardCharsets.UTF_8
instead
-
-
Method Detail
-
getWidthFromMaxInt
public static int getWidthFromMaxInt(int bound)
give the number of bits needed to encode an int given the max value- Parameters:
bound
- max int that we want to encode- Returns:
- the number of bits required
-
readIntLittleEndian
public static int readIntLittleEndian(ByteBuffer in, int offset) throws IOException
reads an int in little endian at the given position- Parameters:
in
- a byte bufferoffset
- an offset into the byte buffer- Returns:
- the integer at position offset read using little endian byte order
- Throws:
IOException
- if there is an exception reading from the byte buffer
-
readIntLittleEndian
public static int readIntLittleEndian(byte[] in, int offset) throws IOException
reads an int in little endian at the given position- Parameters:
in
- a byte arrayoffset
- an offset into the byte array- Returns:
- the integer at position offset read using little endian byte order
- Throws:
IOException
- if there is an exception reading from the byte array
-
readIntLittleEndian
public static int readIntLittleEndian(InputStream in) throws IOException
- Throws:
IOException
-
readIntLittleEndianOnOneByte
public static int readIntLittleEndianOnOneByte(InputStream in) throws IOException
- Throws:
IOException
-
readIntLittleEndianOnTwoBytes
public static int readIntLittleEndianOnTwoBytes(InputStream in) throws IOException
- Throws:
IOException
-
readIntLittleEndianOnThreeBytes
public static int readIntLittleEndianOnThreeBytes(InputStream in) throws IOException
- Throws:
IOException
-
readIntLittleEndianPaddedOnBitWidth
public static int readIntLittleEndianPaddedOnBitWidth(InputStream in, int bitWidth) throws IOException
- Throws:
IOException
-
writeIntLittleEndianOnOneByte
public static void writeIntLittleEndianOnOneByte(OutputStream out, int v) throws IOException
- Throws:
IOException
-
writeIntLittleEndianOnTwoBytes
public static void writeIntLittleEndianOnTwoBytes(OutputStream out, int v) throws IOException
- Throws:
IOException
-
writeIntLittleEndianOnThreeBytes
public static void writeIntLittleEndianOnThreeBytes(OutputStream out, int v) throws IOException
- Throws:
IOException
-
writeIntLittleEndian
public static void writeIntLittleEndian(OutputStream out, int v) throws IOException
- Throws:
IOException
-
writeIntLittleEndianPaddedOnBitWidth
public static void writeIntLittleEndianPaddedOnBitWidth(OutputStream out, int v, int bitWidth) throws IOException
Write a little endian int to out, using the the number of bytes required by bit width- Parameters:
out
- an output streamv
- an int valuebitWidth
- bit width for padding- Throws:
IOException
- if there is an exception while writing
-
readUnsignedVarInt
public static int readUnsignedVarInt(InputStream in) throws IOException
- Throws:
IOException
-
readZigZagVarInt
public static int readZigZagVarInt(InputStream in) throws IOException
uses a trick mentioned in https://developers.google.com/protocol-buffers/docs/encoding to read zigZag encoded data- Parameters:
in
- an input stream- Returns:
- the value of a zig-zag varint read from the current position in the stream
- Throws:
IOException
- if there is an exception while reading
-
writeUnsignedVarInt
public static void writeUnsignedVarInt(int value, OutputStream out) throws IOException
- Throws:
IOException
-
writeUnsignedVarInt
public static void writeUnsignedVarInt(int value, ByteBuffer dest) throws IOException
- Throws:
IOException
-
writeZigZagVarInt
public static void writeZigZagVarInt(int intValue, OutputStream out) throws IOException
- Throws:
IOException
-
readZigZagVarLong
public static long readZigZagVarLong(InputStream in) throws IOException
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. Is there a need for different functions?- Parameters:
in
- an input stream- Returns:
- the value of a zig-zag var-long read from the current position in the stream
- Throws:
IOException
- if there is an exception while reading
-
readUnsignedVarLong
public static long readUnsignedVarLong(InputStream in) throws IOException
- Throws:
IOException
-
writeUnsignedVarLong
public static void writeUnsignedVarLong(long value, OutputStream out) throws IOException
- Throws:
IOException
-
writeZigZagVarLong
public static void writeZigZagVarLong(long longValue, OutputStream out) throws IOException
- Throws:
IOException
-
paddedByteCountFromBits
public static int paddedByteCountFromBits(int bitLength)
- Parameters:
bitLength
- a count of bits- Returns:
- the corresponding byte count padded to the next byte
-
intToBytes
public static byte[] intToBytes(int value)
-
bytesToInt
public static int bytesToInt(byte[] bytes)
-
longToBytes
public static byte[] longToBytes(long value)
-
bytesToLong
public static long bytesToLong(byte[] bytes)
-
booleanToBytes
public static byte[] booleanToBytes(boolean value)
-
bytesToBool
public static boolean bytesToBool(byte[] bytes)
-
-