Package com.clickhouse.client.stream
Class AbstractByteBufferInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.clickhouse.client.ClickHouseInputStream
-
- com.clickhouse.client.stream.AbstractByteBufferInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
BlockingInputStream,IterableByteBufferInputStream
public abstract class AbstractByteBufferInputStream extends ClickHouseInputStream
ByteBufferbacked input stream.
-
-
Field Summary
Fields Modifier and Type Field Description protected ByteBufferbuffer-
Fields inherited from class com.clickhouse.client.ClickHouseInputStream
byteBuffer, closed, copyTo, EMPTY_BUFFER, EMPTY_BYTES, ERROR_INCOMPLETE_READ, ERROR_NULL_BYTES, ERROR_REUSE_BUFFER, ERROR_STREAM_CLOSED, file, postCloseAction
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractByteBufferInputStream(ClickHouseFile file, OutputStream copyTo, Runnable postCloseAction)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()protected voidensureOpen()Checks whether the input stream has been closed and throw an exception if it is.intpeek()Peeks one byte.longpipe(ClickHouseOutputStream output)Reads all remaining bytes and write into given output stream.intread()intread(byte[] b, int off, int len)ClickHouseByteBufferreadBuffer(int length)Reads byte buffer from the input stream.bytereadByte()Reads one single byte from the input stream.byte[]readBytes(int length)Readslengthbytes from the input stream.ClickHouseByteBufferreadCustom(ClickHouseDataUpdater reader)Reads bytes using custom reader.longskip(long n)protected abstract intupdateBuffer()Update inner buffer as needed.-
Methods inherited from class com.clickhouse.client.ClickHouseInputStream
closeQuietly, empty, getUnderlyingFile, isClosed, of, of, of, of, of, of, of, of, of, of, of, of, of, of, of, of, pipe, pipe, readAsciiString, readAsciiString, readString, readString, readUnicodeString, readUnicodeString, readUnsignedByte, readVarInt, readVarLong, save, save, setCopyToTarget, wrap
-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, transferTo
-
-
-
-
Field Detail
-
buffer
protected ByteBuffer buffer
-
-
Constructor Detail
-
AbstractByteBufferInputStream
protected AbstractByteBufferInputStream(ClickHouseFile file, OutputStream copyTo, Runnable postCloseAction)
-
-
Method Detail
-
ensureOpen
protected void ensureOpen() throws IOExceptionDescription copied from class:ClickHouseInputStreamChecks whether the input stream has been closed and throw an exception if it is.- Overrides:
ensureOpenin classClickHouseInputStream- Throws:
IOException- when the input stream has been closed
-
updateBuffer
protected abstract int updateBuffer() throws IOExceptionUpdate inner buffer as needed.- Returns:
- remaining bytes in buffer
- Throws:
IOException- when failed to update buffer
-
available
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classClickHouseInputStream- Throws:
IOException
-
peek
public int peek() throws IOExceptionDescription copied from class:ClickHouseInputStreamPeeks one byte. It's similar asInputStream.read()except it never changes cursor.- Specified by:
peekin classClickHouseInputStream- 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 long pipe(ClickHouseOutputStream output) throws IOException
Description copied from class:ClickHouseInputStreamReads all remaining bytes and write into given output stream. Current input stream will be closed automatically at the end of writing, butoutputwill remain open.- Specified by:
pipein classClickHouseInputStream- 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
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
readBuffer
public ClickHouseByteBuffer readBuffer(int length) throws IOException
Description copied from class:ClickHouseInputStreamReads byte buffer from the input stream.- Overrides:
readBufferin classClickHouseInputStream- Parameters:
length- byte length- Returns:
- non-null byte buffer
- Throws:
IOException- when failed to read bytes from input stream, not able to retrieve all bytes, or reached end of the stream
-
readCustom
public ClickHouseByteBuffer readCustom(ClickHouseDataUpdater reader) throws IOException
Description copied from class:ClickHouseInputStreamReads bytes using custom reader. Stream will be closed automatically when it reached end of stream. However, unlikeClickHouseInputStream.readBuffer(int), this method will never throwEOFException.- Specified by:
readCustomin classClickHouseInputStream- Parameters:
reader- non-null data reader- Returns:
- non-null byte buffer
- Throws:
IOException- when failed to read bytes from input stream, not able to retrieve all bytes, or reached end of the stream
-
readByte
public byte readByte() throws IOExceptionDescription copied from class:ClickHouseInputStreamReads one single byte from the input stream. UnlikeInputStream.read(), it will throwIOExceptionif the input stream has been closed. In general, this method should be faster thanInputStream.read(), especially when it's an input stream backed by byte[] orByteBuffer.- Specified by:
readBytein classClickHouseInputStream- 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 IOExceptionDescription copied from class:ClickHouseInputStreamReadslengthbytes from the input stream. It behaves in the same way asDataInput.readFully(byte[]), except it will throwIOExceptionwhen the input stream has been closed.- Overrides:
readBytesin classClickHouseInputStream- 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
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
-