FileChannel and is read in ByteBuffer chunks which are cached.
| Modifier and Type | Field and Description |
|---|---|
| private ByteBuffer | |
| private long | |
| private final FileChannel | |
| private final long | |
| private long | |
| private boolean | |
| private ByteBuffer | |
| private static final int | |
| private int | |
| private static final long | |
| private static final int | |
| private static final int | |
| private final Map | pageCache
Create a LRU page cache. |
| private final Path | |
| private final ConcurrentMap |
| Access | Constructor and Description |
|---|---|
| public | RandomAccessReadBufferedFile(String
the filename of the file to be read. filename)Create a random access buffered file instance for the file with the given name. |
| public | RandomAccessReadBufferedFile(File
the file to be read. file)Create a random access buffered file instance for the given file. |
| public | RandomAccessReadBufferedFile(Path
path of the file to be read. path)Create a random access buffered file instance using the given path. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | close()
Implements java. Closes this stream and releases any system resources associated with it. |
| public RandomAccessReadView | createView(long
start position within the underlying random access read startPosition, long stream length streamLength)Implements org. Creates a random access read view starting at the given position with the given length. |
| public long | getPosition()
Implements org. Returns offset of next byte to be returned by a read method. |
| public boolean | isClosed()
Implements org. Returns true if this source has been closed. |
| public boolean | isEOF()
Implements org. A simple test to see if we are at the end of the data. |
| public long | length()
Implements org. The total number of bytes that are available. |
| public int | |
| public int | read(byte[]
The buffer to write the data to. b, int Offset into the buffer to start writing. off, int The amount of data to attempt to read. len)Implements org. Read a buffer of data. |
| private ByteBuffer | |
| public void | seek(final long
the position to seek to. position)Implements org. Seeks to new position. |
| curPage | back to summary |
|---|---|
| private ByteBuffer curPage | |
| curPageOffset | back to summary |
|---|---|
| private long curPageOffset | |
| fileChannel | back to summary |
|---|---|
| private final FileChannel fileChannel | |
| fileLength | back to summary |
|---|---|
| private final long fileLength | |
| fileOffset | back to summary |
|---|---|
| private long fileOffset | |
| isClosed | back to summary |
|---|---|
| private boolean isClosed | |
| lastRemovedCachePage | back to summary |
|---|---|
| private ByteBuffer lastRemovedCachePage | |
| MAX_CACHED_PAGES | back to summary |
|---|---|
| private static final int MAX_CACHED_PAGES | |
| offsetWithinPage | back to summary |
|---|---|
| private int offsetWithinPage | |
| PAGE_OFFSET_MASK | back to summary |
|---|---|
| private static final long PAGE_OFFSET_MASK | |
| PAGE_SIZE | back to summary |
|---|---|
| private static final int PAGE_SIZE | |
| PAGE_SIZE_SHIFT | back to summary |
|---|---|
| private static final int PAGE_SIZE_SHIFT | |
| pageCache | back to summary |
|---|---|
| private final Map<Long, ByteBuffer> pageCache Create a LRU page cache. | |
| path | back to summary |
|---|---|
| private final Path path | |
| rafCopies | back to summary |
|---|---|
| private final ConcurrentMap<Long, RandomAccessReadBufferedFile> rafCopies | |
| RandomAccessReadBufferedFile | back to summary |
|---|---|
| public RandomAccessReadBufferedFile(String filename) throws IOException Create a random access buffered file instance for the file with the given name.
| |
| RandomAccessReadBufferedFile | back to summary |
|---|---|
| public RandomAccessReadBufferedFile(File file) throws IOException Create a random access buffered file instance for the given file.
| |
| RandomAccessReadBufferedFile | back to summary |
|---|---|
| public RandomAccessReadBufferedFile(Path path) throws IOException Create a random access buffered file instance using the given path.
| |
| checkClosed | back to summary |
|---|---|
| private void checkClosed() throws IOException Ensure that the RandomAccessBuffer is not closed
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in
| |
| createView | back to summary |
|---|---|
| public RandomAccessReadView createView(long startPosition, long streamLength) throws IOException Implements org. Doc from org. Creates a random access read view starting at the given position with the given length.
| |
| getPosition | back to summary |
|---|---|
| public long getPosition() throws IOException Implements org. Doc from org. Returns offset of next byte to be returned by a read method.
| |
| isClosed | back to summary |
|---|---|
| public boolean isClosed() Implements org. Doc from org. Returns true if this source has been closed.
| |
| isEOF | back to summary |
|---|---|
| public boolean isEOF() throws IOException Implements org. Doc from org. A simple test to see if we are at the end of the data.
| |
| length | back to summary |
|---|---|
| public long length() throws IOException Implements org. Doc from org. The total number of bytes that are available.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements org. Doc from org. Read a single byte of data.
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Implements org. Doc from org. Read a buffer of data.
| |
| readPage | back to summary |
|---|---|
| private ByteBuffer readPage() throws IOException Reads a page with data from current file position. If we have a previously removed page from cache the buffer of this page is reused. Otherwise a new byte buffer is created. | |
| seek | back to summary |
|---|---|
| public void seek(final long position) throws IOException Implements org. Seeks to new position. If new position is outside of current page the new page is either taken from cache or read from file and added to cache.
| |