Class ClickHouseInputStream

    • Field Detail

      • EMPTY_BYTES

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

        @Deprecated
        public static final ByteBuffer EMPTY_BUFFER
        Deprecated.
        Empty and read-only byte buffer.
      • afterClose

        protected final Runnable afterClose
      • closed

        protected boolean closed
    • Constructor Detail

      • ClickHouseInputStream

        protected ClickHouseInputStream​(Runnable afterClose)
    • Method Detail

      • of

        public static ClickHouseInputStream of​(BlockingQueue<ByteBuffer> queue,
                                               int timeout)
        Wraps the given blocking queue.
        Parameters:
        queue - non-null blocking queue
        timeout - read timeout in milliseconds
        Returns:
        wrapped input
      • of

        public static ClickHouseInputStream of​(BlockingQueue<ByteBuffer> queue,
                                               int timeout,
                                               Runnable afterClose)
        Wraps the given blocking queue.
        Parameters:
        queue - non-null blocking queue
        timeout - read timeout in milliseconds
        afterClose - custom handler will be invoked right after closing the input stream
        Returns:
        wrapped input
      • of

        public static ClickHouseInputStream of​(InputStream input,
                                               int bufferSize)
        Wraps the given input stream.
        Parameters:
        input - non-null input stream
        bufferSize - buffer size which is always greater than zero(usually 4096 or larger)
        Returns:
        wrapped input, or the same input if it's instance of ClickHouseInputStream
      • of

        public static ClickHouseInputStream of​(InputStream input,
                                               int bufferSize,
                                               Runnable afterClose)
        Wraps the given input stream.
        Parameters:
        input - non-null input stream
        bufferSize - buffer size which is always greater than zero(usually 4096 or larger)
        afterClose - custom handler will be invoked right after closing the input stream
        Returns:
        wrapped input, or the same input if it's instance of ClickHouseInputStream
      • closeQuietly

        protected void closeQuietly()
      • peek

        public abstract int peek()
                          throws IOException
        Peeks one byte. It's similar as InputStream.read() except it never changes cursor.
        Returns:
        the next byte of data, or -1 if the end of the stream is reached
        Throws:
        IOException - when failed to read value from input stream or reached end of the stream
      • pipe

        public abstract long pipe​(ClickHouseOutputStream output)
                           throws IOException
        Reads all bytes and write into given output stream.
        Parameters:
        output - non-null output stream
        Returns:
        bytes being written into output stream
        Throws:
        IOException - when failed to read value from input stream or reached end of the stream
      • readUnsignedByte

        public int readUnsignedByte()
                             throws IOException
        Reads an unsigned byte from the input stream. Unlike InputStream.read(), it will throw IOException if the input stream has been closed.
        Returns:
        unsigned byte
        Throws:
        IOException - when failed to read value from input stream or reached end of the stream
      • readByte

        public abstract byte readByte()
                               throws IOException
        Reads one single byte from the input stream. Unlike InputStream.read(), it will throw IOException if the input stream has been closed. In general, this method should be faster than InputStream.read(), especially when it's an input stream backed by byte[] or ByteBuffer.
        Returns:
        byte value if present
        Throws:
        IOException - when failed to read value from input stream or reached end of the stream
      • readBytes

        public byte[] readBytes​(int length)
                         throws IOException
        Reads length bytes from the input stream. It behaves in the same way as DataInput.readFully(byte[]), except it will throw IOException when the input stream has been closed.
        Parameters:
        length - number of bytes to read
        Returns:
        byte 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
      • readString

        public String readString​(Charset charset)
                          throws IOException
        Reads string from the input stream. readVarInt() will be called automatically to understand byte length of the string.
        Parameters:
        charset - charset, null is treated as StandardCharsets.UTF_8
        Returns:
        non-null string
        Throws:
        IOException - when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
      • readString

        public String readString​(int byteLength,
                                 Charset charset)
                          throws IOException
        Reads string from the input stream. When byteLength is zero or negative number, this method will always return empty string.
        Parameters:
        byteLength - length in byte
        charset - charset, null is treated as StandardCharsets.UTF_8
        Returns:
        non-null string
        Throws:
        IOException - when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
      • readAsciiString

        public String readAsciiString()
                               throws IOException
        Reads ascii string from input stream. readVarInt() will be called automatically to understand byte length of the string.
        Returns:
        non-null ascii string
        Throws:
        IOException - when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
      • readAsciiString

        public String readAsciiString​(int byteLength)
                               throws IOException
        Reads ascii string from input stream. Similar as readString(byteLength, StandardCharsets.US_ASCII).
        Parameters:
        byteLength - length in byte
        Returns:
        non-null ascii string
        Throws:
        IOException - when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
      • readUnicodeString

        public String readUnicodeString()
                                 throws IOException
        Reads unicode string from input stream.
        Returns:
        non-null unicode string
        Throws:
        IOException - when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
      • readUnicodeString

        public String readUnicodeString​(int byteLength)
                                 throws IOException
        Reads unicode string from input stream. Similar as readString(byteLength, null).
        Parameters:
        byteLength - length in byte
        Returns:
        non-null unicode string
        Throws:
        IOException - when failed to read value from input stream, not able to retrieve all bytes, or reached end of the stream
      • readVarInt

        public int readVarInt()
                       throws IOException
        Read varint from input stream.
        Returns:
        varint
        Throws:
        IOException - when failed to read value from input stream or reached end of the stream
      • isClosed

        public boolean isClosed()
        Checks if the input stream has been closed or not.
        Returns:
        true if the input stream has been closed; false otherwise