|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream com.levigo.jadice.document.io.SeekableInputStream com.levigo.jadice.document.io.MemoryInputStream
public class MemoryInputStream
A SeekableInputStream which decorates a plain InputStream with seekability by using an in-memory cache. Configurable: jadice.io.memoryInputStream.blocksize integer 2048 The block size to use when buffering input data in memory.
Field Summary |
---|
Fields inherited from class com.levigo.jadice.document.io.SeekableInputStream |
---|
bitOffset, byteOrder, flushedPos |
Constructor Summary | |
---|---|
MemoryInputStream(byte[] data)
Construct a new MemoryInputStream which reads from exactly one data block. |
|
MemoryInputStream(InputStream is)
Constructs a new MemoryInputStream which wraps the given InputStream and uses the default block size of 2048 bytes. |
|
MemoryInputStream(InputStream is,
int blockSize)
Constructs a new MemoryInputStream which wraps the given InputStream and uses the given block size. |
|
MemoryInputStream(InputStream is,
int blockSize,
boolean forcePrefetch)
Constructs a new MemoryInputStream which wraps the given InputStream and uses the given block size. |
Method Summary | |
---|---|
int |
available()
|
void |
close()
Closes this seekable input stream. |
protected void |
finalize()
Finalizes this object prior to garbage collection. |
static int |
getDefaultBlockSize()
Get the default block size to use. |
long |
getSizeEstimate()
A rough estimated size for this stream instance, which is used for internal cache management. |
long |
getStreamPosition()
|
boolean |
isCached()
Returns true since this ImageInputStream caches data in order to
allow seeking backwards. |
boolean |
isCachedFile()
Returns false since this ImageInputStream does not maintain a file
cache. |
boolean |
isCachedMemory()
Returns true since this ImageInputStream maintains a main memory
cache. |
long |
length()
Returns the length of this stream contents, if available. |
int |
read()
Reads a single byte from the stream and returns it as an int between 0 and 255. |
int |
read(byte[] b)
A convenience method that calls read(b, 0, b.length) . |
int |
read(byte[] buffer,
int offset,
int length)
Reads up to len bytes from the stream, and stores them into b
starting at index off . |
void |
seek(long position)
Sets the current stream position, measured from the beginning of this data stream, at which the next read occurs. |
static void |
setDefaultBlockSize(int defaultBlockSize)
Set the default block size to use. |
Methods inherited from class com.levigo.jadice.document.io.SeekableInputStream |
---|
checkClosed, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, mark, mark, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readInt, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedInt, readUnsignedShort, readUTF, reset, resetToInitialState, setBitOffset, setByteOrder, skip, skipBytes, skipBytes |
Methods inherited from class java.io.InputStream |
---|
markSupported |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MemoryInputStream(InputStream is, int blockSize) throws IOException
is
- the input streamblockSize
- the used data block size in bytes. Caused by performance and memory reasons
this value should be a multiple of 1024 greater than 1MB. If this value is smaller
than 1024 bytes, a minimal block size of 1024 will be assumed.
IOException
public MemoryInputStream(InputStream is, int blockSize, boolean forcePrefetch) throws IOException
is
- the input streamblockSize
- the used data block size in bytes. Caused by performance and memory reasons
this value should be a multiple of 1024 greater than 1MB. If this value is smaller
than 1024 bytes, a minimal block size of 1024 will be assumed.forcePrefetch,
- whether the first block of data should be pre-fetched or not.
IOException
public MemoryInputStream(InputStream is) throws IOException
is
-
IOException
public MemoryInputStream(byte[] data)
data
- Method Detail |
---|
public int read(byte[] b) throws IOException
SeekableInputStream
read(b, 0, b.length)
.
The bit offset within the stream is reset to zero before the read occurs.
read
in interface ImageInputStream
read
in class SeekableInputStream
b
- the byte buffer to fill up
-1
to indicate EOF.
IOException
- if an I/O error occurs.InputStream.read(byte[])
public int read(byte[] buffer, int offset, int length) throws IOException
SeekableInputStream
len
bytes from the stream, and stores them into b
starting at index off
. If no bytes can be read because the end of the stream has
been reached, -1
is returned.
The bit offset within the stream must be reset to zero before the read occurs.
Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting.
read
in interface ImageInputStream
read
in class SeekableInputStream
buffer
- an array of bytes to be written to.offset
- the starting position within b
to write to.length
- the maximum number of bytes to read.
-1
to indicate EOF.
IOException
- if an I/O error occurs.InputStream.read(byte[], int, int)
public int read() throws IOException
SeekableInputStream
int
between 0 and 255. If
EOF is reached, -1
is returned.
Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting.
The bit offset within the stream must be reset to zero before the read occurs.
read
in interface ImageInputStream
read
in class SeekableInputStream
-1
if EOF is reached.
IOException
- if the stream has been closed.InputStream.read()
public void seek(long position) throws IOException
SeekableInputStream
EOFException
will be thrown
only if a read is performed. The bit offset is set to 0.
An IndexOutOfBoundsException
will be thrown if pos
is smaller than
the flushed position (as returned by getflushedPosition
).
It is legal to seek past the end of the file; an EOFException
will be thrown only
if a read is performed.
seek
in interface ImageInputStream
seek
in class SeekableInputStream
position
- a long
containing the desired file pointer position.
IOException
- if any other I/O error occurs.ImageInputStream.seek(long)
public void close() throws IOException
SeekableInputStream
IOException
s. Additional attempts to SeekableInputStream.close()
, however, have no effect.
close
in interface Closeable
close
in interface ImageInputStream
close
in class SeekableInputStream
IOException
InputStream.close()
protected void finalize() throws Throwable
SeekableInputStream
close
method is called to
close any open input source. This method should not be called from application code.
finalize
in class SeekableInputStream
Throwable
- if an error occurs during superclass finalization.Object.finalize()
public int available() throws IOException
available
in class InputStream
IOException
InputStream.available()
public long getStreamPosition() throws IOException
IOException
ImageInputStream.getStreamPosition()
public long length() throws IOException
SeekableInputStream
length
in interface ImageInputStream
length
in class SeekableInputStream
IOException
- if an I/O error occurs.ImageInputStream.length()
public boolean isCached()
true
since this ImageInputStream
caches data in order to
allow seeking backwards.
isCached
in interface ImageInputStream
isCached
in class SeekableInputStream
true
.isCachedMemory()
,
isCachedFile()
public boolean isCachedFile()
false
since this ImageInputStream
does not maintain a file
cache.
isCachedFile
in interface ImageInputStream
isCachedFile
in class SeekableInputStream
false
.isCached()
,
isCachedMemory()
public boolean isCachedMemory()
true
since this ImageInputStream
maintains a main memory
cache.
isCachedMemory
in interface ImageInputStream
isCachedMemory
in class SeekableInputStream
true
.isCached()
,
isCachedFile()
public long getSizeEstimate()
SeekableInputStream
getSizeEstimate
in class SeekableInputStream
public static void setDefaultBlockSize(int defaultBlockSize)
defaultBlockSize
- public static int getDefaultBlockSize()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |