Class JimfsFileChannel
java.lang.Object
java.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.FileChannel
com.google.common.jimfs.JimfsFileChannel
- All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, GatheringByteChannel, InterruptibleChannel, ReadableByteChannel, ScatteringByteChannel, SeekableByteChannel, WritableByteChannel
A
FileChannel implementation that reads and writes to a RegularFile object. The
read and write methods and other methods that read or change the position of the channel are
locked because the ReadableByteChannel and WritableByteChannel interfaces specify
that the read and write methods block when another thread is currently doing a read or write
operation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classA file lock that does nothing, since only one JVM process has access to this file system.Nested classes/interfaces inherited from class FileChannel
FileChannel.MapMode -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanSet of threads that are currently doing an interruptible blocking operation; that is, doing something that requires acquiring the file's lock.private final RegularFileprivate final FileSystemStateprivate longprivate final booleanprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionJimfsFileChannel(RegularFile file, Set<OpenOption> options, FileSystemState fileSystemState) -
Method Summary
Modifier and TypeMethodDescriptionasAsynchronousFileChannel(ExecutorService executor) Returns anAsynchronousFileChannelview of this channel using the given executor for asynchronous operations.private booleanBegins a blocking operation, making the operation interruptible.private voidcheckLockArguments(long position, long size, boolean shared) (package private) void(package private) void(package private) voidprivate voidendBlocking(boolean completed) Ends a blocking operation, throwing an exception if the thread was interrupted while blocking or if the channel was closed from another thread.voidforce(boolean metaData) protected voidlock(long position, long size, boolean shared) map(FileChannel.MapMode mode, long position, long size) longposition()position(long newPosition) intread(ByteBuffer dst) longread(ByteBuffer[] dsts, int offset, int length) intread(ByteBuffer dst, long position) longsize()longtransferFrom(ReadableByteChannel src, long position, long count) longtransferTo(long position, long count, WritableByteChannel target) truncate(long size) tryLock(long position, long size, boolean shared) intwrite(ByteBuffer src) longwrite(ByteBuffer[] srcs, int offset, int length) intwrite(ByteBuffer src, long position) Methods inherited from class AbstractInterruptibleChannel
begin, close, end, isOpen
-
Field Details
-
blockingThreads
-
file
-
fileSystemState
-
read
private final boolean read -
write
private final boolean write -
append
private final boolean append -
position
private long position
-
-
Constructor Details
-
JimfsFileChannel
-
-
Method Details
-
asAsynchronousFileChannel
Returns anAsynchronousFileChannelview of this channel using the given executor for asynchronous operations. -
checkReadable
void checkReadable() -
checkWritable
void checkWritable() -
checkOpen
- Throws:
ClosedChannelException
-
beginBlocking
private boolean beginBlocking()Begins a blocking operation, making the operation interruptible. Returnstrueif the channel was open and the thread was added as a blocking thread; returnsfalseif the channel was closed. -
endBlocking
Ends a blocking operation, throwing an exception if the thread was interrupted while blocking or if the channel was closed from another thread.- Throws:
AsynchronousCloseException
-
read
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekableByteChannel- Specified by:
readin classFileChannel- Throws:
IOException
-
read
- Specified by:
readin interfaceScatteringByteChannel- Specified by:
readin classFileChannel- Throws:
IOException
-
read
- Specified by:
readin classFileChannel- Throws:
IOException
-
write
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel- Specified by:
writein classFileChannel- Throws:
IOException
-
write
- Specified by:
writein interfaceGatheringByteChannel- Specified by:
writein classFileChannel- Throws:
IOException
-
write
- Specified by:
writein classFileChannel- Throws:
IOException
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Specified by:
positionin classFileChannel- Throws:
IOException
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Specified by:
positionin classFileChannel- Throws:
IOException
-
size
- Specified by:
sizein interfaceSeekableByteChannel- Specified by:
sizein classFileChannel- Throws:
IOException
-
truncate
- Specified by:
truncatein interfaceSeekableByteChannel- Specified by:
truncatein classFileChannel- Throws:
IOException
-
force
- Specified by:
forcein classFileChannel- Throws:
IOException
-
transferTo
- Specified by:
transferToin classFileChannel- Throws:
IOException
-
transferFrom
- Specified by:
transferFromin classFileChannel- Throws:
IOException
-
map
- Specified by:
mapin classFileChannel- Throws:
IOException
-
lock
- Specified by:
lockin classFileChannel- Throws:
IOException
-
tryLock
- Specified by:
tryLockin classFileChannel- Throws:
IOException
-
checkLockArguments
- Throws:
IOException
-
implCloseChannel
protected void implCloseChannel()- Specified by:
implCloseChannelin classAbstractInterruptibleChannel
-