Package com.google.common.jimfs
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 class
A file lock that does nothing, since only one JVM process has access to this file system.Nested classes/interfaces inherited from class java.nio.channels.FileChannel
FileChannel.MapMode
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
Set of threads that are currently doing an interruptible blocking operation; that is, doing something that requires acquiring the file's lock.private final RegularFile
private final FileSystemState
private long
private final boolean
private final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionJimfsFileChannel
(RegularFile file, Set<OpenOption> options, FileSystemState fileSystemState) -
Method Summary
Modifier and TypeMethodDescriptionasAsynchronousFileChannel
(ExecutorService executor) Returns anAsynchronousFileChannel
view of this channel using the given executor for asynchronous operations.private boolean
Begins a blocking operation, making the operation interruptible.private void
checkLockArguments
(long position, long size, boolean shared) (package private) void
(package private) void
(package private) void
private void
endBlocking
(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.void
force
(boolean metaData) protected void
lock
(long position, long size, boolean shared) map
(FileChannel.MapMode mode, long position, long size) long
position()
position
(long newPosition) int
read
(ByteBuffer dst) long
read
(ByteBuffer[] dsts, int offset, int length) int
read
(ByteBuffer dst, long position) long
size()
long
transferFrom
(ReadableByteChannel src, long position, long count) long
transferTo
(long position, long count, WritableByteChannel target) truncate
(long size) tryLock
(long position, long size, boolean shared) int
write
(ByteBuffer src) long
write
(ByteBuffer[] srcs, int offset, int length) int
write
(ByteBuffer src, long position) Methods inherited from class java.nio.channels.FileChannel
lock, map, open, open, read, tryLock, write
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
Field Details
-
blockingThreads
Set of threads that are currently doing an interruptible blocking operation; that is, doing something that requires acquiring the file's lock. These threads must be interrupted if the channel is closed by another thread. -
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 anAsynchronousFileChannel
view 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. Returnstrue
if the channel was open and the thread was added as a blocking thread; returnsfalse
if 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:
read
in interfaceReadableByteChannel
- Specified by:
read
in interfaceSeekableByteChannel
- Specified by:
read
in classFileChannel
- Throws:
IOException
-
read
- Specified by:
read
in interfaceScatteringByteChannel
- Specified by:
read
in classFileChannel
- Throws:
IOException
-
read
- Specified by:
read
in classFileChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceSeekableByteChannel
- Specified by:
write
in interfaceWritableByteChannel
- Specified by:
write
in classFileChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceGatheringByteChannel
- Specified by:
write
in classFileChannel
- Throws:
IOException
-
write
- Specified by:
write
in classFileChannel
- Throws:
IOException
-
position
- Specified by:
position
in interfaceSeekableByteChannel
- Specified by:
position
in classFileChannel
- Throws:
IOException
-
position
- Specified by:
position
in interfaceSeekableByteChannel
- Specified by:
position
in classFileChannel
- Throws:
IOException
-
size
- Specified by:
size
in interfaceSeekableByteChannel
- Specified by:
size
in classFileChannel
- Throws:
IOException
-
truncate
- Specified by:
truncate
in interfaceSeekableByteChannel
- Specified by:
truncate
in classFileChannel
- Throws:
IOException
-
force
- Specified by:
force
in classFileChannel
- Throws:
IOException
-
transferTo
- Specified by:
transferTo
in classFileChannel
- Throws:
IOException
-
transferFrom
- Specified by:
transferFrom
in classFileChannel
- Throws:
IOException
-
map
- Specified by:
map
in classFileChannel
- Throws:
IOException
-
lock
- Specified by:
lock
in classFileChannel
- Throws:
IOException
-
tryLock
- Specified by:
tryLock
in classFileChannel
- Throws:
IOException
-
checkLockArguments
- Throws:
IOException
-
implCloseChannel
protected void implCloseChannel()- Specified by:
implCloseChannel
in classAbstractInterruptibleChannel
-