Package org.apache.parquet.bytes
Class BytesUtils
java.lang.Object
org.apache.parquet.bytes.BytesUtils
utility methods to deal with bytes
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]booleanToBytes(boolean value) static booleanbytesToBool(byte[] bytes) static intbytesToInt(byte[] bytes) static longbytesToLong(byte[] bytes) static intgetWidthFromMaxInt(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 intpaddedByteCountFromBits(int bitLength) static intreadIntLittleEndian(byte[] in, int offset) reads an int in little endian at the given positionstatic intstatic intreadIntLittleEndian(ByteBuffer in, int offset) reads an int in little endian at the given positionstatic intstatic intstatic intstatic intreadIntLittleEndianPaddedOnBitWidth(InputStream in, int bitWidth) static intstatic longstatic intuses a trick mentioned in https://developers.google.com/protocol-buffers/docs/encoding to read zigZag encoded datastatic longuses 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 voidwriteIntLittleEndian(OutputStream out, int v) static voidwriteIntLittleEndianOnOneByte(OutputStream out, int v) static voidwriteIntLittleEndianOnThreeBytes(OutputStream out, int v) static voidwriteIntLittleEndianOnTwoBytes(OutputStream out, int v) static voidwriteIntLittleEndianPaddedOnBitWidth(OutputStream out, int v, int bitWidth) Write a little endian int to out, using the the number of bytes required by bit widthstatic voidwriteUnsignedVarInt(int value, OutputStream out) static voidwriteUnsignedVarInt(int value, ByteBuffer dest) static voidwriteUnsignedVarLong(long value, OutputStream out) static voidwriteUnsignedVarLong(long value, ByteBuffer out) static voidwriteZigZagVarInt(int intValue, OutputStream out) static voidwriteZigZagVarLong(long longValue, OutputStream out)
-
Field Details
-
UTF8
Deprecated.UseStandardCharsets.UTF_8instead
-
-
Constructor Details
-
BytesUtils
public BytesUtils()
-
-
Method Details
-
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
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
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
- Throws:
IOException
-
readIntLittleEndianOnOneByte
- Throws:
IOException
-
readIntLittleEndianOnTwoBytes
- Throws:
IOException
-
readIntLittleEndianOnThreeBytes
- Throws:
IOException
-
readIntLittleEndianPaddedOnBitWidth
public static int readIntLittleEndianPaddedOnBitWidth(InputStream in, int bitWidth) throws IOException - Throws:
IOException
-
writeIntLittleEndianOnOneByte
- Throws:
IOException
-
writeIntLittleEndianOnTwoBytes
- Throws:
IOException
-
writeIntLittleEndianOnThreeBytes
- Throws:
IOException
-
writeIntLittleEndian
- 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
- Throws:
IOException
-
readZigZagVarInt
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
- Throws:
IOException
-
writeUnsignedVarInt
- Throws:
IOException
-
writeZigZagVarInt
- Throws:
IOException
-
readZigZagVarLong
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
- Throws:
IOException
-
writeUnsignedVarLong
- Throws:
IOException
-
writeUnsignedVarLong
-
writeZigZagVarLong
- 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)
-
StandardCharsets.UTF_8instead