Class BinaryStreamReader
java.lang.Object
com.clickhouse.client.api.data_formats.internal.BinaryStreamReader
This class is not thread safe and should not be shared between multiple threads.
Internally it may use a shared buffer to read data from the input stream.
It is done mainly to reduce extra memory allocations for reading numbers.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfacestatic classByte allocator that caches preallocated byte arrays for small sizes.static classByte allocator that creates a new byte array for each request.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int[]Bases for datetime64.static final intstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisReadToPrimitive(ClickHouseDataType dataType) readArray(ClickHouseColumn column) Reads a array into an ArrayValue object.readArrayItem(ClickHouseColumn itemTypeColumn, int len) readBigIntegerLE(int len, boolean unsigned) Reads a big integer value in little-endian from the internal input stream.static BigIntegerreadBigIntegerLE(InputStream input, byte[] buff, int len, boolean unsigned) Reads a little-endian big integer from input stream.bytereadByte()Read byte from the internal input stream.static intreadByteOrEOF(InputStream input) static ZonedDateTimereadDate(InputStream input, byte[] buff, TimeZone tz) Reads a date from input stream.static ZonedDateTimereadDate32(InputStream input, byte[] buff, TimeZone tz) Reads a date32 from input stream.readDate32(TimeZone tz) Reads a Date32 value from internal input stream.static ZonedDateTimereadDateTime32(InputStream input, byte[] buff, TimeZone tz) Reads a datetime32 from input stream.readDateTime64(int scale, TimeZone tz) Reads a datetime64 from internal input stream.static ZonedDateTimereadDateTime64(InputStream input, byte[] buff, int scale, TimeZone tz) Reads a datetime64 from input stream.readDecimal(int precision, int scale) Reads a decimal value from the internal input stream.doubleReads a double value from the internal input stream.floatReads a decimal value from the internal input stream.double[]Reads a GEO point as an array of two doubles what represents coordinates (X, Y).double[][][]Reads a GEO polygon as an array of rings.double[][]Reads a GEO ring as an array of points.intReads an int value in little-endian from the internal input stream.static intreadIntLE(InputStream input, byte[] buff) Reads a little-endian int from input stream.longReads a long value in little-endian from the internal input stream.static longreadLongLE(InputStream input, byte[] buff) Reads a little-endian long from input stream.Map<?,?> readMap(ClickHouseColumn column) Reads a map.static byte[]readNBytes(InputStream inputStream, byte[] buffer, int offset, int len) Readslenbytes from input stream to buffer.static byte[]readNBytes(InputStream inputStream, int len) static byte[]readNBytesLE(InputStream input, byte[] buffer, int offset, int len) Readslenbytes from input stream to buffer in little-endian order.shortRead a short value in little-endian from the internal input stream.static shortreadShortLE(InputStream input, byte[] buff) Reads a little-endian short from input stream.static StringreadString(InputStream input) Reads a decimal value from input stream.Object[]readTuple(ClickHouseColumn column) Reads a tuple.shortReads an unsigned byte value from the internal input stream.longReads an unsigned int value in little-endian from the internal input stream.static longreadUnsignedIntLE(InputStream input, byte[] buff) Reads a little-endian unsigned int from input stream.intReads an unsigned short value from the internal input stream.static intreadUnsignedShortLE(InputStream input, byte[] buff) Reads a little-endian unsigned short from input stream.<T> TreadValue(ClickHouseColumn column) Reads a value from the internal input stream.<T> TreadValue(ClickHouseColumn column, Class<?> typeHint) Reads a value from the internal input stream.readVariant(ClickHouseColumn column) static intreadVarInt(InputStream input) Reads a varint from input stream.voidskipValue(ClickHouseColumn column)
-
Field Details
-
INT16_SIZE
public static final int INT16_SIZE- See Also:
-
INT32_SIZE
public static final int INT32_SIZE- See Also:
-
INT64_SIZE
public static final int INT64_SIZE- See Also:
-
INT128_SIZE
public static final int INT128_SIZE- See Also:
-
INT256_SIZE
public static final int INT256_SIZE- See Also:
-
BASES
public static final int[] BASESBases for datetime64.
-
-
Method Details
-
readValue
Reads a value from the internal input stream.- Type Parameters:
T- - target type of the value- Parameters:
column- - column information- Returns:
- value
- Throws:
IOException- when IO error occurs
-
readValue
Reads a value from the internal input stream. Method will use type hint to do smarter conversion if possible. For example, all datetime values are ofZonedDateTime; if a type hint isLocalDateTimethenZonedDateTime.toLocalDateTime().- Type Parameters:
T- - target type of the value- Parameters:
column- - column informationtypeHint- - type hint- Returns:
- value
- Throws:
IOException- when IO error occurs
-
readShortLE
Read a short value in little-endian from the internal input stream.- Returns:
- short value
- Throws:
IOException- when IO error occurs
-
readShortLE
Reads a little-endian short from input stream. Uses buff to receive data from the input stream.- Parameters:
input- - source of bytesbuff- - buffer to store data- Returns:
- short value
- Throws:
IOException- when IO error occurs
-
readIntLE
Reads an int value in little-endian from the internal input stream.- Returns:
- int value
- Throws:
IOException- when IO error occurs
-
readIntLE
Reads a little-endian int from input stream. Uses buff to receive data from the input stream.- Parameters:
input- - source of bytesbuff- - buffer to store data- Returns:
- - int value
- Throws:
IOException- when IO error occurs
-
readLongLE
Reads a long value in little-endian from the internal input stream.- Returns:
- long value
- Throws:
IOException- when IO error occurs
-
readLongLE
Reads a little-endian long from input stream. Uses buff to receive data from the input stream.- Parameters:
input- - source of bytesbuff- - buffer to store data- Returns:
- - long value
- Throws:
IOException- when IO error occurs
-
readByte
Read byte from the internal input stream.- Returns:
- byte value
- Throws:
IOException- when IO error occurs
-
readUnsignedByte
Reads an unsigned byte value from the internal input stream.- Returns:
- unsigned byte value
- Throws:
IOException- when IO error occurs
-
readUnsignedShortLE
Reads an unsigned short value from the internal input stream.- Returns:
- unsigned short value
- Throws:
IOException- when IO error occurs
-
readUnsignedShortLE
Reads a little-endian unsigned short from input stream. Uses buff to receive data from the input stream.- Parameters:
input- - source of bytesbuff- - buffer to store data- Returns:
- - unsigned short value
- Throws:
IOException
-
readUnsignedIntLE
Reads an unsigned int value in little-endian from the internal input stream.- Returns:
- unsigned int value
- Throws:
IOException- when IO error occurs
-
readUnsignedIntLE
Reads a little-endian unsigned int from input stream. Uses buff to receive data from the input stream.- Parameters:
input- - source of bytesbuff- - buffer to store data- Returns:
- - unsigned int value
- Throws:
IOException- when IO error occurs
-
readBigIntegerLE
Reads a big integer value in little-endian from the internal input stream.- Parameters:
len- - number of bytes to readunsigned- - whether the value is unsigned- Returns:
- big integer value
- Throws:
IOException- when IO error occurs
-
readBigIntegerLE
public static BigInteger readBigIntegerLE(InputStream input, byte[] buff, int len, boolean unsigned) throws IOException Reads a little-endian big integer from input stream. Uses buff to receive data from the input stream.- Parameters:
input- - source of bytesbuff- - buffer to store datalen- - number of bytes to readunsigned- - whether the value is unsigned- Returns:
- - big integer value
- Throws:
IOException
-
readFloatLE
Reads a decimal value from the internal input stream.- Returns:
- decimal value
- Throws:
IOException- when IO error occurs
-
readDoubleLE
Reads a double value from the internal input stream.- Returns:
- double value
- Throws:
IOException- when IO error occurs
-
readDecimal
Reads a decimal value from the internal input stream.- Parameters:
precision- - precision of the decimal valuescale- - scale of the decimal value- Returns:
- decimal value
- Throws:
IOException- when IO error occurs
-
readNBytes
- Throws:
IOException
-
readNBytes
public static byte[] readNBytes(InputStream inputStream, byte[] buffer, int offset, int len) throws IOException Readslenbytes from input stream to buffer.- Parameters:
inputStream- - source of bytesbuffer- - target bufferoffset- - target buffer offsetlen- - number of bytes to read- Returns:
- target buffer
- Throws:
IOException
-
readNBytesLE
public static byte[] readNBytesLE(InputStream input, byte[] buffer, int offset, int len) throws IOException Readslenbytes from input stream to buffer in little-endian order.- Parameters:
input- - source of bytesbuffer- - target bufferoffset- - target buffer offsetlen- - number of bytes to read- Returns:
- - target buffer
- Throws:
IOException
-
readArray
Reads a array into an ArrayValue object.- Parameters:
column- - column information- Returns:
- array value
- Throws:
IOException- when IO error occurs
-
readArrayItem
public BinaryStreamReader.ArrayValue readArrayItem(ClickHouseColumn itemTypeColumn, int len) throws IOException - Throws:
IOException
-
skipValue
- Throws:
IOException
-
readMap
Reads a map.- Parameters:
column- - column information- Returns:
- a map
- Throws:
IOException- when IO error occurs
-
readTuple
Reads a tuple.- Parameters:
column- - column information- Returns:
- a tuple
- Throws:
IOException- when IO error occurs
-
readVariant
- Throws:
IOException
-
readGeoPoint
Reads a GEO point as an array of two doubles what represents coordinates (X, Y).- Returns:
- X, Y coordinates
- Throws:
IOException- when IO error occurs
-
readGeoRing
Reads a GEO ring as an array of points.- Returns:
- array of points
- Throws:
IOException- when IO error occurs
-
readGeoPolygon
Reads a GEO polygon as an array of rings.- Returns:
- polygon
- Throws:
IOException- when IO error occurs
-
readVarInt
Reads a varint from input stream.- Returns:
- varint
- Throws:
IOException- when failed to read value from input stream or reached end of the stream
-
readDate
public static ZonedDateTime readDate(InputStream input, byte[] buff, TimeZone tz) throws IOException Reads a date from input stream.- Parameters:
input- - source of bytesbuff- - for reading short value. Should be 2 bytes.tz- - timezone- Returns:
- ZonedDateTime
- Throws:
IOException- when IO error occurs
-
readDate32
Reads a Date32 value from internal input stream.- Parameters:
tz- - timezone- Returns:
- ZonedDateTime
- Throws:
IOException- when IO error occurs
-
readDate32
public static ZonedDateTime readDate32(InputStream input, byte[] buff, TimeZone tz) throws IOException Reads a date32 from input stream.- Parameters:
input- - source of bytesbuff- - for reading int value. Should be 4 bytes.tz- - timezone- Returns:
- ZonedDateTime
- Throws:
IOException- when IO error occurs
-
readDateTime32
public static ZonedDateTime readDateTime32(InputStream input, byte[] buff, TimeZone tz) throws IOException Reads a datetime32 from input stream.- Parameters:
input- - source of bytesbuff- - for reading int value. Should be 4 bytes.tz- - timezone- Returns:
- ZonedDateTime
- Throws:
IOException- when IO error occurs
-
readDateTime64
Reads a datetime64 from internal input stream.- Parameters:
scale- - scale of the datetime64tz- - timezone- Returns:
- ZonedDateTime
- Throws:
IOException- when IO error occurs
-
readDateTime64
public static ZonedDateTime readDateTime64(InputStream input, byte[] buff, int scale, TimeZone tz) throws IOException Reads a datetime64 from input stream.- Parameters:
input- - source of bytesbuff- - for reading long value. Should be 8 bytes.scale- - scale of the datetime64tz- - timezone- Returns:
- Throws:
IOException
-
readString
Reads a decimal value from input stream.- Parameters:
input- - source of bytes- Returns:
- String
- Throws:
IOException- when IO error occurs
-
readByteOrEOF
- Throws:
IOException
-
isReadToPrimitive
-