|
|||||||||
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
public abstract class SeekableInputStream
This class defines an extended InputStream which is seekable.
Field Summary | |
---|---|
protected int |
bitOffset
The current bit offset within the stream. |
protected ByteOrder |
byteOrder
The byte order of the stream as an instance of the enumeration class java.nio.ByteOrder , where ByteOrder.BIG_ENDIAN indicates network byte
order and ByteOrder.LITTLE_ENDIAN indicates the reverse order. |
protected long |
flushedPos
The position prior to which data may be discarded. |
Constructor Summary | |
---|---|
SeekableInputStream()
|
Method Summary | |
---|---|
protected void |
checkClosed()
Throws an IOException if the stream has been closed. |
void |
close()
Closes this seekable input stream. |
protected void |
finalize()
Finalizes this object prior to garbage collection. |
void |
flush()
|
void |
flushBefore(long pos)
|
int |
getBitOffset()
|
ByteOrder |
getByteOrder()
|
long |
getFlushedPosition()
|
abstract long |
getSizeEstimate()
A rough estimated size for this stream instance, which is used for internal cache management. |
boolean |
isCached()
Default implementation returns false. |
boolean |
isCachedFile()
Default implementation returns false. |
boolean |
isCachedMemory()
Default implementation returns false. |
abstract long |
length()
Returns the length of this stream contents, if available. |
void |
mark()
Pushes the current stream position onto a stack of marked positions. |
void |
mark(int readlimit)
|
abstract 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) . |
abstract int |
read(byte[] b,
int off,
int len)
Reads up to len bytes from the stream, and stores them into b
starting at index off . |
int |
readBit()
|
long |
readBits(int numBits)
|
boolean |
readBoolean()
|
byte |
readByte()
|
void |
readBytes(IIOByteBuffer buf,
int len)
|
char |
readChar()
|
double |
readDouble()
|
float |
readFloat()
|
void |
readFully(byte[] b)
|
void |
readFully(byte[] b,
int off,
int len)
|
void |
readFully(char[] c,
int off,
int len)
|
void |
readFully(double[] d,
int off,
int len)
|
void |
readFully(float[] f,
int off,
int len)
|
void |
readFully(int[] i,
int off,
int len)
|
void |
readFully(long[] l,
int off,
int len)
|
void |
readFully(short[] s,
int off,
int len)
|
int |
readInt()
|
int |
readInt(int appliedBytes)
Reads appliedBytes bytes from the stream, and (conceptually) concatenates them
according to the current byte order and returns the result as an int . |
String |
readLine()
|
long |
readLong()
|
short |
readShort()
|
int |
readUnsignedByte()
|
long |
readUnsignedInt()
|
long |
readUnsignedInt(int appliedBytes)
Reads appliedBytes bytes from the stream, and (conceptually) concatenates them
according to the current byte order, converts the result to a long, masks it with
0xffffffffL in order to strip off any sign-extension bits, and returns the result
as an unsigned long value. |
int |
readUnsignedShort()
|
String |
readUTF()
|
void |
reset()
Resets the current stream byte and bit positions from the stack of marked positions. |
void |
resetToInitialState()
Resets the current stream byte, bit positions from the stack of marked positions, the flushed position and seeks to 0 . |
abstract void |
seek(long pos)
Sets the current stream position, measured from the beginning of this data stream, at which the next read occurs. |
void |
setBitOffset(int bitOffset)
|
void |
setByteOrder(ByteOrder byteOrder)
|
long |
skip(long n)
|
int |
skipBytes(int n)
Advances the current stream position by calling seek(getStreamPosition() + n) . |
long |
skipBytes(long n)
Advances the current stream position by calling seek(getStreamPosition() + n) . |
Methods inherited from class java.io.InputStream |
---|
available, markSupported |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.imageio.stream.ImageInputStream |
---|
getStreamPosition |
Field Detail |
---|
protected ByteOrder byteOrder
java.nio.ByteOrder
, where ByteOrder.BIG_ENDIAN
indicates network byte
order and ByteOrder.LITTLE_ENDIAN
indicates the reverse order. By default, the
value is ByteOrder.BIG_ENDIAN
.
protected int bitOffset
protected long flushedPos
flushedPos
will always be >= 0.
Constructor Detail |
---|
public SeekableInputStream()
Method Detail |
---|
protected final void checkClosed() throws IOException
IOException
if the stream has been closed. Subclasses may call this
method from any of their methods that require the stream not to be closed.
IOException
- if the stream is closed.public void close() throws IOException
IOException
s. Additional attempts to close()
, however, have no effect.
close
in interface Closeable
close
in interface ImageInputStream
close
in class InputStream
IOException
InputStream.close()
protected void finalize() throws Throwable
close
method is called to
close any open input source. This method should not be called from application code.
finalize
in class Object
Throwable
- if an error occurs during superclass finalization.public void flush() throws IOException
flush
in interface ImageInputStream
IOException
ImageInputStream.flush()
public void flushBefore(long pos) throws IOException
flushBefore
in interface ImageInputStream
IOException
ImageInputStream.flushBefore(long)
public int getBitOffset() throws IOException
getBitOffset
in interface ImageInputStream
IOException
ImageInputStream.getBitOffset()
public ByteOrder getByteOrder()
getByteOrder
in interface ImageInputStream
ImageInputStream.getByteOrder()
public long getFlushedPosition()
getFlushedPosition
in interface ImageInputStream
ImageInputStream.getFlushedPosition()
public abstract long getSizeEstimate()
public boolean isCached()
isCached
in interface ImageInputStream
ImageInputStream.isCached()
public boolean isCachedFile()
isCachedFile
in interface ImageInputStream
ImageInputStream.isCachedFile()
public boolean isCachedMemory()
isCachedMemory
in interface ImageInputStream
ImageInputStream.isCachedMemory()
public abstract long length() throws IOException
length
in interface ImageInputStream
IOException
- if an I/O error occurs.public void mark()
mark
in interface ImageInputStream
public void mark(int readlimit)
mark
in class InputStream
public abstract int read() throws IOException
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 InputStream
-1
if EOF is reached.
IOException
- if the stream has been closed.public int read(byte[] b) throws IOException
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 InputStream
b
- the byte buffer to fill up
-1
to indicate EOF.
NullPointerException
- if b
is null
.
IOException
- if an I/O error occurs.public abstract int read(byte[] b, int off, int len) throws IOException
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 InputStream
b
- an array of bytes to be written to.off
- the starting position within b
to write to.len
- the maximum number of bytes to read.
-1
to indicate EOF.
IndexOutOfBoundsException
- if off
is negative, len
is
negative, or off +
len
is greater than b.length
.
NullPointerException
- if b
is null
.
IOException
- if an I/O error occurs.public int readBit() throws IOException
readBit
in interface ImageInputStream
IOException
ImageInputStream.readBit()
public long readBits(int numBits) throws IOException
readBits
in interface ImageInputStream
IOException
ImageInputStream.readBits(int)
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
readBoolean
in interface ImageInputStream
IOException
ImageInputStream.readBoolean()
public byte readByte() throws IOException
readByte
in interface DataInput
readByte
in interface ImageInputStream
IOException
ImageInputStream.readByte()
public void readBytes(IIOByteBuffer buf, int len) throws IOException
readBytes
in interface ImageInputStream
IOException
ImageInputStream.readBytes(javax.imageio.stream.IIOByteBuffer, int)
public char readChar() throws IOException
readChar
in interface DataInput
readChar
in interface ImageInputStream
IOException
ImageInputStream.readChar()
public double readDouble() throws IOException
readDouble
in interface DataInput
readDouble
in interface ImageInputStream
IOException
ImageInputStream.readDouble()
public float readFloat() throws IOException
readFloat
in interface DataInput
readFloat
in interface ImageInputStream
IOException
ImageInputStream.readFloat()
public void readFully(byte[] b) throws IOException
readFully
in interface DataInput
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(byte[])
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(byte[], int, int)
public void readFully(char[] c, int off, int len) throws IOException
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(char[], int, int)
public void readFully(double[] d, int off, int len) throws IOException
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(double[], int, int)
public void readFully(float[] f, int off, int len) throws IOException
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(float[], int, int)
public void readFully(int[] i, int off, int len) throws IOException
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(int[], int, int)
public void readFully(long[] l, int off, int len) throws IOException
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(long[], int, int)
public void readFully(short[] s, int off, int len) throws IOException
readFully
in interface ImageInputStream
IOException
ImageInputStream.readFully(short[], int, int)
public int readInt() throws IOException
readInt
in interface DataInput
readInt
in interface ImageInputStream
IOException
ImageInputStream.readInt()
public int readInt(int appliedBytes) throws IOException
appliedBytes
bytes from the stream, and (conceptually) concatenates them
according to the current byte order and returns the result as an int
. As
consequence, appliedBytes
have to be greater than 0 and smaller or equals than 4.
All other values of appliedBytes
will cause an IllegalArgumentException.
The bit offset within the stream is ignored and treated as though it were zero.
appliedBytes
-
EOFException
- if the stream reaches the end before reading all the bytes.
IOException
- if an I/O error occurs.getByteOrder()
public String readLine() throws IOException
readLine
in interface DataInput
readLine
in interface ImageInputStream
IOException
ImageInputStream.readLine()
public long readLong() throws IOException
readLong
in interface DataInput
readLong
in interface ImageInputStream
IOException
ImageInputStream.readLong()
public short readShort() throws IOException
readShort
in interface DataInput
readShort
in interface ImageInputStream
IOException
ImageInputStream.readShort()
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
readUnsignedByte
in interface ImageInputStream
IOException
ImageInputStream.readUnsignedByte()
public long readUnsignedInt() throws IOException
readUnsignedInt
in interface ImageInputStream
IOException
ImageInputStream.readUnsignedInt()
public long readUnsignedInt(int appliedBytes) throws IOException
appliedBytes
bytes from the stream, and (conceptually) concatenates them
according to the current byte order, converts the result to a long, masks it with
0xffffffffL
in order to strip off any sign-extension bits, and returns the result
as an unsigned long
value. As consequence, appliedBytes
have to be
greater than 0 and smaller or equals than 4. All other values of appliedBytes
will
cause an IllegalArgumentException.
The bit offset within the stream is reset to zero before the read occurs.
appliedBytes
-
EOFException
- if the stream reaches the end before reading all the bytes.
IOException
- if an I/O error occurs.getByteOrder()
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
readUnsignedShort
in interface ImageInputStream
IOException
ImageInputStream.readUnsignedShort()
public String readUTF() throws IOException
readUTF
in interface DataInput
readUTF
in interface ImageInputStream
IOException
ImageInputStream.readUTF()
public void reset() throws IOException
An IOException
will be thrown if the previous marked position lies in the
discarded portion of the stream.
reset
in interface ImageInputStream
reset
in class InputStream
IOException
- if an I/O error occurs.public void resetToInitialState() throws IOException
0
.
IOException
- if an I/O error occurs.public abstract void seek(long pos) throws IOException
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
pos
- a long
containing the desired file pointer position.
IndexOutOfBoundsException
- if pos
is smaller than the flushed position.
IOException
- if any other I/O error occurs.public void setBitOffset(int bitOffset) throws IOException
setBitOffset
in interface ImageInputStream
IOException
ImageInputStream.setBitOffset(int)
public void setByteOrder(ByteOrder byteOrder)
setByteOrder
in interface ImageInputStream
ImageInputStream.setByteOrder(java.nio.ByteOrder)
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public int skipBytes(int n) throws IOException
seek(getStreamPosition() + n)
.
The bit offset is reset to zero.
skipBytes
in interface DataInput
skipBytes
in interface ImageInputStream
n
- the number of bytes to seek forward.
int
representing the number of bytes skipped.
IOException
- if getStreamPosition
throws an IOException
when computing either the starting or ending position.public long skipBytes(long n) throws IOException
seek(getStreamPosition() + n)
.
The bit offset is reset to zero.
skipBytes
in interface ImageInputStream
n
- the number of bytes to seek forward.
long
representing the number of bytes skipped.
IOException
- if getStreamPosition
throws an IOException
when computing either the starting or ending position.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |