Class ClickHouseByteBuffer

    • Field Detail

      • EMPTY_BYTES

        public static final byte[] EMPTY_BYTES
        Empty byte array.
      • EMPTY_BUFFER

        public static final ByteBuffer EMPTY_BUFFER
        Empty and read-only byte buffer.
      • array

        protected byte[] array
      • position

        protected int position
      • length

        protected int length
    • Constructor Detail

      • ClickHouseByteBuffer

        protected ClickHouseByteBuffer​(byte[] bytes,
                                       int offset,
                                       int length)
        Default constructor.
        Parameters:
        bytes - non-null byte array
        offset - start position
        length - length of bytes
    • Method Detail

      • newInstance

        public static ClickHouseByteBuffer newInstance()
        Creates an empty byte buffer.
        Returns:
        empty byte buffer
      • of

        public static ClickHouseByteBuffer of​(byte[] bytes)
        Wraps given byte array as byte buffer.
        Parameters:
        bytes - byte array
        Returns:
        non-null byte buffer
      • of

        public static ClickHouseByteBuffer of​(byte[] bytes,
                                              int offset,
                                              int length)
        Wraps given byte array as byte buffer.
        Parameters:
        bytes - byte array
        offset - start position
        length - length
        Returns:
        non-null byte buffer
      • of

        public static ClickHouseByteBuffer of​(List<byte[]> list,
                                              int offset,
                                              int length)
        Wraps given byte arrays as byte buffer.
        Parameters:
        list - list of non-null byte arrays
        offset - offset
        length - length
        Returns:
        non-null byte buffer
      • asInt32

        @Deprecated
        public int asInt32()
        Deprecated.
        will be removed in v0.3.3, please use asInteger() instead
        Converts 4 bytes(little-endian) to Int32. Same as getInteger(0).
        Returns:
        Int32 value
      • asUnsignedInt32

        @Deprecated
        public long asUnsignedInt32()
        Deprecated.
        will be removed in v0.3.3, please use asUnsignedInteger() instead
        Converts 4 bytes(little-endian) to UInt32. Same as getUnsignedInteger(0).
        Returns:
        UInt32 value
      • getInt32

        @Deprecated
        public int getInt32​(int offset)
        Deprecated.
        will be removed in v0.3.3, please use getInteger(int) instead
        Converts 4 bytes(little-endian) starting from position() + offset to Int32.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        Int32 value
      • getUnsignedInt32

        @Deprecated
        public long getUnsignedInt32​(int offset)
        Deprecated.
        will be removed in v0.3.3, please use getUnsignedInteger(int) instead
        Converts 4 bytes(little-endian) starting from position() + offset to UInt32.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        UInt32 value
      • asInt64

        @Deprecated
        public long asInt64()
        Deprecated.
        will be removed in v0.3.3, please use asLong() instead
        Converts 8 bytes(little-endian) to Int64. Same as getLong(0).
        Returns:
        Int64 value
      • asUnsignedInt64

        @Deprecated
        public BigInteger asUnsignedInt64()
        Deprecated.
        will be removed in v0.3.3, please use asUnsignedLong() instead
        Converts 8 bytes(little-endian) to unsigned Int64. Same as getBigInteger(0, 8, true).
        Returns:
        unsigned Int64 value
      • getInt64

        @Deprecated
        public long getInt64​(int offset)
        Deprecated.
        will be removed in v0.3.3, please use getLong(int) instead
        Converts 8 bytes(little-endian) starting from position() + offset to Int64.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        Int64 value
      • asBigInteger

        public BigInteger asBigInteger()
        Converts all bytes(little-endian) to signed big integer. Same as getBigInteger(0, length(), false).
        Returns:
        non-null signed big integer
      • asDouble

        public double asDouble()
      • asDoubleArray

        public double[] asDoubleArray()
      • asFloat

        public float asFloat()
      • asFloatArray

        public float[] asFloatArray()
      • asUnsignedBigInteger

        public BigInteger asUnsignedBigInteger()
        Converts all bytes(little-endian) to unsigned big integer. Same as getBigInteger(0, length(), true).
        Returns:
        non-null unsigned big integer
      • getBigInteger

        public BigInteger getBigInteger​(int offset,
                                        int byteLength,
                                        boolean unsigned)
        Converts byteLength bytes(little-endian) starting from position() + offset to big integer.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        byteLength - bytes to convert
        unsigned - true if it's unsigned big integer; false otherwise
        Returns:
        non-null big integer
      • getDouble

        public double getDouble​(int offset)
        Converts 8 bytes(little-endian) starting from position() + offset to double.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        double
      • getFloat

        public float getFloat​(int offset)
        Converts 4 bytes(little-endian) starting from position() + offset to float.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        float
      • getInteger

        public int getInteger​(int offset)
        Converts 4 bytes(little-endian) starting from position() + offset to signed integer.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        signed integer
      • getLong

        public long getLong​(int offset)
        Converts 8 bytes(little-endian) starting from position() + offset to signed long.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        signed long
      • getShort

        public short getShort​(int offset)
        Converts 2 bytes(little-endian) starting from position() + offset to signed short.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        signed short
      • getUnsignedInteger

        public long getUnsignedInteger​(int offset)
        Converts 4 bytes(little-endian) starting from position() + offset to unsigned integer.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        unsigned integer
      • getUnsignedLong

        public BigInteger getUnsignedLong​(int offset)
        Converts 8 bytes(little-endian) starting from position() + offset to unsigned long.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        non-null unsigned long
      • getUnsignedShort

        public int getUnsignedShort​(int offset)
        Converts 2 bytes(little-endian) starting from position() + offset to unsigned short.
        Parameters:
        offset - zero-based relative offset, 1 means the second byte starting from position()
        Returns:
        unsigned short
      • asBigIntegerArray

        public BigInteger[] asBigIntegerArray​(int byteLength,
                                              boolean unsigned)
      • asInteger

        public int asInteger()
      • asLong

        public long asLong()
      • asShort

        public short asShort()
      • asIntegerArray

        public int[] asIntegerArray()
      • asLongArray

        public long[] asLongArray()
      • asShortArray

        public short[] asShortArray()
      • asUnsignedInteger

        public long asUnsignedInteger()
      • asUnsignedLong

        public BigInteger asUnsignedLong()
      • asUnsignedShort

        public int asUnsignedShort()
      • asUnsignedIntegerArray

        public long[] asUnsignedIntegerArray()
      • asUnsignedShortArray

        public int[] asUnsignedShortArray()
      • asUuid

        public UUID asUuid()
      • getUuid

        public UUID getUuid​(int offset)
      • asAsciiString

        public String asAsciiString()
        Converts to ASCII string.
        Returns:
        non-null ASCII string
      • asString

        public String asString​(Charset charset)
        Converts to string using given charset.
        Parameters:
        charset - optional charset, null is treated as StandardCharsets.UTF_8
        Returns:
        non-null string
      • asUnicodeString

        public String asUnicodeString()
        Converts to UTF-8 string.
        Returns:
        non-null UTF-8 string
      • compact

        public ClickHouseByteBuffer compact()
        Compacts byte array by creating a new copy with exact same length but position changed to zero. It does nothing when position is zero and length is same as bytes.length.
        Returns:
        this byte buffer
      • isCompact

        public boolean isCompact()
        Checks whether the buffer is compact or not. A buffer is compact when position points to zero and length equals to array().length.
        Returns:
        true if the buffer is compact; false otherwise
      • isEmpty

        public boolean isEmpty()
        Checks whether the buffer is empty or not. Please pay attention that this will return true when length() is zero, even array() may return an non-empty byte array.
        Returns:
        true if the buffer is empty; false otherwise
      • reverse

        public ClickHouseByteBuffer reverse()
        Reverses the byte array.
        Returns:
        this byte buffer
      • reverse

        public ClickHouseByteBuffer reverse​(int offset,
                                            int length)
        Reverses the byte array.
        Parameters:
        offset - start position
        length - bytes to reserve
        Returns:
        this byte buffer
      • slice

        public ClickHouseByteBuffer slice​(int offset,
                                          int length)
        Gets slice of the byte buffer.
        Parameters:
        offset - offset zero-based relative offset, 1 means the second byte starting from position()
        length - length of the slice
        Returns:
        non-null slice of the byte buffer(backed by the same byte array but with different position and length)
      • update

        public ClickHouseByteBuffer update​(byte[] bytes)
        Updates buffer.
        Parameters:
        bytes - byte array, null is same as empty byte array
        Returns:
        this byte buffer
      • update

        public ClickHouseByteBuffer update​(byte[] bytes,
                                           int offset,
                                           int length)
        Updates buffer.
        Parameters:
        bytes - byte array, null is same as empty byte array
        offset - start position
        length - length of bytes
        Returns:
        this byte buffer
      • update

        public ClickHouseByteBuffer update​(List<byte[]> list,
                                           int offset,
                                           int length)
        Updates buffer.
        Parameters:
        list - list of byte arrays, null is same as empty byte array
        offset - start position
        length - length of bytes
        Returns:
        this byte buffer
      • array

        public byte[] array()
        Gets byte array.
        Returns:
        non-null byte array
      • firstByte

        public byte firstByte()
      • lastByte

        public byte lastByte()
      • position

        public int position()
        Gets start position.
        Returns:
        start position
      • position

        public ClickHouseByteBuffer position​(int newPosition)
        Sets new position.
        Parameters:
        newPosition - new position, which should be always less than limit()
        Returns:
        this byte buffer
      • length

        public int length()
        Gets length of bytes.
        Returns:
        length of bytes
      • limit

        public int limit()
        Gets end position.
        Returns:
        end position
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object