Package com.mckoi.util
Class PagedInputStream
java.lang.Object
java.io.InputStream
com.mckoi.util.PagedInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
An implementation of InputStream that reads data from an underlying
representation in fixed sized pages. This object maintains a single buffer
that is the size of a page. This implementation supports 'skip' and
buffered access to the data.
The only method that needs to be implemented is the 'readPageContent' method.
- Author:
- Tobias Downer
-
Constructor Summary
ConstructorsConstructorDescriptionPagedInputStream
(int page_size, long total_size) Constructs the input stream. -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
void
mark
(int limit) boolean
int
read()
int
read
(byte[] read_buf, int off, int len) protected abstract void
readPageContent
(byte[] buf, long pos, int length) Reads the page at the given offset in the underlying data into the given byte[] array.void
reset()
long
skip
(long n) Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
PagedInputStream
public PagedInputStream(int page_size, long total_size) Constructs the input stream.- Parameters:
page_size
- the size of the pages when accessing the underlying stream.total_size
- the total size of the underlying data set.
-
-
Method Details
-
readPageContent
Reads the page at the given offset in the underlying data into the given byte[] array. The 'pos' variable given is guarenteed to be a multiple of buffer_size. For example, the first access will be to pos = 0, the second access to pos = BUFFER_SIZE, the third access to pos = BUFFER_SIZE * 2, etc. 'length' will always be either BUFFER_SIZE or a value smaller than BUFFER_SIZE if the page containing the end of the stream is read.- Throws:
IOException
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int limit) - Overrides:
mark
in classInputStream
-
reset
public void reset()- Overrides:
reset
in classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-