Package com.mckoi.util
Class PagedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.mckoi.util.PagedInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public abstract class PagedInputStream extends java.io.InputStreamAn 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
Constructors Constructor Description PagedInputStream(int page_size, long total_size)Constructs the input stream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()voidmark(int limit)booleanmarkSupported()intread()intread(byte[] read_buf, int off, int len)protected abstract voidreadPageContent(byte[] buf, long pos, int length)Reads the page at the given offset in the underlying data into the given byte[] array.voidreset()longskip(long n)
-
-
-
Method Detail
-
readPageContent
protected abstract void readPageContent(byte[] buf, long pos, int length) throws java.io.IOExceptionReads 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:
java.io.IOException
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] read_buf, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.InputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
mark
public void mark(int limit)
- Overrides:
markin classjava.io.InputStream
-
reset
public void reset()
- Overrides:
resetin classjava.io.InputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classjava.io.InputStream
-
-