Class ByteStringOutputStream

java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.apache.pekko.http.impl.util.ByteStringOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class ByteStringOutputStream extends ByteArrayOutputStream
INTERNAL API

An OutputStream that buffers into a byte array like ByteArrayOutputStream but that can hand the buffered data over as a pekko.util.ByteString without copying it, unlike ByteArrayOutputStream.toByteArray which always creates a copy.

Derived from the ByteStringOutputStream in Apache Pekko gRPC (https://github.com/apache/pekko-grpc/pull/862).

  • Constructor Details

    • ByteStringOutputStream

      public ByteStringOutputStream(int capacity)
  • Method Details

    • toByteStringUnsafe

      public org.apache.pekko.util.ByteString toByteStringUnsafe()
      Wraps the bytes written so far in a ByteString. The buffer may be shared with the returned ByteString, so this stream must not be written to, reset or reused afterwards.
      Returns:
      (undocumented)