Class BytesUtils

java.lang.Object
org.apache.parquet.bytes.BytesUtils

public class BytesUtils extends Object
utility methods to deal with bytes
  • Field Details

  • 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

      public static int readIntLittleEndian(ByteBuffer in, int offset) throws IOException
      reads an int in little endian at the given position
      Parameters:
      in - a byte buffer
      offset - 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 array
      offset - 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 stream
      v - an int value
      bitWidth - 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
    • writeUnsignedVarLong

      public static void writeUnsignedVarLong(long value, ByteBuffer out)
    • 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)