RandomAccess as sequence of multiple fixed size pages handled
by ScratchFile.
| Modifier and Type | Field and Description |
|---|---|
| private byte[] | currentPage
The current page data. |
| private boolean | currentPageContentChanged
|
| private long | currentPageOffset
The offset of the current page within this buffer. |
| private int | currentPagePositionInPageIndexes
Index of current page in |
| private int | pageCount
number of pages held by this buffer |
| private ScratchFile | pageHandler
The underlying page handler. |
| private int[] | pageIndexes
contains ordered list of pages with the index the page is known by page handler ( |
| private final int | |
| private int | positionInPage
The current position (for next read/write) of the buffer as an offset in the current page. |
| private long | size
The number of bytes of content in this buffer. |
| Access | Constructor and Description |
|---|---|
| pack-priv | ScratchFileBuffer(ScratchFile
The pageHandler)ScratchFile managing the pages to be used by this buffer.Creates a new buffer using pages handled by provided |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | checkClosed()
Checks if this buffer, or the underlying |
| public final void | |
| public void | close()
Implements java. Closes this stream and releases any system resources associated with it. |
| pack-priv void | close(boolean
remove buffer from ScratchFile if set to true removeBuffer)Release all resources and remove this buffer from ScratchFile. |
| 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. |
| private boolean | Returns: true if we were successful positioning pointer before end of page;
we might return false if it is not allowed to add another page
and current pointer points at end of last pageif addNewPageIfNeeded)true it is allowed to add a new page in case
we are currently at end of last buffer pageEnsures the current page has at least one byte left
( |
| 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. |
| public void | seek(long
The position to seek to. seekToPosition)Implements org. Seek to a position in the data. |
| public void | write(int
The byte to write. b)Implements org. Write a byte to the stream. |
| public void | write(byte[]
The buffer to get the data from. b)Implements org. Write a buffer of data to the stream. |
| public void | write(byte[]
The buffer to get the data from. b, int An offset into the buffer to get the data from. off, int The length of data to write. len)Implements org. Write a buffer of data to the stream. |
| currentPage | back to summary |
|---|---|
| private byte[] currentPage The current page data. | |
| currentPageContentChanged | back to summary |
|---|---|
| private boolean currentPageContentChanged
| |
| currentPageOffset | back to summary |
|---|---|
| private long currentPageOffset The offset of the current page within this buffer. | |
| currentPagePositionInPageIndexes | back to summary |
|---|---|
| private int currentPagePositionInPageIndexes Index of current page in | |
| pageCount | back to summary |
|---|---|
| private int pageCount number of pages held by this buffer | |
| pageHandler | back to summary |
|---|---|
| private ScratchFile pageHandler The underlying page handler. | |
| pageIndexes | back to summary |
|---|---|
| private int[] pageIndexes contains ordered list of pages with the index the page is known by page handler ( | |
| pageSize | back to summary |
|---|---|
| private final int pageSize | |
| positionInPage | back to summary |
|---|---|
| private int positionInPage The current position (for next read/write) of the buffer as an offset in the current page. | |
| size | back to summary |
|---|---|
| private long size The number of bytes of content in this buffer. | |
| ScratchFileBuffer | back to summary |
|---|---|
| pack-priv ScratchFileBuffer(ScratchFile pageHandler) throws IOException Creates a new buffer using pages handled by provided
| |
| addPage | back to summary |
|---|---|
| private void addPage() throws IOException Adds a new page and positions all pointers to start of new page.
| |
| checkClosed | back to summary |
|---|---|
| private void checkClosed() throws IOException Checks if this buffer, or the underlying
| |
| clear | back to summary |
|---|---|
| public final void clear() throws IOException Implements org. Doc from org. Clears all data of the buffer.
| |
| 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
| |
| close | back to summary |
|---|---|
| pack-priv void close(boolean removeBuffer) Release all resources and remove this buffer from ScratchFile.
| |
| 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.
| |
| ensureAvailableBytesInPage | back to summary |
|---|---|
| private boolean ensureAvailableBytesInPage(boolean addNewPageIfNeeded) throws IOException Ensures the current page has at least one byte left
( If this is not the case we go to next page (writing current one if changed). If current buffer has no more pages we add a new one.
| |
| 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.
| |
| seek | back to summary |
|---|---|
| public void seek(long seekToPosition) throws IOException Implements org. Doc from org. Seek to a position in the data.
| |
| write | back to summary |
|---|---|
| public void write(int b) throws IOException Implements org. Doc from org. Write a byte to the stream.
| |
| write | back to summary |
|---|---|
| public void write(byte[] b) throws IOException Implements org. Doc from org. Write a buffer of data to the stream.
| |
| write | back to summary |
|---|---|
| public void write(byte[] b, int off, int len) throws IOException Implements org. Doc from org. Write a buffer of data to the stream.
| |