public class MemFileChannel
extends java.nio.channels.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.| Modifier and Type | Class and Description |
|---|---|
private static class |
MemFileChannel.ReadOnlyChannel
Subclass of MemFileChannel which is read-only.
|
| Modifier and Type | Field and Description |
|---|---|
private byte[][] |
_data
chunks containing the file data.
|
private long |
_position
current read/write position
|
private long |
_size
current amount of actual data in the file
|
private static int |
CHUNK_SIZE |
private static byte[][] |
EMPTY_DATA |
private static int |
INIT_CHUNKS |
| Modifier | Constructor and Description |
|---|---|
private |
MemFileChannel() |
private |
MemFileChannel(long position,
long size,
byte[][] data) |
| Modifier and Type | Method and Description |
|---|---|
private void |
ensureCapacity(long newSize) |
void |
force(boolean metaData) |
private static int |
getChunkIndex(long pos) |
private static int |
getChunkOffset(long pos) |
private static int |
getNumChunks(long size) |
protected void |
implCloseChannel() |
java.nio.channels.FileLock |
lock(long position,
long size,
boolean shared) |
java.nio.MappedByteBuffer |
map(java.nio.channels.FileChannel.MapMode mode,
long position,
long size) |
static MemFileChannel |
newChannel()
Creates a new read/write, empty MemFileChannel.
|
static MemFileChannel |
newChannel(java.io.File file)
Creates a new read/write MemFileChannel containing the contents of the
given File.
|
static MemFileChannel |
newChannel(java.io.File file,
java.lang.String mode)
Creates a new MemFileChannel containing the contents of the
given File with the given mode (for mode details see
RandomAccessFile(File,String)). |
static MemFileChannel |
newChannel(java.io.InputStream in)
Creates a new read/write MemFileChannel containing the contents of the
given InputStream.
|
static MemFileChannel |
newChannel(java.io.InputStream in,
java.lang.String mode)
Creates a new MemFileChannel containing the contents of the
given InputStream with the given mode (for mode details see
RandomAccessFile(File,String)). |
static MemFileChannel |
newChannel(java.nio.channels.ReadableByteChannel in)
Creates a new read/write MemFileChannel containing the contents of the
given ReadableByteChannel.
|
static MemFileChannel |
newChannel(java.nio.channels.ReadableByteChannel in,
java.lang.String mode)
Creates a new MemFileChannel containing the contents of the
given ReadableByteChannel with the given mode (for mode details see
RandomAccessFile(File,String)). |
long |
position() |
java.nio.channels.FileChannel |
position(long newPosition) |
int |
read(java.nio.ByteBuffer dst) |
long |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length) |
int |
read(java.nio.ByteBuffer dst,
long position) |
long |
size() |
long |
transferFrom(java.nio.channels.ReadableByteChannel src,
long position,
long count) |
long |
transferTo(long position,
long count,
java.io.OutputStream dst)
Convenience method for writing the selected portion of this channel to
the given destination stream.
|
long |
transferTo(long position,
long count,
java.nio.channels.WritableByteChannel dst) |
long |
transferTo(java.io.OutputStream dst)
Convenience method for writing the entire contents of this channel to the
given destination stream.
|
long |
transferTo(java.nio.channels.WritableByteChannel dst)
Convenience method for writing the entire contents of this channel to the
given destination channel.
|
java.nio.channels.FileChannel |
truncate(long newSize) |
java.nio.channels.FileLock |
tryLock(long position,
long size,
boolean shared) |
int |
write(java.nio.ByteBuffer src) |
long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length) |
int |
write(java.nio.ByteBuffer src,
long position) |
begin, close, end, isOpenprivate static final byte[][] EMPTY_DATA
private static final int CHUNK_SIZE
private static final int INIT_CHUNKS
private long _position
private long _size
private byte[][] _data
private MemFileChannel()
private MemFileChannel(long position,
long size,
byte[][] data)
public static MemFileChannel newChannel()
public static MemFileChannel newChannel(java.io.File file) throws java.io.IOException
java.io.IOExceptionpublic static MemFileChannel newChannel(java.io.File file, java.lang.String mode) throws java.io.IOException
RandomAccessFile(File,String)). Note,
modifications to the returned channel will not affect the original
File source.java.io.IOExceptionpublic static MemFileChannel newChannel(java.io.InputStream in) throws java.io.IOException
java.io.IOExceptionpublic static MemFileChannel newChannel(java.io.InputStream in, java.lang.String mode) throws java.io.IOException
RandomAccessFile(File,String)).java.io.IOExceptionpublic static MemFileChannel newChannel(java.nio.channels.ReadableByteChannel in) throws java.io.IOException
java.io.IOExceptionpublic static MemFileChannel newChannel(java.nio.channels.ReadableByteChannel in, java.lang.String mode) throws java.io.IOException
RandomAccessFile(File,String)).java.io.IOExceptionpublic int read(java.nio.ByteBuffer dst)
throws java.io.IOException
read in interface java.nio.channels.ReadableByteChannelread in interface java.nio.channels.SeekableByteChannelread in class java.nio.channels.FileChanneljava.io.IOExceptionpublic int read(java.nio.ByteBuffer dst,
long position)
throws java.io.IOException
read in class java.nio.channels.FileChanneljava.io.IOExceptionpublic int write(java.nio.ByteBuffer src)
throws java.io.IOException
write in interface java.nio.channels.SeekableByteChannelwrite in interface java.nio.channels.WritableByteChannelwrite in class java.nio.channels.FileChanneljava.io.IOExceptionpublic int write(java.nio.ByteBuffer src,
long position)
throws java.io.IOException
write in class java.nio.channels.FileChanneljava.io.IOExceptionpublic long position()
throws java.io.IOException
position in interface java.nio.channels.SeekableByteChannelposition in class java.nio.channels.FileChanneljava.io.IOExceptionpublic java.nio.channels.FileChannel position(long newPosition)
throws java.io.IOException
position in interface java.nio.channels.SeekableByteChannelposition in class java.nio.channels.FileChanneljava.io.IOExceptionpublic long size()
throws java.io.IOException
size in interface java.nio.channels.SeekableByteChannelsize in class java.nio.channels.FileChanneljava.io.IOExceptionpublic java.nio.channels.FileChannel truncate(long newSize)
throws java.io.IOException
truncate in interface java.nio.channels.SeekableByteChanneltruncate in class java.nio.channels.FileChanneljava.io.IOExceptionpublic void force(boolean metaData)
throws java.io.IOException
force in class java.nio.channels.FileChanneljava.io.IOExceptionpublic long transferTo(java.nio.channels.WritableByteChannel dst)
throws java.io.IOException
java.io.IOExceptiontransferTo(long,long,WritableByteChannel)public long transferTo(long position,
long count,
java.nio.channels.WritableByteChannel dst)
throws java.io.IOException
transferTo in class java.nio.channels.FileChanneljava.io.IOExceptionpublic long transferTo(java.io.OutputStream dst)
throws java.io.IOException
java.io.IOExceptiontransferTo(long,long,WritableByteChannel)public long transferTo(long position,
long count,
java.io.OutputStream dst)
throws java.io.IOException
java.io.IOExceptiontransferTo(long,long,WritableByteChannel)public long transferFrom(java.nio.channels.ReadableByteChannel src,
long position,
long count)
throws java.io.IOException
transferFrom in class java.nio.channels.FileChanneljava.io.IOExceptionprotected void implCloseChannel()
throws java.io.IOException
implCloseChannel in class java.nio.channels.spi.AbstractInterruptibleChanneljava.io.IOExceptionprivate void ensureCapacity(long newSize)
private static int getChunkIndex(long pos)
private static int getChunkOffset(long pos)
private static int getNumChunks(long size)
public long write(java.nio.ByteBuffer[] srcs,
int offset,
int length)
throws java.io.IOException
write in interface java.nio.channels.GatheringByteChannelwrite in class java.nio.channels.FileChanneljava.io.IOExceptionpublic long read(java.nio.ByteBuffer[] dsts,
int offset,
int length)
throws java.io.IOException
read in interface java.nio.channels.ScatteringByteChannelread in class java.nio.channels.FileChanneljava.io.IOExceptionpublic java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode mode,
long position,
long size)
throws java.io.IOException
map in class java.nio.channels.FileChanneljava.io.IOExceptionpublic java.nio.channels.FileLock lock(long position,
long size,
boolean shared)
throws java.io.IOException
lock in class java.nio.channels.FileChanneljava.io.IOExceptionpublic java.nio.channels.FileLock tryLock(long position,
long size,
boolean shared)
throws java.io.IOException
tryLock in class java.nio.channels.FileChanneljava.io.IOException