Class NoCopyByteArrayOutputStream

java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.opensearch.client.util.NoCopyByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class NoCopyByteArrayOutputStream extends ByteArrayOutputStream
A ByteArrayOutputStream that reduces copy operations of its underlying buffer.
  • Constructor Details

    • NoCopyByteArrayOutputStream

      public NoCopyByteArrayOutputStream()
      Create a new output stream with default initial capacity.
    • NoCopyByteArrayOutputStream

      public NoCopyByteArrayOutputStream(int size)
      Create a new output stream with the specified initial capacity.
      Parameters:
      size - the initial capacity of the internal buffer
  • Method Details

    • array

      public byte[] array()
      Get the underlying buffer. Data was added to this buffer up to size(). Note that calling this method again may return a different result if additional data was inserted and the buffer had to grow.
    • asInputStream

      public ByteArrayInputStream asInputStream()
      Get an InputStream view on this object, based on the current buffer and size.
    • asByteBuffer

      public ByteBuffer asByteBuffer()
      Get a ByteBuffer view on this object, based on the current buffer and size.