Package org.apache.avro.util
Class NonCopyingByteArrayOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.apache.avro.util.NonCopyingByteArrayOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Utility to make data written to an
ByteArrayOutputStream directly
available as a ByteBuffer.Supports limits to the amount of data which
may be written. All decompressors MUST create capacity restricted streams to
prevent maliciously compressed data to trigger memory problems across
threads.-
Field Summary
Fields inherited from class java.io.ByteArrayOutputStream
buf, count -
Constructor Summary
ConstructorsConstructorDescriptionNonCopyingByteArrayOutputStream(int size) Creates a new byte array output stream, with no size limit. -
Method Summary
Modifier and TypeMethodDescriptionGet the contents of this ByteArrayOutputStream wrapped as a ByteBuffer.capacityLimitedOutputStream(int size) Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.capacityLimitedOutputStream(int size, long limit) Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes, capacity limit as specified inlimit.voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwriteBytes(byte[] b) Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, toString, writeToMethods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Constructor Details
-
NonCopyingByteArrayOutputStream
public NonCopyingByteArrayOutputStream(int size) Creates a new byte array output stream, with no size limit.- Parameters:
size- the initial size- Throws:
IllegalArgumentException- if size is negative
-
-
Method Details
-
asByteBuffer
Get the contents of this ByteArrayOutputStream wrapped as a ByteBuffer. This is a shallow copy. Changes to this ByteArrayOutputstream "write through" to the ByteBuffer.- Returns:
- The contents of this ByteArrayOutputstream wrapped as a ByteBuffer
-
write
public void write(int b) - Overrides:
writein classByteArrayOutputStream
-
write
public void write(byte[] b, int off, int len) - Overrides:
writein classByteArrayOutputStream
-
writeBytes
public void writeBytes(byte[] b) - Overrides:
writeBytesin classByteArrayOutputStream
-
capacityLimitedOutputStream
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. The amount of data which can be written to any output stream is limited by the system propertySystemLimitException.MAX_DECOMPRESS_LENGTH_PROPERTY- Parameters:
size- buffer capacity- Returns:
- the output stream
-
capacityLimitedOutputStream
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes, capacity limit as specified inlimit.- Parameters:
size- buffer capacitylimit- max size of output buffer- Returns:
- the output stream
-