Package org.eclipse.jetty.io
Class ByteBufferOutputStream2
java.lang.Object
java.io.OutputStream
org.eclipse.jetty.io.ByteBufferOutputStream2
- All Implemented Interfaces:
- Closeable,- Flushable,- AutoCloseable
This class implements an output stream in which the data is written into a list of ByteBuffer,
 the buffer list automatically grows as data is written to it, the buffers are taken from the
 supplied 
ByteBufferPool or freshly allocated if one is not supplied.
 Designed to mimic ByteArrayOutputStream but with better memory usage, and less copying.- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()intsize()Take the combined buffer containing all content written to the OutputStream.byte[]Take the combined buffer containing all content written to the OutputStream.toString()voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwrite(ByteBuffer buffer) voidwriteTo(OutputStream out) voidwriteTo(ByteBuffer buffer) Methods inherited from class java.io.OutputStreamflush, nullOutputStream, write
- 
Constructor Details- 
ByteBufferOutputStream2public ByteBufferOutputStream2()
- 
ByteBufferOutputStream2
 
- 
- 
Method Details- 
getByteBufferPool
- 
takeByteBufferTake the combined buffer containing all content written to the OutputStream. The caller is responsible for releasing thisByteBufferback into theByteBufferPool.- Returns:
- a buffer containing all content written to the OutputStream.
 
- 
toByteBufferTake the combined buffer containing all content written to the OutputStream. The returned buffer is still contained within the OutputStream and will be released back to theByteBufferPoolwhen the OutputStream is closed.- Returns:
- a buffer containing all content written to the OutputStream.
 
- 
toByteArraypublic byte[] toByteArray()- Returns:
- a newly allocated byte array containing all content written into the OutputStream.
 
- 
sizepublic int size()
- 
writepublic void write(int b) - Specified by:
- writein class- OutputStream
 
- 
writepublic void write(byte[] b, int off, int len) - Overrides:
- writein class- OutputStream
 
- 
write
- 
writeTo
- 
writeTo- Throws:
- IOException
 
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- OutputStream
 
- 
toString
 
-