Package org.apache.beam.sdk.util
Class ExposedByteArrayOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.ByteArrayOutputStream
-
- org.apache.beam.sdk.util.ExposedByteArrayOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
@Internal public class ExposedByteArrayOutputStream extends java.io.ByteArrayOutputStream
ByteArrayOutputStream
special cased to treat writes of a single byte-array specially. When callingtoByteArray()
after writing only onebyte[]
usingwriteAndOwn(byte[])
, it will return that array directly.
-
-
Constructor Summary
Constructors Constructor Description ExposedByteArrayOutputStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
reset()
byte[]
toByteArray()
void
write(byte[] b, int off, int len)
void
write(int b)
void
writeAndOwn(byte[] b)
Writeb
to the stream and take the ownership ofb
.
-
-
-
Method Detail
-
writeAndOwn
public void writeAndOwn(byte[] b) throws java.io.IOException
Writeb
to the stream and take the ownership ofb
. If the stream is empty,b
itself will be used as the content of the stream and no content copy will be involved.Note: After passing any byte array to this method, it must not be modified again.
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len)
- Overrides:
write
in classjava.io.ByteArrayOutputStream
-
write
public void write(int b)
- Overrides:
write
in classjava.io.ByteArrayOutputStream
-
toByteArray
public byte[] toByteArray()
- Overrides:
toByteArray
in classjava.io.ByteArrayOutputStream
-
reset
public void reset()
- Overrides:
reset
in classjava.io.ByteArrayOutputStream
-
-