public class MemFileChannel extends FileChannel
newChannel() methods to construct an instance of this class.
In order to use this class with a Database, you must use the DatabaseBuilder to open/create the Database instance, passing an instance
of this class to the DatabaseBuilder.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.
FileChannel.MapMode| Modifier and Type | Field and Description |
|---|---|
static String |
RO_CHANNEL_MODE
read-only channel access mode
|
static String |
RW_CHANNEL_MODE
read/write channel access mode
|
| Modifier and Type | Method and Description |
|---|---|
void |
force(boolean metaData) |
FileLock |
lock(long position,
long size,
boolean shared) |
MappedByteBuffer |
map(FileChannel.MapMode mode,
long position,
long size) |
static MemFileChannel |
newChannel()
Creates a new read/write, empty MemFileChannel.
|
static MemFileChannel |
newChannel(File file)
Creates a new read/write MemFileChannel containing the contents of the
given File.
|
static MemFileChannel |
newChannel(File file,
String mode)
Creates a new MemFileChannel containing the contents of the
given File with the given mode (for mode details see
RandomAccessFile.RandomAccessFile(File,String)). |
static MemFileChannel |
newChannel(InputStream in)
Creates a new read/write MemFileChannel containing the contents of the
given InputStream.
|
static MemFileChannel |
newChannel(InputStream in,
String mode)
Creates a new MemFileChannel containing the contents of the
given InputStream with the given mode (for mode details see
RandomAccessFile.RandomAccessFile(File,String)). |
static MemFileChannel |
newChannel(Path file)
Creates a new read/write MemFileChannel containing the contents of the
given Path.
|
static MemFileChannel |
newChannel(Path file,
OpenOption... opts)
Creates a new MemFileChannel containing the contents of the
given Path with the given mode (for mode details see
RandomAccessFile.RandomAccessFile(File,String)). |
static MemFileChannel |
newChannel(ReadableByteChannel in)
Creates a new read/write MemFileChannel containing the contents of the
given ReadableByteChannel.
|
static MemFileChannel |
newChannel(ReadableByteChannel in,
String mode)
Creates a new MemFileChannel containing the contents of the
given ReadableByteChannel with the given mode (for mode details see
RandomAccessFile.RandomAccessFile(File,String)). |
long |
position() |
FileChannel |
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,
OutputStream dst)
Convenience method for writing the selected portion of this channel to
the given destination stream.
|
long |
transferTo(long position,
long count,
WritableByteChannel dst) |
long |
transferTo(OutputStream dst)
Convenience method for writing the entire contents of this channel to the
given destination stream.
|
long |
transferTo(WritableByteChannel dst)
Convenience method for writing the entire contents of this channel to the
given destination channel.
|
FileChannel |
truncate(long newSize) |
FileLock |
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) |
close, isOpenpublic static final String RO_CHANNEL_MODE
public static final String RW_CHANNEL_MODE
public static MemFileChannel newChannel()
public static MemFileChannel newChannel(File file) throws IOException
IOExceptionpublic static MemFileChannel newChannel(File file, String mode) throws IOException
RandomAccessFile.RandomAccessFile(File,String)). Note,
modifications to the returned channel will not affect the original
File source.IOExceptionpublic static MemFileChannel newChannel(Path file, OpenOption... opts) throws IOException
RandomAccessFile.RandomAccessFile(File,String)). Note,
modifications to the returned channel will not affect the original
File source.IOExceptionpublic static MemFileChannel newChannel(Path file) throws IOException
IOExceptionpublic static MemFileChannel newChannel(InputStream in) throws IOException
IOExceptionpublic static MemFileChannel newChannel(InputStream in, String mode) throws IOException
RandomAccessFile.RandomAccessFile(File,String)).IOExceptionpublic static MemFileChannel newChannel(ReadableByteChannel in) throws IOException
IOExceptionpublic static MemFileChannel newChannel(ReadableByteChannel in, String mode) throws IOException
RandomAccessFile.RandomAccessFile(File,String)).IOExceptionpublic int read(ByteBuffer dst)
read in interface ReadableByteChannelread in interface SeekableByteChannelread in class FileChannelpublic int read(ByteBuffer dst, long position)
read in class FileChannelpublic int write(ByteBuffer src)
write in interface SeekableByteChannelwrite in interface WritableByteChannelwrite in class FileChannelpublic int write(ByteBuffer src, long position)
write in class FileChannelpublic long position()
position in interface SeekableByteChannelposition in class FileChannelpublic FileChannel position(long newPosition)
position in interface SeekableByteChannelposition in class FileChannelpublic long size()
size in interface SeekableByteChannelsize in class FileChannelpublic FileChannel truncate(long newSize)
truncate in interface SeekableByteChanneltruncate in class FileChannelpublic void force(boolean metaData)
force in class FileChannelpublic long transferTo(WritableByteChannel dst) throws IOException
IOExceptiontransferTo(long,long,WritableByteChannel)public long transferTo(long position,
long count,
WritableByteChannel dst)
throws IOException
transferTo in class FileChannelIOExceptionpublic long transferTo(OutputStream dst) throws IOException
IOExceptiontransferTo(long,long,WritableByteChannel)public long transferTo(long position,
long count,
OutputStream dst)
throws IOException
IOExceptiontransferTo(long,long,WritableByteChannel)public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException
transferFrom in class FileChannelIOExceptionpublic long write(ByteBuffer[] srcs, int offset, int length)
write in interface GatheringByteChannelwrite in class FileChannelpublic long read(ByteBuffer[] dsts, int offset, int length)
read in interface ScatteringByteChannelread in class FileChannelpublic MappedByteBuffer map(FileChannel.MapMode mode, long position, long size)
map in class FileChannelpublic FileLock lock(long position, long size, boolean shared)
lock in class FileChannelpublic FileLock tryLock(long position, long size, boolean shared)
tryLock in class FileChannelCopyright © 2005–2025 OpenHMS. All rights reserved.