org.jppf.io
Class ByteBufferOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.jppf.io.ByteBufferOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class ByteBufferOutputStream
extends OutputStream

Implementation of an OutputStream backed by a ByteBuffer.

Author:
Laurent Cohen

Constructor Summary
ByteBufferOutputStream(ByteBuffer buffer)
          Initialize this output stream with the specified backing ByteBuffer.
ByteBufferOutputStream(int capacity)
          Initialize this output stream with the specified capacity for the backing ByteBuffer.
 
Method Summary
 void close()
          Close this output stream and releases any system resources associated with it.
 void flush()
          Flushes this output stream and force any buffered output bytes to be written out.
 ByteBuffer toByteBuffer()
          Get the content of this output stream as a ByteBuffer.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this output stream.
 void write(byte[] b, int off, int len)
          Write len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBufferOutputStream

public ByteBufferOutputStream(int capacity)
Initialize this output stream with the specified capacity for the backing ByteBuffer.

Parameters:
capacity - the capacity of the backing byte buffer.

ByteBufferOutputStream

public ByteBufferOutputStream(ByteBuffer buffer)
Initialize this output stream with the specified backing ByteBuffer.

Parameters:
buffer - the backing byte buffer.
Method Detail

close

public void close()
           throws IOException
Close this output stream and releases any system resources associated with it.

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.close()

flush

public void flush()
           throws IOException
Flushes this output stream and force any buffered output bytes to be written out.

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.flush()

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Write len bytes from the specified byte array starting at offset off to this output stream.

Overrides:
write in class OutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.write(byte[], int, int)

write

public void write(byte[] b)
           throws IOException
Writes b.length bytes from the specified byte array to this output stream.

Overrides:
write in class OutputStream
Parameters:
b - the data.
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.write(byte[])

write

public void write(int b)
           throws IOException
Writes the specified byte to this output stream.

Specified by:
write in class OutputStream
Parameters:
b - the byte.
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.write(int)

toByteBuffer

public ByteBuffer toByteBuffer()
Get the content of this output stream as a ByteBuffer.

Returns:
the content as a byte buffer.


Copyright © 2005-2010 JPPF Team.