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 of `ByteArrayOutputStream`

### Constructor Summary

Constructors
`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
`void` `close()` Closing a `ByteArrayOutputStream` has no effect.
`FastByteArrayInputStream` `convertToInputStream()` Creates InputStream using the same data that is written into this stream with no copying in memory
`void` `copyFrom​(FastByteArrayInputStream source, int offset, int count)` Copies data from input stream
`void` `copyTo​(DataOutput dest)`
`void` `copyTo​(OutputStream dest)`
`byte[]` `getBuffer()`
`void` `reset()`
`int` `size()` Returns the current size of the buffer.
`byte[]` `toByteArray()` returns inner array
`ByteBuffer` `toByteBuffer()`
`void` `write​(byte[] b, int off, int len)` Writes `len` bytes from the specified byte array starting at offset `off` 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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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 class `OutputStream`
Parameters:
  `b` - the byte to be written.

#### write

    public void write​(byte[] b,
                      int off,
                      int len)

Writes `len` bytes from the specified byte array starting at offset `off` to this byte array output stream.

Overrides:
  `write` in class `OutputStream`
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 a `ByteArrayOutputStream` has no effect. The methods in this class can be called after the stream has been closed without generating an `IOException`.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Overrides:
  `close` in class `OutputStream`
Throws:
  `IOException`

#### copyFrom

    public void copyFrom​(FastByteArrayInputStream source,
                         int offset,
                         int count)

Copies data from input stream

Parameters:
  `source` - source stream
  `offset` - offset in the source
  `count` - 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()