Package com.clickhouse.client.data.tsv
Class FastByteArrayOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.clickhouse.client.data.tsv.FastByteArrayOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public final class FastByteArrayOutputStream extends OutputStream
Not synchronized quick version ofByteArrayOutputStream
-
-
Constructor Summary
Constructors Constructor Description FastByteArrayOutputStream()
Creates a new byte array output stream.FastByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closing aByteArrayOutputStream
has no effect.FastByteArrayInputStream
convertToInputStream()
Creates InputStream using the same data that is written into this stream with no copying in memoryvoid
copyFrom(FastByteArrayInputStream source, int offset, int count)
Copies data from input streamvoid
copyTo(DataOutput dest)
void
copyTo(OutputStream dest)
byte[]
getBuffer()
void
reset()
int
size()
Returns the current size of the buffer.byte[]
toByteArray()
returns inner arrayByteBuffer
toByteBuffer()
void
write(byte[] b, int off, int len)
Writeslen
bytes from the specified byte array starting at offsetoff
to this byte array output stream.void
write(int b)
Writes the specified byte to this byte array output stream.void
writeTo(OutputStream output)
-
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
-
-
-
Constructor Detail
-
FastByteArrayOutputStream
public FastByteArrayOutputStream()
Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if necessary.
-
FastByteArrayOutputStream
public FastByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.- Parameters:
size
- the initial size.- Throws:
IllegalArgumentException
- if size is negative.
-
-
Method Detail
-
write
public void write(int b)
Writes the specified byte to this byte array output stream.- Specified by:
write
in classOutputStream
- Parameters:
b
- the byte to be written.
-
write
public void write(byte[] b, int off, int len)
Writeslen
bytes from the specified byte array starting at offsetoff
to this byte array output stream.- Overrides:
write
in classOutputStream
- Parameters:
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.
-
toByteArray
public byte[] toByteArray()
returns inner array- Returns:
- the current contents of this output stream, as a byte array.
-
writeTo
public void writeTo(OutputStream output) throws IOException
- Throws:
IOException
-
size
public int size()
Returns the current size of the buffer.- Returns:
- the value of the
count
field, which is the number of valid bytes in this output stream.
-
close
public void close() throws IOException
Closing aByteArrayOutputStream
has no effect. The methods in this class can be called after the stream has been closed without generating anIOException
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
copyFrom
public void copyFrom(FastByteArrayInputStream source, int offset, int count)
Copies data from input stream- Parameters:
source
- source streamoffset
- offset in the sourcecount
- number of bytes to copy
-
copyTo
public void copyTo(OutputStream dest) throws IOException
- Throws:
IOException
-
copyTo
public void copyTo(DataOutput dest) throws IOException
- Throws:
IOException
-
convertToInputStream
public FastByteArrayInputStream convertToInputStream()
Creates InputStream using the same data that is written into this stream with no copying in memory- Returns:
- a input stream contained all bytes recorded in a current stream
-
toByteBuffer
public ByteBuffer toByteBuffer()
-
getBuffer
public byte[] getBuffer()
-
reset
public void reset()
-
-