Class FiberFileChannel
- java.lang.Object
- 
- co.paralleluniverse.fibers.io.FiberFileChannel
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable,- java.nio.channels.ByteChannel,- java.nio.channels.Channel,- java.nio.channels.GatheringByteChannel,- java.nio.channels.ReadableByteChannel,- java.nio.channels.ScatteringByteChannel,- java.nio.channels.SeekableByteChannel,- java.nio.channels.WritableByteChannel
 
 public class FiberFileChannel extends java.lang.Object implements java.nio.channels.SeekableByteChannel, java.nio.channels.GatheringByteChannel, java.nio.channels.ScatteringByteChannelA fiber-blocking version ofFileChannel.
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidforce(boolean metaData)booleanisOpen()java.nio.channels.FileLocklock(long position, long size, boolean shared)java.nio.MappedByteBuffermap(java.nio.channels.FileChannel.MapMode mode, long position, long size)static FiberFileChannelopen(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.static FiberFileChannelopen(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, returning a file channel to access the file.longposition()FiberFileChannelposition(long newPosition)intread(java.nio.ByteBuffer dst)longread(java.nio.ByteBuffer[] dsts)Reads a sequence of bytes from this channel into the given buffers.longread(java.nio.ByteBuffer[] dsts, int offset, int length)intread(java.nio.ByteBuffer dst, long position)Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.longsize()longtransferFrom(java.nio.channels.ReadableByteChannel src, long position, long count)longtransferTo(long position, long count, java.nio.channels.WritableByteChannel target)FiberFileChanneltruncate(long size)java.nio.channels.FileLocktryLock(long position, long size, boolean shared)intwrite(java.nio.ByteBuffer src)longwrite(java.nio.ByteBuffer[] srcs)longwrite(java.nio.ByteBuffer[] srcs, int offset, int length)intwrite(java.nio.ByteBuffer src, long position)Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.
 
- 
- 
- 
Method Detail- 
open@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 Opens or creates a file, returning a file channel to access the file.The optionsparameter determines how the file is opened. TheREADandWRITEoptions determine if the file should be opened for reading and/or writing. If neither option (or theAPPENDoption) is contained in the array then the file is opened for reading. By default reading or writing commences at the beginning of the file.In the addition to READandWRITE, the following options may be present:Option Description APPENDIf this option is present then the file is opened for writing and each invocation of the channel's writemethod first advances the position to the end of the file and then writes the requested data. Whether the advancement of the position and the writing of the data are done in a single atomic operation is system-dependent and therefore unspecified. This option may not be used in conjunction with theREADorTRUNCATE_EXISTINGoptions.TRUNCATE_EXISTINGIf this option is present then the existing file is truncated to a size of 0 bytes. This option is ignored when the file is opened only for reading. CREATE_NEWIf 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. CREATEIf 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_NEWoption is also present or the file is opened only for reading.DELETE_ON_CLOSEWhen this option is present then the implementation makes a best effort attempt to delete the file when closed by the closemethod. If theclosemethod is not invoked then a best effort attempt is made to delete the file when the Java virtual machine terminates.SPARSEWhen 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. SYNCRequires that every update to the file's content or metadata be written synchronously to the underlying storage device. (see Synchronized I/O file integrity). DSYNCRequires 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 attrsparameter is an optional array of filefile-attributesto set atomically when creating the file.The new channel is created by invoking the newFileChannelmethod on the provider that created thePath.- Parameters:
- path- The path of the file to open or create
- options- Options specifying how the file is opened
- ioExecutor- The thread pool or- nullto associate the channel with the default thread pool
- attrs- An optional list of file attributes to set atomically when creating the file
- Returns:
- A new file channel
- Throws:
- java.lang.IllegalArgumentException- If the set contains an invalid combination of options
- java.lang.UnsupportedOperationException- If the- fileis 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 file
- java.io.IOException- If an I/O error occurs
- java.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
 
 - 
open@Suspendable public static FiberFileChannel open(java.nio.file.Path path, java.nio.file.OpenOption... options) throws java.io.IOException Opens or creates a file for reading and/or writing, returning a file channel to access the file.An invocation of this method behaves in exactly the same way as the invocation ch.whereopen(null, file, opts, new FileAttribute<?>[0]);optsis aSetcontaining 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. - Parameters:
- path- The path of the file to open or create
- options- Options specifying how the file is opened
- Returns:
- A new file channel
- Throws:
- java.lang.IllegalArgumentException- If the set contains an invalid combination of options
- java.lang.UnsupportedOperationException- If the- fileis associated with a provider that does not support creating file channels, or an unsupported open option is specified
- java.io.IOException- If an I/O error occurs
- java.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
 
 - 
isOpenpublic final boolean isOpen() - Specified by:
- isOpenin interface- java.nio.channels.Channel
 
 - 
close@Suspendable public void close() throws java.io.IOException - Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.nio.channels.Channel
- Specified by:
- closein interface- java.io.Closeable
- Throws:
- java.io.IOException
 
 - 
positionpublic long position() throws java.io.IOException- Specified by:
- positionin interface- java.nio.channels.SeekableByteChannel
- Throws:
- java.io.IOException
 
 - 
positionpublic FiberFileChannel position(long newPosition) throws java.io.IOException - Specified by:
- positionin interface- java.nio.channels.SeekableByteChannel
- Throws:
- java.io.IOException
 
 - 
read@Suspendable public int read(java.nio.ByteBuffer dst, long position) throws java.io.IOException Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.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.- Parameters:
- dst- The buffer into which bytes are to be transferred
- position- The file position at which the transfer is to begin; must be non-negative
- Returns:
- The number of bytes read, possibly zero, or -1if the given position is greater than or equal to the file's current size
- Throws:
- java.lang.IllegalArgumentException- If the position is negative
- java.nio.channels.NonReadableChannelException- If this channel was not opened for reading
- java.nio.channels.ClosedChannelException- If this channel is closed
- java.nio.channels.AsynchronousCloseException- If another thread closes this channel while the read operation is in progress
- java.nio.channels.ClosedByInterruptException- 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 status
- java.io.IOException- If some other I/O error occurs
 
 - 
read@Suspendable public int read(java.nio.ByteBuffer dst) throws java.io.IOException - Specified by:
- readin interface- java.nio.channels.ReadableByteChannel
- Specified by:
- readin interface- java.nio.channels.SeekableByteChannel
- Throws:
- java.io.IOException
 
 - 
read@Suspendable public final long read(java.nio.ByteBuffer[] dsts) throws java.io.IOException Reads a sequence of bytes from this channel into the given buffers.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 ScatteringByteChannelinterface.- Specified by:
- readin interface- java.nio.channels.ScatteringByteChannel
- Throws:
- java.io.IOException
 
 - 
read@Suspendable public long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException - Specified by:
- readin interface- java.nio.channels.ScatteringByteChannel
- Throws:
- java.io.IOException
 
 - 
write@Suspendable public int write(java.nio.ByteBuffer src, long position) throws java.io.IOException Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.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.- Parameters:
- src- The buffer from which bytes are to be transferred
- position- The file position at which the transfer is to begin; must be non-negative
- Returns:
- The number of bytes written, possibly zero
- Throws:
- java.lang.IllegalArgumentException- If the position is negative
- java.nio.channels.NonWritableChannelException- If this channel was not opened for writing
- java.nio.channels.ClosedChannelException- If this channel is closed
- java.nio.channels.AsynchronousCloseException- If another thread closes this channel while the write operation is in progress
- java.nio.channels.ClosedByInterruptException- 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 status
- java.io.IOException- If some other I/O error occurs
 
 - 
write@Suspendable public int write(java.nio.ByteBuffer src) throws java.io.IOException - Specified by:
- writein interface- java.nio.channels.SeekableByteChannel
- Specified by:
- writein interface- java.nio.channels.WritableByteChannel
- Throws:
- java.io.IOException
 
 - 
write@Suspendable public long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException - Specified by:
- writein interface- java.nio.channels.GatheringByteChannel
- Throws:
- java.io.IOException
 
 - 
write@Suspendable public final long write(java.nio.ByteBuffer[] srcs) throws java.io.IOException - Specified by:
- writein interface- java.nio.channels.GatheringByteChannel
- Throws:
- java.io.IOException
 
 - 
sizepublic long size() throws java.io.IOException- Specified by:
- sizein interface- java.nio.channels.SeekableByteChannel
- Throws:
- java.io.IOException
 
 - 
lock@Suspendable public java.nio.channels.FileLock lock(long position, long size, boolean shared) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
forcepublic void force(boolean metaData) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
truncatepublic FiberFileChannel truncate(long size) throws java.io.IOException - Specified by:
- truncatein interface- java.nio.channels.SeekableByteChannel
- Throws:
- java.io.IOException
 
 - 
tryLockpublic java.nio.channels.FileLock tryLock(long position, long size, boolean shared) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
transferTopublic long transferTo(long position, long count, java.nio.channels.WritableByteChannel target) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
transferFrompublic long transferFrom(java.nio.channels.ReadableByteChannel src, long position, long count) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
mappublic java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode mode, long position, long size) throws java.io.IOException- Throws:
- java.io.IOException
 
 
- 
 
-