public class FileBuffer extends AbstractBuffer
File buffers wrap a simple RandomAccessFile instance to provide random access to a file on local disk. All
operations are delegated directly to the RandomAccessFile interface, and limitations are dependent on the
semantics of the underlying file.
| Modifier and Type | Method and Description |
|---|---|
static FileBuffer |
allocate(File file)
Allocates a file buffer of unlimited capacity.
|
static FileBuffer |
allocate(File file,
int initialCapacity)
Allocates a file buffer with the given initial capacity.
|
static FileBuffer |
allocate(File file,
int initialCapacity,
int maxCapacity)
Allocates a file buffer.
|
static FileBuffer |
allocate(File file,
String mode,
int initialCapacity,
int maxCapacity)
Allocates a file buffer.
|
void |
delete()
Deletes the underlying file.
|
FileBuffer |
duplicate()
Returns a duplicate of the buffer.
|
FileBuffer |
duplicate(String mode)
Duplicates the buffer using the given mode.
|
File |
file()
Returns the underlying file object.
|
MappedBuffer |
map(int size)
Maps a portion of the underlying file into memory in
FileChannel.MapMode#READ_WRITE mode
starting at the current position up to the given count. |
MappedBuffer |
map(int size,
FileChannel.MapMode mode)
Maps a portion of the underlying file into memory starting at the current position up to the given
count. |
MappedBuffer |
map(int offset,
int size)
Maps a portion of the underlying file into memory in
FileChannel.MapMode#READ_WRITE mode
starting at the given offset up to the given count. |
MappedBuffer |
map(int offset,
int size,
FileChannel.MapMode mode)
Maps a portion of the underlying file into memory starting at the given
offset up to the given count. |
acquire, asReadOnlyBuffer, bytes, capacity, capacity, clear, close, compact, flip, flush, hasRemaining, isDirect, isFile, isReadOnly, limit, limit, mark, maxCapacity, offset, order, order, position, position, read, read, read, read, read, read, read, readBoolean, readBoolean, readByte, readByte, readChar, readChar, readDouble, readDouble, readFloat, readFloat, readInt, readInt, readLong, readLong, readMedium, readMedium, readShort, readShort, readString, readString, readString, readString, readUnsignedByte, readUnsignedByte, readUnsignedInt, readUnsignedInt, readUnsignedMedium, readUnsignedMedium, readUnsignedShort, readUnsignedShort, readUTF8, readUTF8, references, release, remaining, reset, rewind, skip, slice, slice, slice, write, write, write, write, write, write, write, writeBoolean, writeBoolean, writeByte, writeByte, writeChar, writeChar, writeDouble, writeDouble, writeFloat, writeFloat, writeInt, writeInt, writeLong, writeLong, writeMedium, writeMedium, writeShort, writeShort, writeString, writeString, writeString, writeString, writeUnsignedByte, writeUnsignedByte, writeUnsignedInt, writeUnsignedInt, writeUnsignedMedium, writeUnsignedMedium, writeUnsignedShort, writeUnsignedShort, writeUTF8, writeUTF8, zero, zero, zeroequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitreadByteswriteBytespublic static FileBuffer allocate(File file)
The buffer will initially be allocated with 4096 bytes. As bytes are written to the resulting buffer and
the original capacity is reached, the buffer's capacity will double.
file - The file to allocate.allocate(File, int),
allocate(File, int, int),
allocate(File, String, int, int)public static FileBuffer allocate(File file, int initialCapacity)
If the underlying file is empty, the file count will expand dynamically as bytes are written to the file.
The underlying FileBytes will be initialized to the nearest power of 2.
file - The file to allocate.initialCapacity - The initial capacity of the bytes to allocate.allocate(File),
allocate(File, int, int),
allocate(File, String, int, int)public static FileBuffer allocate(File file, int initialCapacity, int maxCapacity)
The underlying RandomAccessFile will be created in rw mode by default.
The resulting buffer will be initialized with a capacity of initialCapacity. The underlying FileBytes
will be initialized to the nearest power of 2. As bytes are written to the file the buffer's capacity will
double up to maxCapacity.
file - The file to allocate.initialCapacity - The initial capacity of the buffer.maxCapacity - The maximum allowed capacity of the buffer.allocate(File),
allocate(File, int),
allocate(File, String, int, int)public static FileBuffer allocate(File file, String mode, int initialCapacity, int maxCapacity)
The resulting buffer will be initialized with a capacity of initialCapacity. The underlying FileBytes
will be initialized to the nearest power of 2. As bytes are written to the file the buffer's capacity will
double up to maxCapacity.
file - The file to allocate.mode - The mode in which to open the underlying RandomAccessFile.initialCapacity - The initial capacity of the buffer.maxCapacity - The maximum allowed capacity of the buffer.allocate(File),
allocate(File, int),
allocate(File, int, int)public File file()
public MappedBuffer map(int size)
FileChannel.MapMode#READ_WRITE mode
starting at the current position up to the given count.size - The count of the bytes to map into memory.IllegalArgumentException - If count is greater than the maximum allowed
MappedByteBuffer count: Integer.MAX_VALUEpublic MappedBuffer map(int size, FileChannel.MapMode mode)
count.size - The count of the bytes to map into memory.mode - The mode in which to map the bytes into memory.IllegalArgumentException - If count is greater than the maximum allowed
MappedByteBuffer count: Integer.MAX_VALUEpublic MappedBuffer map(int offset, int size)
FileChannel.MapMode#READ_WRITE mode
starting at the given offset up to the given count.offset - The offset from which to map bytes into memory.size - The count of the bytes to map into memory.IllegalArgumentException - If count is greater than the maximum allowed
MappedByteBuffer count: Integer.MAX_VALUEpublic MappedBuffer map(int offset, int size, FileChannel.MapMode mode)
offset up to the given count.offset - The offset from which to map bytes into memory.size - The count of the bytes to map into memory.mode - The mode in which to map the bytes into memory.IllegalArgumentException - If count is greater than the maximum allowed
MappedByteBuffer count: Integer.MAX_VALUEpublic FileBuffer duplicate()
Bufferpublic FileBuffer duplicate(String mode)
public void delete()
Copyright © 2013–2018. All rights reserved.