Class ClickHouseByteUtils

java.lang.Object
com.clickhouse.data.ClickHouseByteUtils

public final class ClickHouseByteUtils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    equals(byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
     
    static float
    getFloat32(byte[] bytes, int offset)
     
    static double
    getFloat64(byte[] bytes, int offset)
     
    static short
    getInt16(byte[] bytes, int offset)
    Reads a 16-bit integer in little-endian byte order from the given byte array starting at the specified offset.
    static int
    getInt32(byte[] bytes, int offset)
    Reads a 32-bit integer in little-endian byte order from the given byte array starting at the specified offset.
    static long
    getInt64(byte[] bytes, int offset)
     
    static byte[]
    getOrCopy(ByteBuffer buffer, int length)
     
    static int
    Gets varint from given byte buffer.
    static int
    getVarIntSize(int value)
    Get varint length of given integer.
    static int
    getVarLongSize(long value)
    Get varint length of given long.
    static int
    indexOf(byte[] bytes, byte[] search)
    Returns the index of the first occurrence of the specified search array within the given bytes array.
    static int
    indexOf(byte[] bytes, int bpos, int blen, byte[] search, int spos, int slen)
    Returns the index of the first occurrence of the specified search array within the given bytes array, considering specified positions and lengths for both arrays.
    static int
    indexOf(byte[] bytes, int bpos, int blen, byte[] search, int spos, int slen, boolean partial)
    Returns the index of the first occurrence of the specified search array within the given bytes array, considering specified positions and lengths for both arrays and partial matching at the end of the bytes array.
    static int
    Reads varint from given input stream.
    static void
    setFloat32(byte[] bytes, int offset, float value)
     
    static void
    setFloat64(byte[] bytes, int offset, double value)
     
    static void
    setInt16(byte[] bytes, int offset, short value)
     
    static void
    setInt32(byte[] bytes, int offset, int value)
     
    static void
    setInt64(byte[] bytes, int offset, long value)
     
    static void
    setVarInt(ByteBuffer buffer, int value)
    Write varint to given output stream.
    static void
    writeVarInt(OutputStream output, long value)
    Writes varint to given output stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • equals

      public static boolean equals(byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
    • getInt16

      public static short getInt16(byte[] bytes, int offset)
      Reads a 16-bit integer in little-endian byte order from the given byte array starting at the specified offset.
      Parameters:
      bytes - the byte array containing the integer value
      offset - the starting position of the integer value within the byte array
      Returns:
      the 16-bit integer value read from the byte array
    • setInt16

      public static void setInt16(byte[] bytes, int offset, short value)
    • getInt32

      public static int getInt32(byte[] bytes, int offset)
      Reads a 32-bit integer in little-endian byte order from the given byte array starting at the specified offset.
      Parameters:
      bytes - the byte array containing the integer value
      offset - the starting position of the integer value within the byte array
      Returns:
      the 32-bit integer value read from the byte array
    • setInt32

      public static void setInt32(byte[] bytes, int offset, int value)
    • getInt64

      public static long getInt64(byte[] bytes, int offset)
    • setInt64

      public static void setInt64(byte[] bytes, int offset, long value)
    • getFloat32

      public static float getFloat32(byte[] bytes, int offset)
    • setFloat32

      public static void setFloat32(byte[] bytes, int offset, float value)
    • getFloat64

      public static double getFloat64(byte[] bytes, int offset)
    • setFloat64

      public static void setFloat64(byte[] bytes, int offset, double value)
    • getOrCopy

      public static byte[] getOrCopy(ByteBuffer buffer, int length)
    • indexOf

      public static int indexOf(byte[] bytes, byte[] search)
      Returns the index of the first occurrence of the specified search array within the given bytes array. Same as indexOf(bytes, 0, bytes.length, search, 0, search.length, false).
      Parameters:
      bytes - the byte array in which to search for the specified search array.
      search - the byte array to search for within the bytes array.
      Returns:
      the index of the first occurrence of the search array within the bytes array, or -1 if the search array is not found
    • indexOf

      public static int indexOf(byte[] bytes, int bpos, int blen, byte[] search, int spos, int slen)
      Returns the index of the first occurrence of the specified search array within the given bytes array, considering specified positions and lengths for both arrays.
      Parameters:
      bytes - the byte array in which to search for the specified search array.
      bpos - the starting position in the bytes array from which to search
      blen - the number of bytes in the bytes array to consider for searching
      search - the byte array to search for within the bytes array.
      spos - the starting position in the search array to consider for matching
      slen - the number of bytes in the search array to consider for matching
      Returns:
      the index of the first occurrence of the search array within the bytes array, or -1 if the search array is not found
    • indexOf

      public static int indexOf(byte[] bytes, int bpos, int blen, byte[] search, int spos, int slen, boolean partial)
      Returns the index of the first occurrence of the specified search array within the given bytes array, considering specified positions and lengths for both arrays and partial matching at the end of the bytes array.
      Parameters:
      bytes - the byte array in which to search for the specified search array.
      bpos - the starting position in the bytes array from which to search
      blen - the number of bytes in the bytes array to consider for searching
      search - the byte array to search for within the bytes array.
      spos - the starting position in the search array to consider for matching
      slen - the number of bytes in the search array to consider for matching
      partial - whether partial match should be considered
      Returns:
      the index of the first occurrence of the search array within the bytes array, or -1 if the search array is not found
    • getVarIntSize

      public static int getVarIntSize(int value)
      Get varint length of given integer.
      Parameters:
      value - integer
      Returns:
      varint length
    • getVarLongSize

      public static int getVarLongSize(long value)
      Get varint length of given long.
      Parameters:
      value - long
      Returns:
      varint length
    • getVarInt

      public static int getVarInt(ByteBuffer buffer)
      Gets varint from given byte buffer.
      Parameters:
      buffer - non-null byte buffer
      Returns:
      varint
    • setVarInt

      public static void setVarInt(ByteBuffer buffer, int value)
      Write varint to given output stream.
      Parameters:
      buffer - non-null byte buffer
      value - integer value
    • readVarInt

      public static int readVarInt(InputStream input) throws IOException
      Reads varint from given input stream.
      Parameters:
      input - non-null input stream
      Returns:
      varint
      Throws:
      IOException - when failed to read value from input stream or reached end of the stream
    • writeVarInt

      public static void writeVarInt(OutputStream output, long value) throws IOException
      Writes varint to given output stream.
      Parameters:
      output - non-null output stream
      value - long value
      Throws:
      IOException - when failed to write value to output stream or reached end of the stream