messif.objects.nio
Class ChannelOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by messif.objects.nio.BufferOutputStream
          extended by messif.objects.nio.ChannelOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, BinaryOutput
Direct Known Subclasses:
FileChannelOutputStream

public class ChannelOutputStream
extends BufferOutputStream
implements BinaryOutput

Buffered output stream for operating over channels.

Note that it is not safe to use several ChannelOutputStreams over the same channel (even if synchronized). For file channels, the FileChannelOutputStream can be used if you need this functionality. Use copy-pipes if you need it on other channel types.

If multiple threads use the same instance of this class, the access to the instance must be synchronized.

See Also:
ChannelInputStream

Field Summary
 
Fields inherited from class messif.objects.nio.BufferOutputStream
MINIMAL_BUFFER_SIZE
 
Constructor Summary
ChannelOutputStream(int bufferSize, boolean bufferDirect, java.nio.channels.WritableByteChannel writeChannel)
          Creates a new instance of ChannelOutputStream.
 
Method Summary
protected  void write(java.nio.ByteBuffer buffer)
          Writes the buffered data to the write channel.
 
Methods inherited from class messif.objects.nio.BufferOutputStream
bufferedSize, close, flush, isDirty, prepareOutput, write, write, write, write, write
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface messif.objects.nio.BinaryOutput
flush, prepareOutput
 

Constructor Detail

ChannelOutputStream

public ChannelOutputStream(int bufferSize,
                           boolean bufferDirect,
                           java.nio.channels.WritableByteChannel writeChannel)
                    throws java.io.IOException
Creates a new instance of ChannelOutputStream.

Parameters:
bufferSize - the size of the internal buffer used for flushing
bufferDirect - allocate the internal buffer as direct
writeChannel - the channel into which to write data
Throws:
java.io.IOException - if there was an error using writeChannel
Method Detail

write

protected void write(java.nio.ByteBuffer buffer)
              throws java.io.IOException
Writes the buffered data to the write channel.

Overrides:
write in class BufferOutputStream
Parameters:
buffer - the buffer from which to write data
Throws:
java.io.IOException - if there was an error writing the data