public class FiberFileChannel
extends java.lang.Object
implements java.nio.channels.SeekableByteChannel, java.nio.channels.GatheringByteChannel, java.nio.channels.ScatteringByteChannel
FileChannel.| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
force(boolean metaData) |
boolean |
isOpen() |
java.nio.channels.FileLock |
lock(long position,
long size,
boolean shared) |
java.nio.MappedByteBuffer |
map(java.nio.channels.FileChannel.MapMode mode,
long position,
long size) |
static FiberFileChannel |
open(java.util.concurrent.ExecutorService ioExecutor,
java.nio.file.Path path,
java.util.Set<? extends java.nio.file.OpenOption> options,
java.nio.file.attribute.FileAttribute<?>... attrs)
Opens or creates a file for reading and/or writing, returning a file channel to access the file.
|
static FiberFileChannel |
open(java.nio.file.Path path,
java.nio.file.OpenOption... options)
Opens or creates a file for reading and/or writing, returning a file channel to access the file.
|
long |
position() |
FiberFileChannel |
position(long newPosition) |
int |
read(java.nio.ByteBuffer dst) |
long |
read(java.nio.ByteBuffer[] dsts)
Reads a sequence of bytes from this channel into the given buffers.
|
long |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length) |
int |
read(java.nio.ByteBuffer dst,
long position)
Reads a sequence of bytes from this channel into the given buffer,
starting at the given file position.
|
long |
size() |
long |
transferFrom(java.nio.channels.ReadableByteChannel src,
long position,
long count) |
long |
transferTo(long position,
long count,
java.nio.channels.WritableByteChannel target) |
FiberFileChannel |
truncate(long size) |
java.nio.channels.FileLock |
tryLock(long position,
long size,
boolean shared) |
int |
write(java.nio.ByteBuffer src) |
long |
write(java.nio.ByteBuffer[] srcs) |
long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length) |
int |
write(java.nio.ByteBuffer src,
long position)
Writes a sequence of bytes to this channel from the given buffer,
starting at the given file position.
|
@Suspendable public static FiberFileChannel open(java.util.concurrent.ExecutorService ioExecutor, java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOException
The options parameter determines how the file is opened.
The READ and WRITE options determines if the file should be opened for reading and/or
writing. If neither option is contained in the array then an existing file
is opened for reading.
In addition to READ and WRITE, the following options
may be present:
| Option | Description |
|---|---|
TRUNCATE_EXISTING |
When opening an existing file, the file is first truncated to a size of 0 bytes. This option is ignored when the file is opened only for reading. |
CREATE_NEW |
If this option is present then a new file is created, failing if the file already exists. When creating a file the check for the existence of the file and the creation of the file if it does not exist is atomic with respect to other file system operations. This option is ignored when the file is opened only for reading. |
CREATE |
If this option is present then an existing file is opened if it
exists, otherwise a new file is created. When creating a file the check
for the existence of the file and the creation of the file if it does
not exist is atomic with respect to other file system operations. This
option is ignored if the CREATE_NEW option is also present or
the file is opened only for reading. |
DELETE_ON_CLOSE |
When this option is present then the implementation makes a
best effort attempt to delete the file when closed by the
the close method. If the close method is not
invoked then a best effort attempt is made to delete the file
when the Java virtual machine terminates. |
SPARSE |
When creating a new file this option is a hint that the new file will be sparse. This option is ignored when not creating a new file. |
SYNC |
Requires that every update to the file's content or metadata be written synchronously to the underlying storage device. (see Synchronized I/O file integrity). |
DSYNC |
Requires that every update to the file's content be written synchronously to the underlying storage device. (see Synchronized I/O file integrity). |
An implementation may also support additional options.
The executor parameter is the ExecutorService to
which tasks are submitted to handle I/O events and dispatch completion
results for operations initiated on resulting channel.
The nature of these tasks is highly implementation specific and so care
should be taken when configuring the Executor. Minimally it
should support an unbounded work queue and should not run tasks on the
caller thread of the execute method.
Shutting down the executor service while the channel is open results in
unspecified behavior.
The attrs parameter is an optional array of file file-attributes to set atomically when creating the file.
The new channel is created by invoking the newFileChannel method on the
provider that created the Path.
path - The path of the file to open or createoptions - Options specifying how the file is openedioExecutor - The thread pool or null to associate the channel with the default thread poolattrs - An optional list of file attributes to set atomically when creating the filejava.lang.IllegalArgumentException - If the set contains an invalid combination of optionsjava.lang.UnsupportedOperationException - If the file is associated with a provider that does not
support creating asynchronous file channels, or an unsupported
open option is specified, or the array contains an attribute that
cannot be set atomically when creating the filejava.io.IOException - If an I/O error occursjava.lang.SecurityException - If a security manager is installed and it denies an
unspecified permission required by the implementation.
In the case of the default provider, the SecurityManager.checkRead(String)
method is invoked to check read access if the file is opened for reading.
The SecurityManager.checkWrite(String) method is invoked to check
write access if the file is opened for writing@Suspendable public static FiberFileChannel open(java.nio.file.Path path, java.nio.file.OpenOption... options) throws java.io.IOException
An invocation of this method behaves in exactly the same way as the invocation
ch.open(null, file, opts, new FileAttribute<?>[0]);
where opts is a Set containing the options specified to
this method.
The resulting channel is associated with default thread pool to which tasks are submitted to handle I/O events and dispatch to completion handlers that consume the result of asynchronous operations performed on the resulting channel.
path - The path of the file to open or createoptions - Options specifying how the file is openedjava.lang.IllegalArgumentException - If the set contains an invalid combination of optionsjava.lang.UnsupportedOperationException - If the file is associated with a provider that does not
support creating file channels, or an unsupported open option is
specifiedjava.io.IOException - If an I/O error occursjava.lang.SecurityException - If a security manager is installed and it denies an
unspecified permission required by the implementation.
In the case of the default provider, the SecurityManager.checkRead(String)
method is invoked to check read access if the file is opened for reading.
The SecurityManager.checkWrite(String) method is invoked to check
write access if the file is opened for writingpublic final boolean isOpen()
isOpen in interface java.nio.channels.Channel@Suspendable public void close() throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channeljava.io.IOExceptionpublic long position()
throws java.io.IOException
position in interface java.nio.channels.SeekableByteChanneljava.io.IOExceptionpublic FiberFileChannel position(long newPosition) throws java.io.IOException
position in interface java.nio.channels.SeekableByteChanneljava.io.IOException@Suspendable public int read(java.nio.ByteBuffer dst, long position) throws java.io.IOException
This method works in the same manner as the read(ByteBuffer) method, except that bytes are read starting at the
given file position rather than at the channel's current position. This
method does not modify this channel's position. If the given position
is greater than the file's current size then no bytes are read.
dst - The buffer into which bytes are to be transferredposition - The file position at which the transfer is to begin;
must be non-negativejava.lang.IllegalArgumentException - If the position is negativeNonReadableChannelException - If this channel was not opened for readingClosedChannelException - If this channel is closedAsynchronousCloseException - If another thread closes this channel
while the read operation is in progressClosedByInterruptException - If another thread interrupts the current thread
while the read operation is in progress, thereby
closing the channel and setting the current thread's
interrupt statusjava.io.IOException - If some other I/O error occurs@Suspendable public int read(java.nio.ByteBuffer dst) throws java.io.IOException
read in interface java.nio.channels.ReadableByteChannelread in interface java.nio.channels.SeekableByteChanneljava.io.IOException@Suspendable public final long read(java.nio.ByteBuffer[] dsts) throws java.io.IOException
Bytes are read starting at this channel's current file position, and
then the file position is updated with the number of bytes actually
read. Otherwise this method behaves exactly as specified in the ScatteringByteChannel interface.
read in interface java.nio.channels.ScatteringByteChanneljava.io.IOException@Suspendable public long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
read in interface java.nio.channels.ScatteringByteChanneljava.io.IOException@Suspendable public int write(java.nio.ByteBuffer src, long position) throws java.io.IOException
This method works in the same manner as the write(ByteBuffer) method, except that bytes are written starting at
the given file position rather than at the channel's current position.
This method does not modify this channel's position. If the given
position is greater than the file's current size then the file will be
grown to accommodate the new bytes; the values of any bytes between the
previous end-of-file and the newly-written bytes are unspecified.
src - The buffer from which bytes are to be transferredposition - The file position at which the transfer is to begin;
must be non-negativejava.lang.IllegalArgumentException - If the position is negativeNonWritableChannelException - If this channel was not opened for writingClosedChannelException - If this channel is closedAsynchronousCloseException - If another thread closes this channel
while the write operation is in progressClosedByInterruptException - If another thread interrupts the current thread
while the write operation is in progress, thereby
closing the channel and setting the current thread's
interrupt statusjava.io.IOException - If some other I/O error occurs@Suspendable public int write(java.nio.ByteBuffer src) throws java.io.IOException
write in interface java.nio.channels.SeekableByteChannelwrite in interface java.nio.channels.WritableByteChanneljava.io.IOException@Suspendable public long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
write in interface java.nio.channels.GatheringByteChanneljava.io.IOException@Suspendable public final long write(java.nio.ByteBuffer[] srcs) throws java.io.IOException
write in interface java.nio.channels.GatheringByteChanneljava.io.IOExceptionpublic long size()
throws java.io.IOException
size in interface java.nio.channels.SeekableByteChanneljava.io.IOException@Suspendable public java.nio.channels.FileLock lock(long position, long size, boolean shared) throws java.io.IOException
java.io.IOExceptionpublic void force(boolean metaData)
throws java.io.IOException
java.io.IOExceptionpublic FiberFileChannel truncate(long size) throws java.io.IOException
truncate in interface java.nio.channels.SeekableByteChanneljava.io.IOExceptionpublic java.nio.channels.FileLock tryLock(long position,
long size,
boolean shared)
throws java.io.IOException
java.io.IOExceptionpublic long transferTo(long position,
long count,
java.nio.channels.WritableByteChannel target)
throws java.io.IOException
java.io.IOExceptionpublic long transferFrom(java.nio.channels.ReadableByteChannel src,
long position,
long count)
throws java.io.IOException
java.io.IOExceptionpublic java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode mode,
long position,
long size)
throws java.io.IOException
java.io.IOException