Package org.apache.beam.sdk.util
Class ByteStringOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.beam.sdk.util.ByteStringOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
@NotThreadSafe public final class ByteStringOutputStream extends java.io.OutputStream
AnOutputStream
that producesByteString
s.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)
-
-
-
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 classjava.io.OutputStream
-
write
public void write(byte[] b, int offset, int length)
- Overrides:
write
in classjava.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 futurewrite(int)
mutatingByteString
s 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 classjava.lang.Object
-
-