Class ByteStringOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    @NotThreadSafe
    public final class ByteStringOutputStream
    extends java.io.OutputStream
    An OutputStream that produces ByteStrings.

    Closing this output stream does nothing.

    This class is not thread safe and expects appropriate locking to be used in a thread-safe manner. This differs from ByteString.Output which synchronizes its writes.

    • Constructor Summary

      Constructors 
      Constructor Description
      ByteStringOutputStream()
      Creates a new output stream with a default capacity.
      ByteStringOutputStream​(int initialCapacity)
      Creates a new output stream with the specified initial capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int size()
      Returns the current size of the output stream.
      org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.ByteString toByteString()
      Creates a byte string with the size and contents of this output stream.
      org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.ByteString toByteStringAndReset()
      Creates a byte string with the size and contents of this output stream and resets the output stream to be re-used possibly re-using any existing buffers.
      java.lang.String toString()  
      void write​(byte[] b, int offset, int length)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        close, flush, nullOutputStream, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ByteStringOutputStream

        public ByteStringOutputStream()
        Creates a new output stream with a default capacity.
      • ByteStringOutputStream

        public ByteStringOutputStream​(int initialCapacity)
        Creates a new output stream with the specified initial capacity.
        Parameters:
        initialCapacity - the initial capacity of the output stream.
    • Method Detail

      • write

        public void write​(int b)
        Specified by:
        write in class java.io.OutputStream
      • write

        public void write​(byte[] b,
                          int offset,
                          int length)
        Overrides:
        write in class java.io.OutputStream
      • toByteString

        public org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.ByteString toByteString()
        Creates a byte string with the size and contents of this output stream.

        Note that the caller must not invoke {#link toByteStringAndReset() as the internal buffer maybe mutated by a future write(int) mutating ByteStrings returned in the past.

      • toByteStringAndReset

        public org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.ByteString toByteStringAndReset()
        Creates a byte string with the size and contents of this output stream and resets the output stream to be re-used possibly re-using any existing buffers.
      • size

        public int size()
        Returns the current size of the output stream.
        Returns:
        the current size of the output stream
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object