Class ClickHouseOutputStream

    • Constructor Detail

      • ClickHouseOutputStream

        protected ClickHouseOutputStream​(ClickHouseFile file,
                                         Runnable postCloseAction)
    • Method Detail

      • empty

        public static ClickHouseOutputStream empty()
        Gets an empty output stream that consumes nothing and cannot be closed.
        Returns:
        empty output stream
      • of

        public static ClickHouseOutputStream of​(ClickHouseFile file,
                                                int bufferSize,
                                                Runnable postCloseAction)
        Wraps the given file as output stream.
        Parameters:
        file - non-null file
        postCloseAction - custom action will be performed right after closing the output stream
        bufferSize - buffer size which is always greater than zero(usually 8192 or larger)
        Returns:
        wrapped output
      • of

        public static ClickHouseOutputStream of​(OutputStream output,
                                                int bufferSize)
        Wraps the given output stream.
        Parameters:
        output - output stream
        bufferSize - buffer size which is always greater than zero(usually 8192 or larger)
        Returns:
        wrapped output, or the same output if it's instance of ClickHouseOutputStream
      • of

        public static ClickHouseOutputStream of​(OutputStream output,
                                                int bufferSize,
                                                ClickHouseCompression compression,
                                                Runnable postCloseAction)
        Wraps the given output stream.
        Parameters:
        output - output stream
        bufferSize - buffer size which is always greater than zero(usually 8192 or larger)
        compression - compression algorithm, null or ClickHouseCompression.NONE means no compression
        postCloseAction - custom action will be performed right after closing the output stream
        Returns:
        wrapped output, or the same output if it's instance of ClickHouseOutputStream
      • getUnderlyingFile

        public ClickHouseFile getUnderlyingFile()
        Gets underlying file.
        Returns:
        non-null underlying file
      • transferBytes

        public final ClickHouseOutputStream transferBytes​(byte[] bytes)
                                                   throws IOException
        Transfers bytes into output stream without creating a copy.
        Parameters:
        bytes - non-null byte array
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • transferBytes

        public ClickHouseOutputStream transferBytes​(ByteBuffer buffer,
                                                    int length)
                                             throws IOException
        Transfer bytes into output stream without creating a copy.
        Parameters:
        buffer - non-null byte buffer
        length - bytes to write
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • transferBytes

        public abstract ClickHouseOutputStream transferBytes​(byte[] bytes,
                                                             int offset,
                                                             int length)
                                                      throws IOException
        Transfers the given bytes into output stream, without creating a copy as in writeBytes(byte[], int, int).
        Parameters:
        bytes - non-null byte array
        offset - offset of the byte array
        length - bytes to write
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • isClosed

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

        public abstract ClickHouseOutputStream writeByte​(byte b)
                                                  throws IOException
        Writes a single byte into output stream.
        Parameters:
        b - byte to write
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeBytes

        public ClickHouseOutputStream writeBytes​(ByteBuffer buffer,
                                                 int length)
                                          throws IOException
        Writes bytes into output stream.
        Parameters:
        buffer - non-null byte buffer
        length - bytes to write
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeBytes

        public final ClickHouseOutputStream writeBytes​(byte[] bytes)
                                                throws IOException
        Writes bytes into output stream.
        Parameters:
        bytes - non-null byte array
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeBytes

        public abstract ClickHouseOutputStream writeBytes​(byte[] bytes,
                                                          int offset,
                                                          int length)
                                                   throws IOException
        Writes copy of given bytes into output stream.
        Parameters:
        bytes - non-null byte array
        offset - offset of the byte array
        length - bytes to write
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeBuffer

        public ClickHouseOutputStream writeBuffer​(ClickHouseByteBuffer buffer)
                                           throws IOException
        Writes bytes into output stream.
        Parameters:
        buffer - wrapped byte array with offset and limit
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeCustom

        public abstract ClickHouseOutputStream writeCustom​(ClickHouseDataUpdater writer)
                                                    throws IOException
        Writes bytes using custom writer.
        Parameters:
        writer - non-null data writer
        Returns:
        current output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeString

        public ClickHouseOutputStream writeString​(String value,
                                                  Charset charset)
                                           throws IOException
        Writes string into the output stream. Nothing will happen when value is null or empty.
        Parameters:
        value - string to write
        charset - charset, null is treated as StandardCharsets.UTF_8
        Returns:
        this output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeAsciiString

        public ClickHouseOutputStream writeAsciiString​(String value)
                                                throws IOException
        Writes ascii string into output stream. writeVarInt(int) will be called automatically before writing the string.
        Parameters:
        value - ascii string to write
        Returns:
        this output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeUnicodeString

        public ClickHouseOutputStream writeUnicodeString​(String value)
                                                  throws IOException
        Writes unicode string into output stream. writeVarInt(int) will be called automatically before writing the string.
        Parameters:
        value - unicode string to write
        Returns:
        this output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeVarInt

        public ClickHouseOutputStream writeVarInt​(int value)
                                           throws IOException
        Writes varint into output stream.
        Parameters:
        value - varint
        Returns:
        this output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream
      • writeUnsignedVarInt

        public ClickHouseOutputStream writeUnsignedVarInt​(long value)
                                                   throws IOException
        Writes varint into output stream.
        Parameters:
        value - varint
        Returns:
        this output stream
        Throws:
        IOException - when failed to write value into output stream, not able to sent all bytes, or opereate on a closed stream