messif.objects.nio
Class ChannelOutputStream
java.lang.Object
java.io.OutputStream
messif.objects.nio.BufferOutputStream
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
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 java.io.OutputStream |
write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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 flushingbufferDirect
- 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
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