public class AsynchronousFileChannelOutputStream extends BufferOutputStream
ChannelOutputStream
operating over a
file. The position is restored before every write operation, so it is safe
to use multiple instances of this class over the same file channel. However,
if multiple threads use the same instance of this class, the access to the
instance must be synchronized.Modifier and Type | Field and Description |
---|---|
protected java.nio.channels.AsynchronousFileChannel |
fileChannel
The file to which to write data
|
MINIMAL_BUFFER_SIZE
Constructor and Description |
---|
AsynchronousFileChannelOutputStream(int bufferSize,
boolean bufferDirect,
java.nio.channels.AsynchronousFileChannel fileChannel,
long position,
long maxLength)
Creates a new instance of FileChannelOutputStream.
|
Modifier and Type | Method and Description |
---|---|
long |
getPosition()
Returns the current position in the file.
|
void |
setPosition(long position)
Set the position at which the data will be written.
|
protected void |
write(java.nio.ByteBuffer buffer)
Writes the buffered data to the file channel.
|
bufferedSize, close, flush, isDirty, prepareOutput, setBufferedSizeLimit, write, write, write, write, write
protected final java.nio.channels.AsynchronousFileChannel fileChannel
public AsynchronousFileChannelOutputStream(int bufferSize, boolean bufferDirect, java.nio.channels.AsynchronousFileChannel fileChannel, long position, long maxLength) throws java.io.IOException
bufferSize
- the size of the internal buffer used for flushingbufferDirect
- allocate the internal buffer as direct
fileChannel
- the file channel into which to write dataposition
- the starting position of the filemaxLength
- the maximal length of datajava.io.IOException
- if there was an error using the file channelpublic long getPosition()
public void setPosition(long position) throws java.io.IOException
position
- the new positionjava.io.IOException
- if the specified position is outside the boundariesprotected void write(java.nio.ByteBuffer buffer) throws java.io.IOException
write
in class BufferOutputStream
buffer
- the buffer from which to write datajava.io.IOException
- if there was an error writing the data