|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectInputStream
ChannelImageInputStream
public class ChannelImageInputStream
An Image Input Stream using a Readable Byte Channel as the data source. Using this class is similar to using the code below:
except that:import javax.imageio.ImageIO; import java.nio.channels.Channels; // Omitting class and method declaration... ReadableByteChannel channel = ...; ImageInputStream stream = ImageIO.createImageInputStream(Channels.newInputStream(channel));
InputStream and an ImageInputStream.ByteBuffer (by contrast,
the standard ImageInputStreamImpl performs many work
itself, including the byte order handling).ByteBuffer supplied by the caller.
FileImageInputStream,
ImageInputStreamImpl,
ImageIO.createImageInputStream(Object),
Channels.newInputStream(ReadableByteChannel)
| coverage/geotk-coverageio (download) | View source code for this class |
| Field Summary | |
|---|---|
protected ByteBuffer |
buffer
The byte buffer to use for reading bytes from the channel. |
protected ReadableByteChannel |
channel
The channel from which to read bytes. |
| Constructor Summary | |
|---|---|
ChannelImageInputStream(ReadableByteChannel channel,
ByteBuffer buffer)
Creates a new image input stream using the given channel and buffer. |
|
ChannelImageInputStream(ReadableByteChannel channel,
int size)
Creates a new image input stream using the given channel. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the channel. |
void |
flush()
Discards the initial position of the stream prior to the current stream position. |
void |
flushBefore(long pos)
Discards the initial portion of the stream prior to the indicated postion. |
int |
getBitOffset()
Returns the current bit offset, as an integer between 0 and 7 inclusive. |
ByteOrder |
getByteOrder()
Returns the byte order with which data values will be read from this stream. |
long |
getFlushedPosition()
Returns the earliest position in the stream to which seeking may be performed. |
long |
getStreamPosition()
Returns the current byte position of the stream. |
boolean |
isCached()
Returns true if this ImageInputStream caches data itself in order to
allow seeking backwards. |
boolean |
isCachedFile()
Returns true if this ImageInputStream caches data itself in order to
allow seeking backwards, and the cache is kept in a temporary
file. |
boolean |
isCachedMemory()
Returns true if this ImageInputStream caches data itself in order to
allow seeking backwards, and the cache is kept in main memory. |
long |
length()
Returns the length of the stream (in bytes), or -1 if unknown. |
void |
mark()
Pushes the current stream position onto a stack of marked positions. |
int |
read()
Reads a single byte from the stream and returns it as an int between 0 and 255. |
int |
read(byte[] dest)
Reads up to dest.length bytes from the stream, and stores them into
dest starting at index 0. |
int |
read(byte[] dest,
int offset,
int length)
Reads up to length bytes from the stream, and stores them into dest
starting at index offset. |
int |
readBit()
Reads a single bit from the stream. |
long |
readBits(int numBits)
Reads many bits from the stream. |
boolean |
readBoolean()
Reads a byte from the stream and returns a true if it is nonzero,
false otherwise. |
byte |
readByte()
Reads a byte from the stream. |
void |
readBytes(IIOByteBuffer dest,
int length)
Reads up to length bytes from the stream, and modifies the supplied
IIOByteBuffer to indicate the byte array, offset, and length where
the data may be found. |
char |
readChar()
Reads a character from the stream. |
double |
readDouble()
Reads a double from the stream. |
float |
readFloat()
Reads a float from the stream. |
void |
readFully(byte[] dest)
Reads dest.length bytes from the stream, and stores them into
dest starting at index 0. |
void |
readFully(byte[] dest,
int offset,
int length)
Reads length bytes from the stream, and stores them into
dest starting at index offset. |
void |
readFully(char[] dest,
int offset,
int length)
Reads length characters from the stream, and stores them into
dest starting at index offset. |
void |
readFully(double[] dest,
int offset,
int length)
Reads length doubles from the stream, and stores them into
dest starting at index offset. |
void |
readFully(float[] dest,
int offset,
int length)
Reads length floats from the stream, and stores them into
dest starting at index offset. |
void |
readFully(int[] dest,
int offset,
int length)
Reads length ints from the stream, and stores them into
dest starting at index offset. |
void |
readFully(long[] dest,
int offset,
int length)
Reads length longs from the stream, and stores them into
dest starting at index offset. |
void |
readFully(short[] dest,
int offset,
int length)
Reads length shorts from the stream, and stores them into
dest starting at index offset. |
int |
readInt()
Reads an integer from the stream. |
String |
readLine()
Reads the new bytes until the next EOL. |
long |
readLong()
Reads a long from the stream. |
short |
readShort()
Reads a short from the stream. |
int |
readUnsignedByte()
Reads a unsigned byte from the stream. |
long |
readUnsignedInt()
Reads a unsigned integer from the stream. |
int |
readUnsignedShort()
Reads a unsigned short from the stream. |
String |
readUTF()
Reads in a string that has been encoded using a UTF-8 string. |
void |
reset()
Resets the current stream byte and bit positions from the stack of marked positions. |
void |
seek(long pos)
Sets the current stream position to the desired location. |
void |
setBitOffset(int bitOffset)
Sets the bit offset to the given value. |
void |
setByteOrder(ByteOrder byteOrder)
Sets the desired byte order for future reads of data values from this stream. |
int |
skipBytes(int n)
Advances the current stream position by the given amount of bytes. |
long |
skipBytes(long n)
Advances the current stream position by the given amount of bytes. |
| Methods inherited from class InputStream |
|---|
available, mark, markSupported, skip |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final ReadableByteChannel channel
protected final ByteBuffer buffer
| Constructor Detail |
|---|
public ChannelImageInputStream(ReadableByteChannel channel,
int size)
channel - The channel to use.size - The buffer size.
public ChannelImageInputStream(ReadableByteChannel channel,
ByteBuffer buffer)
buffer.clear().limit(0);
channel - The channel to use.buffer - The buffer to use.| Method Detail |
|---|
public void setByteOrder(ByteOrder byteOrder)
BIG_ENDIAN.
setByteOrder in interface ImageInputStreampublic ByteOrder getByteOrder()
getByteOrder in interface ImageInputStream
public long length()
throws IOException
length in interface ImageInputStreamIOException - If an error occurred while fetching the stream length.public long getFlushedPosition()
getFlushedPosition in interface ImageInputStream
public long getStreamPosition()
throws IOException
getStreamPosition in interface ImageInputStreamIOException - if an I/O error occurs.
public int getBitOffset()
throws IOException
read methods except readBit()
and readBits(int).
getBitOffset in interface ImageInputStreamIOException - if an I/O error occurs.
public void setBitOffset(int bitOffset)
throws IOException
read methods except readBit() and readBits(int).
setBitOffset in interface ImageInputStreambitOffset - The new bit offset of the stream.
IOException - if an I/O error occurs.
public int read()
throws IOException
read in interface ImageInputStreamread in class InputStream-1 on EOF.
IOException - If an error occurred while reading.
public int readBit()
throws IOException
read methods except readBit() and readBits(int).
readBit in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public long readBits(int numBits)
throws IOException
read methods except readBit() and readBits(int).
readBits in interface ImageInputStreamnumBits - The number of bits to read.
IOException - If an error occurred while reading (including EOF).
public boolean readBoolean()
throws IOException
true if it is nonzero,
false otherwise. The default implementation is as below:
return readByte() != 0;
readBoolean in interface DataInputreadBoolean in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public byte readByte()
throws IOException
ByteBuffer.get().
readByte in interface DataInputreadByte in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public int readUnsignedByte()
throws IOException
return readByte() & 0xFF;
readUnsignedByte in interface DataInputreadUnsignedByte in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public short readShort()
throws IOException
ByteBuffer.getShort().
readShort in interface DataInputreadShort in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public int readUnsignedShort()
throws IOException
return readShort() & 0xFFFF;
readUnsignedShort in interface DataInputreadUnsignedShort in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public char readChar()
throws IOException
ByteBuffer.getChar().
readChar in interface DataInputreadChar in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public int readInt()
throws IOException
ByteBuffer.getInt().
readInt in interface DataInputreadInt in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public long readUnsignedInt()
throws IOException
return readInt() & 0xFFFFFFFFL;
readUnsignedInt in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public long readLong()
throws IOException
ByteBuffer.getLong().
readLong in interface DataInputreadLong in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public float readFloat()
throws IOException
ByteBuffer.getFloat().
readFloat in interface DataInputreadFloat in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public double readDouble()
throws IOException
ByteBuffer.getDouble().
readDouble in interface DataInputreadDouble in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public String readLine()
throws IOException
readLine in interface DataInputreadLine in interface ImageInputStreamnull if the EOF has been reached.
IOException - If an error occurred while reading.
public String readUTF()
throws IOException
readUTF in interface DataInputreadUTF in interface ImageInputStreamIOException - If an error occurred while reading (including EOF).
public void readBytes(IIOByteBuffer dest,
int length)
throws IOException
length bytes from the stream, and modifies the supplied
IIOByteBuffer to indicate the byte array, offset, and length where
the data may be found.
readBytes in interface ImageInputStreamdest - The buffer to be written to.length - The maximum number of bytes to read.
IOException - If an error occurred while reading.
public int read(byte[] dest)
throws IOException
dest.length bytes from the stream, and stores them into
dest starting at index 0. The default implementation is as below:
return read(dest, 0, dest.length);
read in interface ImageInputStreamread in class InputStreamdest - An array of bytes to be written to.
IOException - If an error occurred while reading.
public int read(byte[] dest,
int offset,
int length)
throws IOException
length bytes from the stream, and stores them into dest
starting at index offset. If no bytes can be read because the end of the stream
has been reached, -1 is returned.
read in interface ImageInputStreamread in class InputStreamdest - An array of bytes to be written to.offset - The starting position withing dest to write.length - The maximum number of bytes to read.
IOException - If an error occurred while reading.
public void readFully(byte[] dest)
throws IOException
dest.length bytes from the stream, and stores them into
dest starting at index 0. The default implementation is as below:
return readFully(dest, 0, dest.length);
readFully in interface DataInputreadFully in interface ImageInputStreamdest - An array of bytes to be written to.
IOException - If an error occurred while reading.
public void readFully(byte[] dest,
int offset,
int length)
throws IOException
length bytes from the stream, and stores them into
dest starting at index offset.
readFully in interface DataInputreadFully in interface ImageInputStreamdest - An array of bytes to be written to.offset - The starting position withing dest to write.length - The number of bytes to read.
IOException - If an error occurred while reading (including EOF).
public void readFully(char[] dest,
int offset,
int length)
throws IOException
length characters from the stream, and stores them into
dest starting at index offset.
readFully in interface ImageInputStreamdest - An array of characters to be written to.offset - The starting position withing dest to write.length - The number of characters to read.
IOException - If an error occurred while reading (including EOF).
public void readFully(short[] dest,
int offset,
int length)
throws IOException
length shorts from the stream, and stores them into
dest starting at index offset.
readFully in interface ImageInputStreamdest - An array of shorts to be written to.offset - The starting position withing dest to write.length - The number of shorts to read.
IOException - If an error occurred while reading (including EOF).
public void readFully(int[] dest,
int offset,
int length)
throws IOException
length ints from the stream, and stores them into
dest starting at index offset.
readFully in interface ImageInputStreamdest - An array of ints to be written to.offset - The starting position withing dest to write.length - The number of ints to read.
IOException - If an error occurred while reading (including EOF).
public void readFully(long[] dest,
int offset,
int length)
throws IOException
length longs from the stream, and stores them into
dest starting at index offset.
readFully in interface ImageInputStreamdest - An array of longs to be written to.offset - The starting position withing dest to write.length - The number of longs to read.
IOException - If an error occurred while reading (including EOF).
public void readFully(float[] dest,
int offset,
int length)
throws IOException
length floats from the stream, and stores them into
dest starting at index offset.
readFully in interface ImageInputStreamdest - An array of floats to be written to.offset - The starting position withing dest to write.length - The number of floats to read.
IOException - If an error occurred while reading (including EOF).
public void readFully(double[] dest,
int offset,
int length)
throws IOException
length doubles from the stream, and stores them into
dest starting at index offset.
readFully in interface ImageInputStreamdest - An array of doubles to be written to.offset - The starting position withing dest to write.length - The number of shorts to read.
IOException - If an error occurred while reading (including EOF).
public int skipBytes(int n)
throws IOException
return (int) skipBytes((long) n);
skipBytes in interface DataInputskipBytes in interface ImageInputStreamn - The number of bytes to seek forward.
IOException - If an error occurred while skiping.
public long skipBytes(long n)
throws IOException
skipBytes in interface ImageInputStreamn - The number of bytes to seek forward.
IOException - If an error occurred while skiping.
public void seek(long pos)
throws IOException,
IllegalArgumentException
seek in interface ImageInputStreampos - The new stream position.
IOException - If an I/O error occurred.
IllegalArgumentException - If the given position is before the
flushed position.public void mark()
mark in interface ImageInputStream
public void reset()
throws IOException
IOException will be thrown if the previous marked position lies in the
discarded portion of the stream.
reset in interface ImageInputStreamreset in class InputStreamIOException - If an I/O error occurs.
public void flush()
throws IOException
flushBefore(getStreamPosition());
flush in interface ImageInputStreamIOException - If an I/O error occurred.
public void flushBefore(long pos)
throws IOException
IndexOutOfBoundsException.
flushBefore in interface ImageInputStreampos - The length of the stream prefix that may be flushed.
IOException - If an I/O error occurred.public boolean isCached()
true if this ImageInputStream caches data itself in order to
allow seeking backwards. The default implementation returns
false.
isCached in interface ImageInputStreamtrue If this ImageInputStream caches data.isCachedMemory(),
isCachedFile()public boolean isCachedMemory()
true if this ImageInputStream caches data itself in order to
allow seeking backwards, and the cache is kept in main memory.
The default implementation returns false.
isCachedMemory in interface ImageInputStreamtrue if this ImageInputStream caches data in main memory.public boolean isCachedFile()
true if this ImageInputStream caches data itself in order to
allow seeking backwards, and the cache is kept in a temporary
file. The default implementation returns false.
isCachedFile in interface ImageInputStreamtrue if this ImageInputStream caches data in a temporary file.
public void close()
throws IOException
close in interface Closeableclose in interface ImageInputStreamclose in class InputStreamIOException - If an error occurred while closing the channel.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||