Package com.clickhouse.client.data
Class BinaryStreamUtils
- java.lang.Object
-
- com.clickhouse.client.data.BinaryStreamUtils
-
public final class BinaryStreamUtils extends Object
Utility class for dealing with binary stream and data.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DATE32_MAX
static int
DATE32_MIN
static long
DATETIME_MAX
static long
DATETIME64_MAX
static long
DATETIME64_MIN
static BigDecimal
DECIMAL128_MAX
static BigDecimal
DECIMAL128_MIN
static BigDecimal
DECIMAL256_MAX
static BigDecimal
DECIMAL256_MIN
static BigDecimal
DECIMAL32_MAX
static BigDecimal
DECIMAL32_MIN
static BigDecimal
DECIMAL64_MAX
static BigDecimal
DECIMAL64_MIN
static long
MILLIS_IN_DAY
static BigDecimal
NANOS
static BigInteger
U_INT128_MAX
static int
U_INT16_MAX
static BigInteger
U_INT256_MAX
static long
U_INT32_MAX
static BigInteger
U_INT64_MAX
static int
U_INT8_MAX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getVarIntSize(int value)
Get varint length of given integer.static int
getVarLongSize(long value)
Get varint length of given long.static ClickHouseBitmap
readBitmap(ClickHouseInputStream input, ClickHouseDataType dataType)
Reads bitmap from given input stream.static boolean
readBoolean(ClickHouseInputStream input)
Read boolean from given input stream.static char[]
readCharacters(Reader input, int length)
Readslength
characters from given reader.static LocalDate
readDate(ClickHouseInputStream input)
ReadLocalDate
from given input stream.static LocalDate
readDate(ClickHouseInputStream input, TimeZone tz)
ReadLocalDate
from given input stream.static LocalDate
readDate32(ClickHouseInputStream input)
ReadLocalDate
from given input stream.static LocalDate
readDate32(ClickHouseInputStream input, TimeZone tz)
ReadLocalDate
from given input stream.static LocalDateTime
readDateTime(ClickHouseInputStream input, int scale, TimeZone tz)
ReadLocalDateTime
from given input stream.static LocalDateTime
readDateTime(ClickHouseInputStream input, TimeZone tz)
ReadLocalDateTime
from given input stream.static LocalDateTime
readDateTime32(ClickHouseInputStream input, TimeZone tz)
ReadLocalDateTime
from given input stream.static LocalDateTime
readDateTime64(ClickHouseInputStream input, int scale, TimeZone tz)
ReadLocalDateTime
from given input stream.static LocalDateTime
readDateTime64(ClickHouseInputStream input, TimeZone tz)
ReadLocalDateTime
from given input stream.static BigDecimal
readDecimal(ClickHouseInputStream input, int precision, int scale)
Read big decimal(4 - 32 bytes) from given input stream.static BigDecimal
readDecimal128(ClickHouseInputStream input, int scale)
Read big decimal(16 bytes) from given input stream.static BigDecimal
readDecimal256(ClickHouseInputStream input, int scale)
Read big decimal from given input stream.static BigDecimal
readDecimal32(ClickHouseInputStream input, int scale)
Read big decimal(4 bytes) from given input stream.static BigDecimal
readDecimal64(ClickHouseInputStream input, int scale)
Read big decimal(8 bytes) from gicen input stream.static short
readEnum16(ClickHouseInputStream input)
Read enum value from given input stream.static <T extends Enum<T>>
TreadEnum16(ClickHouseInputStream input, Class<T> enumType)
Read enum value from given input stream.static byte
readEnum8(ClickHouseInputStream input)
Read enum value from given input stream.static <T extends Enum<T>>
TreadEnum8(ClickHouseInputStream input, Class<T> enumType)
Read enum value from given input stream.static String
readFixedString(ClickHouseInputStream input, int length)
Read string with fixed length from given input stream.static String
readFixedString(ClickHouseInputStream input, int length, Charset charset)
Read string with fixed length from given input stream.static float
readFloat32(ClickHouseInputStream input)
Read a float value from given input stream.static double
readFloat64(ClickHouseInputStream input)
Read a double value from given input stream.static double[][][][]
readGeoMultiPolygon(ClickHouseInputStream input)
Read geo multi-polygon(array of polygons) from given input stream.static double[]
readGeoPoint(ClickHouseInputStream input)
Read geo point(X and Y coordinates) from given input stream.static double[][][]
readGeoPolygon(ClickHouseInputStream input)
Read geo polygon(array of rings) from given input stream.static double[][]
readGeoRing(ClickHouseInputStream input)
Read geo ring(array of X and Y coordinates) from given input stream.static Inet4Address
readInet4Address(ClickHouseInputStream input)
Read Inet4Address from given input stream.static Inet6Address
readInet6Address(ClickHouseInputStream input)
Read Inet6Address from given input stream.static BigInteger
readInt128(ClickHouseInputStream input)
Read a big integer(16 bytes) from given input stream.static short
readInt16(ClickHouseInputStream input)
Read a short value from given input stream.static BigInteger
readInt256(ClickHouseInputStream input)
Read a big integer(32 bytes) from given input stream.static int
readInt32(ClickHouseInputStream input)
Read an integer from given input stream.static long
readInt64(ClickHouseInputStream input)
Read a long value from given input stream.static byte
readInt8(ClickHouseInputStream input)
Read a byte from given input stream.static boolean
readNull(ClickHouseInputStream input)
Read null marker from input stream.static String
readString(Reader input, int length)
Reads characters from given reader.static BigInteger
readUnsignedInt128(ClickHouseInputStream input)
Read an unsigned big integer from given input stream.static int
readUnsignedInt16(ClickHouseInputStream input)
Read an unsigned short value from given input stream.static BigInteger
readUnsignedInt256(ClickHouseInputStream input)
Read an unsigned big integer(32 bytes) from given input stream.static long
readUnsignedInt32(ClickHouseInputStream input)
Read an unsigned integer from given input stream.static BigInteger
readUnsignedInt64(ClickHouseInputStream input)
Read an unsigned long value from given input stream.static short
readUnsignedInt8(ClickHouseInputStream input)
Read an unsigned byte as short from given input stream.static UUID
readUuid(ClickHouseInputStream input)
Read UUID from given input stream.static int
readVarInt(InputStream input)
Read varint from given input stream.static int
readVarInt(ByteBuffer buffer)
Read varint from given byte buffer.static byte[]
reverse(byte[] bytes)
Reverse the given byte array.static void
setInt32(byte[] bytes, int offset, int value)
static void
setInt64(byte[] bytes, int offset, long value)
static int
toInt32(byte[] bytes, int offset)
static int
toInt32(ClickHouseByteBuffer byteBuffer)
static long
toInt64(byte[] bytes, int offset)
static long
toInt64(ClickHouseByteBuffer byteBuffer)
static void
writeBigInteger(OutputStream output, BigInteger value, int length)
Write alength
-byte long big integer to given output stream.static void
writeBitmap(OutputStream output, ClickHouseBitmap bitmap)
Writes bitmap into given output stream.static void
writeBoolean(OutputStream output, boolean value)
Write boolean into given output stream.static void
writeBoolean(OutputStream output, int value)
Write integer as boolean into given output stream.static void
writeByteBuffer(OutputStream output, ByteBuffer buffer)
Writes bytes into given output stream.static void
writeBytes(OutputStream output, byte[] bytes)
Writes bytes into given output stream.static void
writeDate(OutputStream output, LocalDate value)
Write aLocalDate
to given output stream.static void
writeDate(OutputStream output, LocalDate value, TimeZone tz)
Write aLocalDate
to given output stream.static void
writeDate32(OutputStream output, LocalDate value)
Write aLocalDate
to given output stream.static void
writeDate32(OutputStream output, LocalDate value, TimeZone tz)
Write aLocalDate
to given output stream.static void
writeDateTime(OutputStream output, LocalDateTime value, int scale, TimeZone tz)
Write aLocalDateTime
to given output stream.static void
writeDateTime(OutputStream output, LocalDateTime value, TimeZone tz)
Write aLocalDateTime
to given output stream.static void
writeDateTime32(OutputStream output, LocalDateTime value, TimeZone tz)
Write aLocalDateTime
to given output stream.static void
writeDateTime64(OutputStream output, LocalDateTime value, int scale, TimeZone tz)
Write aLocalDateTime
to given output stream.static void
writeDateTime64(OutputStream output, LocalDateTime value, TimeZone tz)
Write aLocalDateTime
to given output stream.static void
writeDecimal(OutputStream output, BigDecimal value, int precision, int scale)
Write a big decimal(4 - 32 bytes) to given output stream.static void
writeDecimal128(OutputStream output, BigDecimal value, int scale)
Write a big decimal(16 bytes) to given output stream.static void
writeDecimal256(OutputStream output, BigDecimal value, int scale)
Write a big decimal(32 bytes) to given output stream.static void
writeDecimal32(OutputStream output, BigDecimal value, int scale)
Write a big decimal(4 bytes) to given output stream.static void
writeDecimal64(OutputStream output, BigDecimal value, int scale)
Write a big decimal(8 bytes) to given output stream.static void
writeEnum16(OutputStream output, int value)
Write enum value into given output stream.static <T extends Enum<T>>
voidwriteEnum16(OutputStream output, T value)
Write enum value into given output stream.static void
writeEnum8(OutputStream output, byte value)
Write enum value into given output stream.static <T extends Enum<T>>
voidwriteEnum8(OutputStream output, T value)
Write enum value into given output stream.static void
writeFixedString(OutputStream output, String value, int length)
Write a string with fixed length to given output stream.static void
writeFixedString(OutputStream output, String value, int length, Charset charset)
Write a string with fixed length to given output stream.static void
writeFloat32(OutputStream output, float value)
Write a float value to given output stream.static void
writeFloat64(OutputStream output, double value)
Write a double value to given output stream.static void
writeGeoMultiPolygon(OutputStream output, double[][][][] value)
Write geo polygon(array of rings).static void
writeGeoPoint(OutputStream output, double[] value)
Write geo point(X and Y coordinates).static void
writeGeoPoint(OutputStream output, double x, double y)
Write geo point(X and Y coordinates).static void
writeGeoPolygon(OutputStream output, double[][][] value)
Write geo polygon(array of rings).static void
writeGeoRing(OutputStream output, double[][] value)
Write geo ring(array of X and Y coordinates).static void
writeInet4Address(OutputStream output, Inet4Address value)
Write Inet4Address to given output stream.static void
writeInet6Address(OutputStream output, Inet6Address value)
Write Inet6Address to given output stream.static void
writeInt128(OutputStream output, BigInteger value)
Write a big integer(16 bytes) to given output stream.static void
writeInt16(OutputStream output, int value)
Write a short value to given output stream.static void
writeInt16(OutputStream output, short value)
Write a short value to given output stream.static void
writeInt256(OutputStream output, BigInteger value)
Write a big integer(32 bytes) to given output stream.static void
writeInt32(OutputStream output, int value)
Write an integer to given output stream.static void
writeInt64(OutputStream output, long value)
Write a long value to given output stream.static void
writeInt8(OutputStream output, byte value)
Write a byte to given output stream.static void
writeInt8(OutputStream output, int value)
Write a byte to given output stream.static void
writeNonNull(OutputStream output)
Write non-null marker.static void
writeNull(OutputStream output)
Write null marker.static void
writeString(OutputStream output, byte[] value)
Writes a binary string to given output stream.static void
writeString(OutputStream output, String value)
Write a string to given output stream.static void
writeString(OutputStream output, String value, Charset charset)
Write a string to given output stream.static void
writeUnsignedInt128(OutputStream output, BigInteger value)
Write an unsigned big integer(16 bytes) to given output stream.static void
writeUnsignedInt16(OutputStream output, int value)
Write an unsigned short value to given output stream.static void
writeUnsignedInt256(OutputStream output, BigInteger value)
Write an unsigned big integer(32 bytes) to given output stream.static void
writeUnsignedInt32(OutputStream output, long value)
Write an unsigned integer to given output stream.static void
writeUnsignedInt64(OutputStream output, long value)
Write an unsigned long value to given output stream.static void
writeUnsignedInt64(OutputStream output, BigInteger value)
Write an unsigned long value to given output stream.static void
writeUnsignedInt8(OutputStream output, int value)
Write an unsigned byte to given output stream.static void
writeUuid(OutputStream output, UUID value)
Write a UUID to given output stream.static void
writeVarInt(OutputStream output, long value)
Write varint to given output stream.static void
writeVarInt(ByteBuffer buffer, int value)
Write varint to given output stream.
-
-
-
Field Detail
-
U_INT8_MAX
public static final int U_INT8_MAX
- See Also:
- Constant Field Values
-
U_INT16_MAX
public static final int U_INT16_MAX
- See Also:
- Constant Field Values
-
U_INT32_MAX
public static final long U_INT32_MAX
- See Also:
- Constant Field Values
-
U_INT64_MAX
public static final BigInteger U_INT64_MAX
-
U_INT128_MAX
public static final BigInteger U_INT128_MAX
-
U_INT256_MAX
public static final BigInteger U_INT256_MAX
-
DATE32_MAX
public static final int DATE32_MAX
-
DATE32_MIN
public static final int DATE32_MIN
-
DECIMAL32_MAX
public static final BigDecimal DECIMAL32_MAX
-
DECIMAL32_MIN
public static final BigDecimal DECIMAL32_MIN
-
DECIMAL64_MAX
public static final BigDecimal DECIMAL64_MAX
-
DECIMAL64_MIN
public static final BigDecimal DECIMAL64_MIN
-
DECIMAL128_MAX
public static final BigDecimal DECIMAL128_MAX
-
DECIMAL128_MIN
public static final BigDecimal DECIMAL128_MIN
-
DECIMAL256_MAX
public static final BigDecimal DECIMAL256_MAX
-
DECIMAL256_MIN
public static final BigDecimal DECIMAL256_MIN
-
DATETIME64_MAX
public static final long DATETIME64_MAX
-
DATETIME64_MIN
public static final long DATETIME64_MIN
-
MILLIS_IN_DAY
public static final long MILLIS_IN_DAY
-
DATETIME_MAX
public static final long DATETIME_MAX
- See Also:
- Constant Field Values
-
NANOS
public static final BigDecimal NANOS
-
-
Method Detail
-
toInt32
public static int toInt32(ClickHouseByteBuffer byteBuffer)
-
toInt32
public static int toInt32(byte[] bytes, int offset)
-
toInt64
public static long toInt64(ClickHouseByteBuffer byteBuffer)
-
toInt64
public static long toInt64(byte[] bytes, int offset)
-
setInt32
public static void setInt32(byte[] bytes, int offset, int value)
-
setInt64
public static void setInt64(byte[] bytes, int offset, long value)
-
reverse
public static byte[] reverse(byte[] bytes)
Reverse the given byte array.- Parameters:
bytes
- byte array to manipulate- Returns:
- same byte array but reserved
-
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
-
writeByteBuffer
public static void writeByteBuffer(OutputStream output, ByteBuffer buffer) throws IOException
Writes bytes into given output stream.- Parameters:
output
- non-null output streambuffer
- non-null byte buffer- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readBitmap
public static ClickHouseBitmap readBitmap(ClickHouseInputStream input, ClickHouseDataType dataType) throws IOException
Reads bitmap from given input stream. It behaves in a similar way asDataInput.readFully(byte[])
.- Parameters:
input
- non-null inputdataType
- number of characters to read- Returns:
- non-null bitmap wrapper class
- Throws:
IOException
- when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
-
writeBitmap
public static void writeBitmap(OutputStream output, ClickHouseBitmap bitmap) throws IOException
Writes bitmap into given output stream.- Parameters:
output
- non-null output streambitmap
- non-null bitmap- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeBytes
public static void writeBytes(OutputStream output, byte[] bytes) throws IOException
Writes bytes into given output stream.- Parameters:
output
- non-null output streambytes
- non-null byte array- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readCharacters
public static char[] readCharacters(Reader input, int length) throws IOException
Readslength
characters from given reader. It behaves in a similar way asDataInput.readFully(byte[])
.- Parameters:
input
- non-null readerlength
- number of characters to read- Returns:
- character array and its length should be
length
- Throws:
IOException
- when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
-
readBoolean
public static boolean readBoolean(ClickHouseInputStream input) throws IOException
Read boolean from given input stream. It usesClickHouseInputStream.readByte()
to get value and returntrue
only when the value is1
.- Parameters:
input
- non-null input stream- Returns:
- boolean
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeBoolean
public static void writeBoolean(OutputStream output, boolean value) throws IOException
Write boolean into given output stream.- Parameters:
output
- non-null output streamvalue
- boolean value, true == 1 and false == 0- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeBoolean
public static void writeBoolean(OutputStream output, int value) throws IOException
Write integer as boolean into given output stream.- Parameters:
output
- non-null output streamvalue
- integer, everyting else besides one will be treated as zero(false)- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readEnum8
public static <T extends Enum<T>> T readEnum8(ClickHouseInputStream input, Class<T> enumType) throws IOException
Read enum value from given input stream.- Type Parameters:
T
- enum type- Parameters:
input
- non-null input streamenumType
- enum class- Returns:
- enum value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
readEnum8
public static byte readEnum8(ClickHouseInputStream input) throws IOException
Read enum value from given input stream. Same asreadInt8(ClickHouseInputStream)
.- Parameters:
input
- non-null input stream- Returns:
- enum value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeEnum8
public static void writeEnum8(OutputStream output, byte value) throws IOException
Write enum value into given output stream. Same aswriteInt8(OutputStream, byte)
.- Parameters:
output
- non-null output streamvalue
- enum value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeEnum8
public static <T extends Enum<T>> void writeEnum8(OutputStream output, T value) throws IOException
Write enum value into given output stream.- Type Parameters:
T
- type of the value- Parameters:
output
- non-null output streamvalue
- enum value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readEnum16
public static <T extends Enum<T>> T readEnum16(ClickHouseInputStream input, Class<T> enumType) throws IOException
Read enum value from given input stream.- Type Parameters:
T
- enum type- Parameters:
input
- non-null input streamenumType
- enum class- Returns:
- enum value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
readEnum16
public static short readEnum16(ClickHouseInputStream input) throws IOException
Read enum value from given input stream. Same asreadInt16(ClickHouseInputStream)
.- Parameters:
input
- non-null input stream- Returns:
- enum value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeEnum16
public static void writeEnum16(OutputStream output, int value) throws IOException
Write enum value into given output stream. Same aswriteInt16(OutputStream, int)
.- Parameters:
output
- non-null output streamvalue
- enum value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeEnum16
public static <T extends Enum<T>> void writeEnum16(OutputStream output, T value) throws IOException
Write enum value into given output stream.- Type Parameters:
T
- type of the value- Parameters:
output
- non-null output streamvalue
- enum value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readGeoPoint
public static double[] readGeoPoint(ClickHouseInputStream input) throws IOException
Read geo point(X and Y coordinates) from given input stream.- Parameters:
input
- non-null input stream- Returns:
- X and Y coordinates
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeGeoPoint
public static void writeGeoPoint(OutputStream output, double[] value) throws IOException
Write geo point(X and Y coordinates).- Parameters:
output
- non-null output streamvalue
- X and Y coordinates- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeGeoPoint
public static void writeGeoPoint(OutputStream output, double x, double y) throws IOException
Write geo point(X and Y coordinates).- Parameters:
output
- non-null output streamx
- X coordinatey
- Y coordinate- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readGeoRing
public static double[][] readGeoRing(ClickHouseInputStream input) throws IOException
Read geo ring(array of X and Y coordinates) from given input stream.- Parameters:
input
- non-null input stream- Returns:
- array of X and Y coordinates
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeGeoRing
public static void writeGeoRing(OutputStream output, double[][] value) throws IOException
Write geo ring(array of X and Y coordinates).- Parameters:
output
- non-null output streamvalue
- array of X and Y coordinates- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readGeoPolygon
public static double[][][] readGeoPolygon(ClickHouseInputStream input) throws IOException
Read geo polygon(array of rings) from given input stream.- Parameters:
input
- non-null input stream- Returns:
- array of rings
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeGeoPolygon
public static void writeGeoPolygon(OutputStream output, double[][][] value) throws IOException
Write geo polygon(array of rings).- Parameters:
output
- non-null output streamvalue
- array of rings- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readGeoMultiPolygon
public static double[][][][] readGeoMultiPolygon(ClickHouseInputStream input) throws IOException
Read geo multi-polygon(array of polygons) from given input stream.- Parameters:
input
- non-null input stream- Returns:
- array of polygons
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeGeoMultiPolygon
public static void writeGeoMultiPolygon(OutputStream output, double[][][][] value) throws IOException
Write geo polygon(array of rings).- Parameters:
output
- non-null output streamvalue
- array of polygons- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readNull
public static boolean readNull(ClickHouseInputStream input) throws IOException
Read null marker from input stream. Same asreadBoolean(ClickHouseInputStream)
.- Parameters:
input
- non-null input stream- Returns:
- true if it's null; false otherwise
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeNull
public static void writeNull(OutputStream output) throws IOException
Write null marker. Same aswriteBoolean(outut, true)
.- Parameters:
output
- non-null output stream- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeNonNull
public static void writeNonNull(OutputStream output) throws IOException
Write non-null marker. Same aswriteBoolean(outut, false)
.- Parameters:
output
- non-null output stream- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInet4Address
public static Inet4Address readInet4Address(ClickHouseInputStream input) throws IOException
Read Inet4Address from given input stream.- Parameters:
input
- non-null input stream- Returns:
- Inet4Address
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInet4Address
public static void writeInet4Address(OutputStream output, Inet4Address value) throws IOException
Write Inet4Address to given output stream.- Parameters:
output
- non-null output streamvalue
- Inet4Address- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInet6Address
public static Inet6Address readInet6Address(ClickHouseInputStream input) throws IOException
Read Inet6Address from given input stream.- Parameters:
input
- non-null input stream- Returns:
- Inet6Address
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInet6Address
public static void writeInet6Address(OutputStream output, Inet6Address value) throws IOException
Write Inet6Address to given output stream.- Parameters:
output
- non-null output streamvalue
- Inet6Address- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInt8
public static byte readInt8(ClickHouseInputStream input) throws IOException
Read a byte from given input stream. Same asClickHouseInputStream.readByte()
.- Parameters:
input
- non-null input stream- Returns:
- byte
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInt8
public static void writeInt8(OutputStream output, byte value) throws IOException
Write a byte to given output stream.- Parameters:
output
- non-null output streamvalue
- byte- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeInt8
public static void writeInt8(OutputStream output, int value) throws IOException
Write a byte to given output stream.- Parameters:
output
- non-null output streamvalue
- byte- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readUnsignedInt8
public static short readUnsignedInt8(ClickHouseInputStream input) throws IOException
Read an unsigned byte as short from given input stream.- Parameters:
input
- non-null input stream- Returns:
- unsigned byte
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeUnsignedInt8
public static void writeUnsignedInt8(OutputStream output, int value) throws IOException
Write an unsigned byte to given output stream.- Parameters:
output
- non-null output streamvalue
- unsigned byte- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInt16
public static short readInt16(ClickHouseInputStream input) throws IOException
Read a short value from given input stream.- Parameters:
input
- non-null input stream- Returns:
- short value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInt16
public static void writeInt16(OutputStream output, short value) throws IOException
Write a short value to given output stream.- Parameters:
output
- non-null output streamvalue
- short value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeInt16
public static void writeInt16(OutputStream output, int value) throws IOException
Write a short value to given output stream.- Parameters:
output
- non-null output streamvalue
- short value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readUnsignedInt16
public static int readUnsignedInt16(ClickHouseInputStream input) throws IOException
Read an unsigned short value from given input stream.- Parameters:
input
- non-null input stream- Returns:
- unsigned short value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeUnsignedInt16
public static void writeUnsignedInt16(OutputStream output, int value) throws IOException
Write an unsigned short value to given output stream.- Parameters:
output
- non-null output streamvalue
- unsigned short value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInt32
public static int readInt32(ClickHouseInputStream input) throws IOException
Read an integer from given input stream.- Parameters:
input
- non-null input stream- Returns:
- integer
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInt32
public static void writeInt32(OutputStream output, int value) throws IOException
Write an integer to given output stream.- Parameters:
output
- non-null output streamvalue
- integer- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readUnsignedInt32
public static long readUnsignedInt32(ClickHouseInputStream input) throws IOException
Read an unsigned integer from given input stream.- Parameters:
input
- non-null input stream- Returns:
- unsigned integer
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeUnsignedInt32
public static void writeUnsignedInt32(OutputStream output, long value) throws IOException
Write an unsigned integer to given output stream.- Parameters:
output
- non-null output streamvalue
- unsigned integer- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInt64
public static long readInt64(ClickHouseInputStream input) throws IOException
Read a long value from given input stream.- Parameters:
input
- non-null input stream- Returns:
- long value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInt64
public static void writeInt64(OutputStream output, long value) throws IOException
Write a long value 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
-
readUnsignedInt64
public static BigInteger readUnsignedInt64(ClickHouseInputStream input) throws IOException
Read an unsigned long value from given input stream.- Parameters:
input
- non-null input stream- Returns:
- unsigned long value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeUnsignedInt64
public static void writeUnsignedInt64(OutputStream output, long value) throws IOException
Write an unsigned long value to given output stream.- Parameters:
output
- non-null output streamvalue
- unsigned long value, negative number will be treated as positive- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeUnsignedInt64
public static void writeUnsignedInt64(OutputStream output, BigInteger value) throws IOException
Write an unsigned long value to given output stream. Due to overhead ofBigInteger
, this method in general uses more memory and slower thanwriteUnsignedInt64(OutputStream, long)
.- Parameters:
output
- non-null output streamvalue
- unsigned long value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInt128
public static BigInteger readInt128(ClickHouseInputStream input) throws IOException
Read a big integer(16 bytes) from given input stream.- Parameters:
input
- non-null input stream- Returns:
- big integer
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInt128
public static void writeInt128(OutputStream output, BigInteger value) throws IOException
Write a big integer(16 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- big integer- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readUnsignedInt128
public static BigInteger readUnsignedInt128(ClickHouseInputStream input) throws IOException
Read an unsigned big integer from given input stream.- Parameters:
input
- non-null input stream- Returns:
- unsigned big integer
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeUnsignedInt128
public static void writeUnsignedInt128(OutputStream output, BigInteger value) throws IOException
Write an unsigned big integer(16 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- unsigned big integer- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readInt256
public static BigInteger readInt256(ClickHouseInputStream input) throws IOException
Read a big integer(32 bytes) from given input stream.- Parameters:
input
- non-null input stream- Returns:
- big integer
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeInt256
public static void writeInt256(OutputStream output, BigInteger value) throws IOException
Write a big integer(32 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- big integer- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readUnsignedInt256
public static BigInteger readUnsignedInt256(ClickHouseInputStream input) throws IOException
Read an unsigned big integer(32 bytes) from given input stream.- Parameters:
input
- non-null input stream- Returns:
- big integer
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeUnsignedInt256
public static void writeUnsignedInt256(OutputStream output, BigInteger value) throws IOException
Write an unsigned big integer(32 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- unsigned big integer- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readFloat32
public static float readFloat32(ClickHouseInputStream input) throws IOException
Read a float value from given input stream.- Parameters:
input
- non-null input stream- Returns:
- float value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeFloat32
public static void writeFloat32(OutputStream output, float value) throws IOException
Write a float value to given output stream.- Parameters:
output
- non-null output streamvalue
- float value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readFloat64
public static double readFloat64(ClickHouseInputStream input) throws IOException
Read a double value from given input stream.- Parameters:
input
- non-null input stream- Returns:
- double value
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeFloat64
public static void writeFloat64(OutputStream output, double value) throws IOException
Write a double value to given output stream.- Parameters:
output
- non-null output streamvalue
- double value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readUuid
public static UUID readUuid(ClickHouseInputStream input) throws IOException
Read UUID from given input stream.- Parameters:
input
- non-null input stream- Returns:
- UUID
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeUuid
public static void writeUuid(OutputStream output, UUID value) throws IOException
Write a UUID to given output stream.- Parameters:
output
- non-null output streamvalue
- UUID- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeBigInteger
public static void writeBigInteger(OutputStream output, BigInteger value, int length) throws IOException
Write alength
-byte long big integer to given output stream.- Parameters:
output
- non-null output streamvalue
- big integerlength
- byte length of the value- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDecimal
public static BigDecimal readDecimal(ClickHouseInputStream input, int precision, int scale) throws IOException
Read big decimal(4 - 32 bytes) from given input stream.- Parameters:
input
- non-null input streamprecision
- precision of the decimalscale
- scale of the decimal- Returns:
- big decimal
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDecimal
public static void writeDecimal(OutputStream output, BigDecimal value, int precision, int scale) throws IOException
Write a big decimal(4 - 32 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- big decimalprecision
- precision of the decimalscale
- scale of the decimal, might be different fromBigDecimal.scale()
- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDecimal32
public static BigDecimal readDecimal32(ClickHouseInputStream input, int scale) throws IOException
Read big decimal(4 bytes) from given input stream.- Parameters:
input
- non-null input streamscale
- scale of the decimal- Returns:
- big decimal
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDecimal32
public static void writeDecimal32(OutputStream output, BigDecimal value, int scale) throws IOException
Write a big decimal(4 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- big decimalscale
- scale of the decimal, might be different fromBigDecimal.scale()
- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDecimal64
public static BigDecimal readDecimal64(ClickHouseInputStream input, int scale) throws IOException
Read big decimal(8 bytes) from gicen input stream.- Parameters:
input
- non-null input streamscale
- scale of the decimal- Returns:
- big decimal
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDecimal64
public static void writeDecimal64(OutputStream output, BigDecimal value, int scale) throws IOException
Write a big decimal(8 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- big decimalscale
- scale of the decimal, might be different fromBigDecimal.scale()
- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDecimal128
public static BigDecimal readDecimal128(ClickHouseInputStream input, int scale) throws IOException
Read big decimal(16 bytes) from given input stream.- Parameters:
input
- non-null input streamscale
- scale of the decimal- Returns:
- big decimal
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDecimal128
public static void writeDecimal128(OutputStream output, BigDecimal value, int scale) throws IOException
Write a big decimal(16 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- big decimalscale
- scale of the decimal, might be different fromBigDecimal.scale()
- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDecimal256
public static BigDecimal readDecimal256(ClickHouseInputStream input, int scale) throws IOException
Read big decimal from given input stream.- Parameters:
input
- non-null input streamscale
- scale of the decimal- Returns:
- big decimal
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDecimal256
public static void writeDecimal256(OutputStream output, BigDecimal value, int scale) throws IOException
Write a big decimal(32 bytes) to given output stream.- Parameters:
output
- non-null output streamvalue
- big decimalscale
- scale of the decimal, might be different fromBigDecimal.scale()
- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDate
public static LocalDate readDate(ClickHouseInputStream input, TimeZone tz) throws IOException
ReadLocalDate
from given input stream.- Parameters:
input
- non-null input streamtz
- time zone for date, could be null- Returns:
- local date
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
readDate
public static LocalDate readDate(ClickHouseInputStream input) throws IOException
ReadLocalDate
from given input stream.- Parameters:
input
- non-null input stream- Returns:
- local date
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDate
public static void writeDate(OutputStream output, LocalDate value, TimeZone tz) throws IOException
Write aLocalDate
to given output stream.- Parameters:
output
- non-null output streamvalue
- local datetz
- time zone for date, could be null- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeDate
public static void writeDate(OutputStream output, LocalDate value) throws IOException
Write aLocalDate
to given output stream.- Parameters:
output
- non-null output streamvalue
- local date- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDate32
public static LocalDate readDate32(ClickHouseInputStream input, TimeZone tz) throws IOException
ReadLocalDate
from given input stream.- Parameters:
input
- non-null input streamtz
- time zone for date, could be null- Returns:
- local date
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
readDate32
public static LocalDate readDate32(ClickHouseInputStream input) throws IOException
ReadLocalDate
from given input stream.- Parameters:
input
- non-null input stream- Returns:
- local date
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDate32
public static void writeDate32(OutputStream output, LocalDate value, TimeZone tz) throws IOException
Write aLocalDate
to given output stream.- Parameters:
output
- non-null output streamvalue
- local datetz
- time zone for date, could be null- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeDate32
public static void writeDate32(OutputStream output, LocalDate value) throws IOException
Write aLocalDate
to given output stream.- Parameters:
output
- non-null output streamvalue
- local date- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDateTime
public static LocalDateTime readDateTime(ClickHouseInputStream input, TimeZone tz) throws IOException
ReadLocalDateTime
from given input stream.- Parameters:
input
- non-null input streamtz
- time zone, null is treated as UTC- Returns:
- local datetime
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
readDateTime
public static LocalDateTime readDateTime(ClickHouseInputStream input, int scale, TimeZone tz) throws IOException
ReadLocalDateTime
from given input stream.- Parameters:
input
- non-null input streamscale
- scale of the datetime, must between 0 and 9 inclusivetz
- time zone, null is treated as UTC- Returns:
- local datetime
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDateTime
public static void writeDateTime(OutputStream output, LocalDateTime value, TimeZone tz) throws IOException
Write aLocalDateTime
to given output stream.- Parameters:
output
- non-null output streamvalue
- local datetimetz
- time zone, null is treated as UTC- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeDateTime
public static void writeDateTime(OutputStream output, LocalDateTime value, int scale, TimeZone tz) throws IOException
Write aLocalDateTime
to given output stream.- Parameters:
output
- non-null output streamvalue
- local datetimescale
- scale of the datetime, must between 0 and 9 inclusivetz
- time zone, null is treated as UTC- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDateTime32
public static LocalDateTime readDateTime32(ClickHouseInputStream input, TimeZone tz) throws IOException
ReadLocalDateTime
from given input stream.- Parameters:
input
- non-null input streamtz
- time zone, null is treated as UTC- Returns:
- local datetime
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDateTime32
public static void writeDateTime32(OutputStream output, LocalDateTime value, TimeZone tz) throws IOException
Write aLocalDateTime
to given output stream.- Parameters:
output
- non-null output streamvalue
- local datetimetz
- time zone, null is treated as UTC- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readDateTime64
public static LocalDateTime readDateTime64(ClickHouseInputStream input, TimeZone tz) throws IOException
ReadLocalDateTime
from given input stream. Same asreadDateTime64(input, 3)
.- Parameters:
input
- non-null input streamtz
- time zone, null is treated as UTC- Returns:
- local datetime
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
readDateTime64
public static LocalDateTime readDateTime64(ClickHouseInputStream input, int scale, TimeZone tz) throws IOException
ReadLocalDateTime
from given input stream.- Parameters:
input
- non-null input streamscale
- scale of the datetimetz
- time zone, null is treated as UTC- Returns:
- local datetime
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeDateTime64
public static void writeDateTime64(OutputStream output, LocalDateTime value, TimeZone tz) throws IOException
Write aLocalDateTime
to given output stream. Same aswriteDateTime64(output, value, 3)
.- Parameters:
output
- non-null output streamvalue
- local datetimetz
- time zone, null is treated as UTC- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeDateTime64
public static void writeDateTime64(OutputStream output, LocalDateTime value, int scale, TimeZone tz) throws IOException
Write aLocalDateTime
to given output stream.- Parameters:
output
- non-null output streamvalue
- local datetimescale
- scale of the datetime, must between 0 and 9 inclusivetz
- time zone, null is treated as UTC- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readFixedString
public static String readFixedString(ClickHouseInputStream input, int length) throws IOException
Read string with fixed length from given input stream.- Parameters:
input
- non-null input streamlength
- byte length of the string- Returns:
- string with fixed length
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
readFixedString
public static String readFixedString(ClickHouseInputStream input, int length, Charset charset) throws IOException
Read string with fixed length from given input stream.- Parameters:
input
- non-null input streamlength
- byte length of the stringcharset
- charset used to convert string to byte array, null means UTF-8- Returns:
- string with fixed length
- Throws:
IOException
- when failed to read value from input stream or reached end of the stream
-
writeFixedString
public static void writeFixedString(OutputStream output, String value, int length) throws IOException
Write a string with fixed length to given output stream.- Parameters:
output
- non-null output streamvalue
- stringlength
- byte length of the string- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeFixedString
public static void writeFixedString(OutputStream output, String value, int length, Charset charset) throws IOException
Write a string with fixed length to given output stream.- Parameters:
output
- non-null output streamvalue
- stringlength
- byte length of the stringcharset
- charset used to convert string to byte array, null means UTF-8- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readString
public static String readString(Reader input, int length) throws IOException
Reads characters from given reader.- Parameters:
input
- non-null readerlength
- length in character- Returns:
- string value
- Throws:
IOException
- when failed to read value from reader or reached end of the stream
-
writeString
public static void writeString(OutputStream output, String value) throws IOException
Write a string to given output stream.- Parameters:
output
- non-null output streamvalue
- string- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeString
public static void writeString(OutputStream output, String value, Charset charset) throws IOException
Write a string to given output stream.- Parameters:
output
- non-null output streamvalue
- stringcharset
- charset used to convert string to byte array, null means UTF-8- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
writeString
public static void writeString(OutputStream output, byte[] value) throws IOException
Writes a binary string to given output stream.- Parameters:
output
- non-null output streamvalue
- non-null byte array- Throws:
IOException
- when failed to write value to output stream or reached end of the stream
-
readVarInt
public static int readVarInt(InputStream input) throws IOException
Read 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
-
readVarInt
public static int readVarInt(ByteBuffer buffer)
Read varint from given byte buffer.- Parameters:
buffer
- non-null byte buffer- Returns:
- varint
-
writeVarInt
public static void writeVarInt(OutputStream output, long value) throws IOException
Write 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
-
writeVarInt
public static void writeVarInt(ByteBuffer buffer, int value)
Write varint to given output stream.- Parameters:
buffer
- non-null byte buffervalue
- integer value
-
-