Package com.pnfsoftware.jeb.util.io
Class DirectByteArrayOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
com.pnfsoftware.jeb.util.io.DirectByteArrayOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Extend
ByteArrayOutputStream to provide direct access to the underlying byte array. In
particular, this class is meant to circumvent the memory consumption issues of
ByteArrayOutputStream.toByteArray().-
Field Summary
Fields inherited from class java.io.ByteArrayOutputStream
buf, count -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBytes()Direct access to the underlying byte array.byte[]Direct access to the underlying byte array.Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, toString, write, write, writeBytes, writeToMethods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Constructor Details
-
DirectByteArrayOutputStream
public DirectByteArrayOutputStream()
-
-
Method Details
-
getRawBytes
public byte[] getRawBytes()Direct access to the underlying byte array. This method is dangerous, but can be used instead of the expensiveByteArrayOutputStream.toByteArray(). It should be used in combination withByteArrayOutputStream.size(). A safer, as efficient alternative, isgetBytes().- Returns:
- array with potentially more bytes than what was actually written to the stream (see
ByteArrayOutputStream.size())
-
getBytes
Direct access to the underlying byte array.- Returns:
- a buffer view of the bytes written to the stream
-