Class MemFileChannel
- java.lang.Object
-
- java.nio.channels.spi.AbstractInterruptibleChannel
-
- java.nio.channels.FileChannel
-
- com.healthmarketscience.jackcess.util.MemFileChannel
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ByteChannel,Channel,GatheringByteChannel,InterruptibleChannel,ReadableByteChannel,ScatteringByteChannel,SeekableByteChannel,WritableByteChannel
public class MemFileChannel extends FileChannel
FileChannel implementation which maintains the entire "file" in memory. This enables working with a Database entirely in memory (for situations where disk usage may not be possible or desirable). Obviously, this requires enough jvm heap space to fit the file data. Use one of thenewChannel()methods to construct an instance of this class.In order to use this class with a Database, you must use the
DatabaseBuilderto open/create the Database instance, passing an instance of this class to theDatabaseBuilder.setChannel(java.nio.channels.FileChannel)method.Implementation note: this class is optimized for use with
Database. Therefore not all methods may be implemented and individual read/write operations are only supported within page boundaries.- Author:
- James Ahlborn
- Usage:
- Advanced: This class is for advanced/internal use.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.nio.channels.FileChannel
FileChannel.MapMode
-
-
Field Summary
Fields Modifier and Type Field Description static StringRO_CHANNEL_MODEread-only channel access modestatic StringRW_CHANNEL_MODEread/write channel access mode
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidforce(boolean metaData)FileLocklock(long position, long size, boolean shared)MappedByteBuffermap(FileChannel.MapMode mode, long position, long size)static MemFileChannelnewChannel()Creates a new read/write, empty MemFileChannel.static MemFileChannelnewChannel(File file)Creates a new read/write MemFileChannel containing the contents of the given File.static MemFileChannelnewChannel(File file, String mode)Creates a new MemFileChannel containing the contents of the given File with the given mode (for mode details seeRandomAccessFile(File,String)).static MemFileChannelnewChannel(InputStream in)Creates a new read/write MemFileChannel containing the contents of the given InputStream.static MemFileChannelnewChannel(InputStream in, String mode)Creates a new MemFileChannel containing the contents of the given InputStream with the given mode (for mode details seeRandomAccessFile(File,String)).static MemFileChannelnewChannel(ReadableByteChannel in)Creates a new read/write MemFileChannel containing the contents of the given ReadableByteChannel.static MemFileChannelnewChannel(ReadableByteChannel in, String mode)Creates a new MemFileChannel containing the contents of the given ReadableByteChannel with the given mode (for mode details seeRandomAccessFile(File,String)).static MemFileChannelnewChannel(Path file)Creates a new read/write MemFileChannel containing the contents of the given Path.static MemFileChannelnewChannel(Path file, OpenOption... opts)Creates a new MemFileChannel containing the contents of the given Path with the given mode (for mode details seeRandomAccessFile(File,String)).longposition()FileChannelposition(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, OutputStream dst)Convenience method for writing the selected portion of this channel to the given destination stream.longtransferTo(long position, long count, WritableByteChannel dst)longtransferTo(OutputStream dst)Convenience method for writing the entire contents of this channel to the given destination stream.longtransferTo(WritableByteChannel dst)Convenience method for writing the entire contents of this channel to the given destination channel.FileChanneltruncate(long newSize)FileLocktryLock(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 java.nio.channels.spi.AbstractInterruptibleChannel
close, isOpen
-
-
-
-
Field Detail
-
RO_CHANNEL_MODE
public static final String RO_CHANNEL_MODE
read-only channel access mode- See Also:
- Constant Field Values
-
RW_CHANNEL_MODE
public static final String RW_CHANNEL_MODE
read/write channel access mode- See Also:
- Constant Field Values
-
-
Method Detail
-
newChannel
public static MemFileChannel newChannel()
Creates a new read/write, empty MemFileChannel.
-
newChannel
public static MemFileChannel newChannel(File file) throws IOException
Creates a new read/write MemFileChannel containing the contents of the given File. Note, modifications to the returned channel will not affect the original File source.- Throws:
IOException
-
newChannel
public static MemFileChannel newChannel(File file, String mode) throws IOException
Creates a new MemFileChannel containing the contents of the given File with the given mode (for mode details seeRandomAccessFile(File,String)). Note, modifications to the returned channel will not affect the original File source.- Throws:
IOException
-
newChannel
public static MemFileChannel newChannel(Path file, OpenOption... opts) throws IOException
Creates a new MemFileChannel containing the contents of the given Path with the given mode (for mode details seeRandomAccessFile(File,String)). Note, modifications to the returned channel will not affect the original File source.- Throws:
IOException
-
newChannel
public static MemFileChannel newChannel(Path file) throws IOException
Creates a new read/write MemFileChannel containing the contents of the given Path. Note, modifications to the returned channel will not affect the original File source.- Throws:
IOException
-
newChannel
public static MemFileChannel newChannel(InputStream in) throws IOException
Creates a new read/write MemFileChannel containing the contents of the given InputStream.- Throws:
IOException
-
newChannel
public static MemFileChannel newChannel(InputStream in, String mode) throws IOException
Creates a new MemFileChannel containing the contents of the given InputStream with the given mode (for mode details seeRandomAccessFile(File,String)).- Throws:
IOException
-
newChannel
public static MemFileChannel newChannel(ReadableByteChannel in) throws IOException
Creates a new read/write MemFileChannel containing the contents of the given ReadableByteChannel.- Throws:
IOException
-
newChannel
public static MemFileChannel newChannel(ReadableByteChannel in, String mode) throws IOException
Creates a new MemFileChannel containing the contents of the given ReadableByteChannel with the given mode (for mode details seeRandomAccessFile(File,String)).- Throws:
IOException
-
read
public int read(ByteBuffer dst)
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekableByteChannel- Specified by:
readin classFileChannel
-
read
public int read(ByteBuffer dst, long position)
- Specified by:
readin classFileChannel
-
write
public int write(ByteBuffer src)
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel- Specified by:
writein classFileChannel
-
write
public int write(ByteBuffer src, long position)
- Specified by:
writein classFileChannel
-
position
public long position()
- Specified by:
positionin interfaceSeekableByteChannel- Specified by:
positionin classFileChannel
-
position
public FileChannel position(long newPosition)
- Specified by:
positionin interfaceSeekableByteChannel- Specified by:
positionin classFileChannel
-
size
public long size()
- Specified by:
sizein interfaceSeekableByteChannel- Specified by:
sizein classFileChannel
-
truncate
public FileChannel truncate(long newSize)
- Specified by:
truncatein interfaceSeekableByteChannel- Specified by:
truncatein classFileChannel
-
force
public void force(boolean metaData)
- Specified by:
forcein classFileChannel
-
transferTo
public long transferTo(WritableByteChannel dst) throws IOException
Convenience method for writing the entire contents of this channel to the given destination channel.- Throws:
IOException- See Also:
transferTo(long,long,WritableByteChannel)
-
transferTo
public long transferTo(long position, long count, WritableByteChannel dst) throws IOException- Specified by:
transferToin classFileChannel- Throws:
IOException
-
transferTo
public long transferTo(OutputStream dst) throws IOException
Convenience method for writing the entire contents of this channel to the given destination stream.- Throws:
IOException- See Also:
transferTo(long,long,WritableByteChannel)
-
transferTo
public long transferTo(long position, long count, OutputStream dst) throws IOExceptionConvenience method for writing the selected portion of this channel to the given destination stream.- Throws:
IOException- See Also:
transferTo(long,long,WritableByteChannel)
-
transferFrom
public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException
- Specified by:
transferFromin classFileChannel- Throws:
IOException
-
write
public long write(ByteBuffer[] srcs, int offset, int length)
- Specified by:
writein interfaceGatheringByteChannel- Specified by:
writein classFileChannel
-
read
public long read(ByteBuffer[] dsts, int offset, int length)
- Specified by:
readin interfaceScatteringByteChannel- Specified by:
readin classFileChannel
-
map
public MappedByteBuffer map(FileChannel.MapMode mode, long position, long size)
- Specified by:
mapin classFileChannel
-
lock
public FileLock lock(long position, long size, boolean shared)
- Specified by:
lockin classFileChannel
-
tryLock
public FileLock tryLock(long position, long size, boolean shared)
- Specified by:
tryLockin classFileChannel
-
-