Package ru.yandex.clickhouse.response
Class FastByteArrayOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- ru.yandex.clickhouse.response.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 voidclose()Closing aByteArrayOutputStreamhas no effect.FastByteArrayInputStreamconvertToInputStream()Creates InputStream using the same data that is written into this stream with no copying in memoryvoidcopyFrom(FastByteArrayInputStream source, int offset, int count)Copies data from input streamvoidcopyTo(DataOutput dest)voidcopyTo(OutputStream dest)byte[]getBuffer()voidreset()intsize()Returns the current size of the buffer.byte[]toByteArray()returns inner arrayByteBuffertoByteBuffer()voidwrite(byte[] b, int off, int len)Writeslenbytes from the specified byte array starting at offsetoffto this byte array output stream.voidwrite(int b)Writes the specified byte to this byte array output stream.voidwriteTo(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:
writein classOutputStream- Parameters:
b- the byte to be written.
-
write
public void write(byte[] b, int off, int len)Writeslenbytes from the specified byte array starting at offsetoffto this byte array output stream.- Overrides:
writein 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
countfield, which is the number of valid bytes in this output stream.
-
close
public void close() throws IOExceptionClosing aByteArrayOutputStreamhas no effect. The methods in this class can be called after the stream has been closed without generating anIOException.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein 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()
-
-