Package org.eclipse.jetty.io
Class ByteBufferOutputStream2
- java.lang.Object
-
- java.io.OutputStream
-
- org.eclipse.jetty.io.ByteBufferOutputStream2
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class ByteBufferOutputStream2 extends java.io.OutputStreamThis 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 suppliedByteBufferPoolor freshly allocated if one is not supplied. Designed to mimicByteArrayOutputStreambut with better memory usage, and less copying.
-
-
Constructor Summary
Constructors Constructor Description ByteBufferOutputStream2()ByteBufferOutputStream2(ByteBufferPool bufferPool, boolean direct)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ByteBufferPoolgetByteBufferPool()intsize()java.nio.ByteBuffertakeByteBuffer()Take the combined buffer containing all content written to the OutputStream.byte[]toByteArray()java.nio.ByteBuffertoByteBuffer()Take the combined buffer containing all content written to the OutputStream.java.lang.StringtoString()voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite(java.nio.ByteBuffer buffer)voidwriteTo(java.io.OutputStream out)voidwriteTo(java.nio.ByteBuffer buffer)
-
-
-
Constructor Detail
-
ByteBufferOutputStream2
public ByteBufferOutputStream2()
-
ByteBufferOutputStream2
public ByteBufferOutputStream2(ByteBufferPool bufferPool, boolean direct)
-
-
Method Detail
-
getByteBufferPool
public ByteBufferPool getByteBufferPool()
-
takeByteBuffer
public java.nio.ByteBuffer takeByteBuffer()
Take 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.
-
toByteBuffer
public java.nio.ByteBuffer toByteBuffer()
Take 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.
-
toByteArray
public byte[] toByteArray()
- Returns:
- a newly allocated byte array containing all content written into the OutputStream.
-
size
public int size()
-
write
public void write(int b)
- Specified by:
writein classjava.io.OutputStream
-
write
public void write(byte[] b, int off, int len)- Overrides:
writein classjava.io.OutputStream
-
write
public void write(java.nio.ByteBuffer buffer)
-
writeTo
public void writeTo(java.nio.ByteBuffer buffer)
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-