Top Description Fields Constructors Methods
org.eclipse.jetty.io

public Class ByteBufferOutputStream2

extends OutputStream
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer

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 java.io.ByteArrayOutputStream but with better memory usage, and less copying.

Field Summary

Modifier and TypeField and Description
private final ByteBufferAccumulator
private int

Constructor Summary

AccessConstructor and Description
public
public
ByteBufferOutputStream2(ByteBufferPool bufferPool, boolean direct)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public int
size()

public RetainableByteBuffer

Returns:

a buffer containing all content written to the OutputStream.
takeByteBuffer
()

Take the combined buffer containing all content written to the OutputStream.

public byte[]

Returns:

a newly allocated byte array containing all content written into the OutputStream.
toByteArray
()

public RetainableByteBuffer

Returns:

a buffer containing all content written to the OutputStream.
toByteBuffer
()

Take the combined buffer containing all content written to the OutputStream.

public synchronized String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(ByteBuffer buffer)

public void
public void
Inherited from java.io.OutputStream:
flushnullOutputStreamwrite

Field Detail

_accumulatorback to summary
private final ByteBufferAccumulator _accumulator
_sizeback to summary
private int _size

Constructor Detail

ByteBufferOutputStream2back to summary
public ByteBufferOutputStream2()
ByteBufferOutputStream2back to summary
public ByteBufferOutputStream2(ByteBufferPool bufferPool, boolean direct)

Method Detail

closeback to summary
public void close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
sizeback to summary
public int size()
takeByteBufferback to summary
public RetainableByteBuffer takeByteBuffer()

Take the combined buffer containing all content written to the OutputStream. The caller is responsible for releasing this RetainableByteBuffer.

Returns:RetainableByteBuffer

a buffer containing all content written to the OutputStream.

toByteArrayback to summary
public byte[] toByteArray()
Returns:byte[]

a newly allocated byte array containing all content written into the OutputStream.

toByteBufferback to summary
public RetainableByteBuffer 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 when the OutputStream is closed.

Returns:RetainableByteBuffer

a buffer containing all content written to the OutputStream.

toStringback to summary
public synchronized String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
writeback to summary
public void write(int b)

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
writeback to summary
public void write(byte[] b, int off, int len)

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
writeback to summary
public void write(ByteBuffer buffer)
writeToback to summary
public void writeTo(ByteBuffer buffer)
writeToback to summary
public void writeTo(OutputStream out) throws IOException