Package com.clickhouse.data
Class ClickHouseByteUtils
java.lang.Object
com.clickhouse.data.ClickHouseByteUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanequals(byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex) static floatgetFloat32(byte[] bytes, int offset) static doublegetFloat64(byte[] bytes, int offset) static shortgetInt16(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 intgetInt32(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 longgetInt64(byte[] bytes, int offset) static byte[]getOrCopy(ByteBuffer buffer, int length) static intgetVarInt(ByteBuffer buffer) Gets varint from given byte buffer.static intgetVarIntSize(int value) Get varint length of given integer.static intgetVarLongSize(long value) Get varint length of given long.static intindexOf(byte[] bytes, byte[] search) Returns the index of the first occurrence of the specifiedsearcharray within the givenbytesarray.static intindexOf(byte[] bytes, int bpos, int blen, byte[] search, int spos, int slen) Returns the index of the first occurrence of the specifiedsearcharray within the givenbytesarray, considering specified positions and lengths for both arrays.static intindexOf(byte[] bytes, int bpos, int blen, byte[] search, int spos, int slen, boolean partial) Returns the index of the first occurrence of the specifiedsearcharray within the givenbytesarray, considering specified positions and lengths for both arrays and partial matching at the end of the bytes array.static intreadVarInt(InputStream input) Reads varint from given input stream.static voidsetFloat32(byte[] bytes, int offset, float value) static voidsetFloat64(byte[] bytes, int offset, double value) static voidsetInt16(byte[] bytes, int offset, short value) static voidsetInt32(byte[] bytes, int offset, int value) static voidsetInt64(byte[] bytes, int offset, long value) static voidsetVarInt(ByteBuffer buffer, int value) Write varint to given output stream.static voidwriteVarInt(OutputStream output, long value) Writes varint to given output stream.
-
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 valueoffset- 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 valueoffset- 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
-
indexOf
public static int indexOf(byte[] bytes, byte[] search) Returns the index of the first occurrence of the specifiedsearcharray within the givenbytesarray. Same asindexOf(bytes, 0, bytes.length, search, 0, search.length, false).- Parameters:
bytes- the byte array in which to search for the specifiedsearcharray.search- the byte array to search for within thebytesarray.- 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 specifiedsearcharray within the givenbytesarray, considering specified positions and lengths for both arrays.- Parameters:
bytes- the byte array in which to search for the specifiedsearcharray.bpos- the starting position in thebytesarray from which to searchblen- the number of bytes in thebytesarray to consider for searchingsearch- the byte array to search for within thebytesarray.spos- the starting position in thesearcharray to consider for matchingslen- the number of bytes in thesearcharray 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 specifiedsearcharray within the givenbytesarray, 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 specifiedsearcharray.bpos- the starting position in thebytesarray from which to searchblen- the number of bytes in thebytesarray to consider for searchingsearch- the byte array to search for within thebytesarray.spos- the starting position in thesearcharray to consider for matchingslen- the number of bytes in thesearcharray to consider for matchingpartial- 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
Gets varint from given byte buffer.- Parameters:
buffer- non-null byte buffer- Returns:
- varint
-
setVarInt
Write varint to given output stream.- Parameters:
buffer- non-null byte buffervalue- integer value
-
readVarInt
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
Writes varint to given output stream.- Parameters:
output- non-null output streamvalue- long value- Throws:
IOException- when failed to write value to output stream or reached end of the stream
-