Class IISRandomAccessIO
- java.lang.Object
-
- com.sun.media.imageioimpl.plugins.jpeg2000.IISRandomAccessIO
-
- All Implemented Interfaces:
BinaryDataInput
,BinaryDataOutput
,RandomAccessIO
public class IISRandomAccessIO extends Object implements RandomAccessIO
A wrapper for converting anImageInputStream
into aRandomAccessIO
. The resulting class is read-only.
-
-
Constructor Summary
Constructors Constructor Description IISRandomAccessIO(ImageInputStream iis)
Creates aRandomAccessIO
instance from the suppliedImageInputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the I/O stream.void
flush()
A null operation as writing is not supported.int
getByteOrdering()
Returns the endianess (i.e., byte ordering) of the implementing class.int
getPos()
Returns the stream position clamped to a maximum ofInteger.MAX_VALUE
.int
length()
Returns the length of the data stream.int
read()
Reads a byte of data from the stream.byte
readByte()
Should read a signed byte (i.e., 8 bit) from the input.double
readDouble()
Should read an IEEE double precision (i.e., 64 bit) floating-point number from the input.float
readFloat()
Should read an IEEE single precision (i.e., 32 bit) floating-point number from the input.void
readFully(byte[] b, int off, int n)
Reads up to len bytes of data from this file into an array of bytes.int
readInt()
Should read a signed int (i.e., 32 bit) from the input.long
readLong()
Should read a signed long (i.e., 64 bit) from the input.short
readShort()
Should read a signed short (i.e., 16 bit) from the input.int
readUnsignedByte()
Should read an unsigned byte (i.e., 8 bit) from the input.long
readUnsignedInt()
Should read an unsigned int (i.e., 32 bit) from the input.int
readUnsignedShort()
Should read an unsigned short (i.e., 16 bit) from the input.void
seek(int off)
Moves the current position for the next read or write operation to offset.int
skipBytes(int n)
Skips n bytes from the input.void
write(int b)
Throws anIOException
as writing is not supported.void
writeByte(int v)
Throws anIOException
as writing is not supported.void
writeDouble(double v)
Throws anIOException
as writing is not supported.void
writeFloat(float v)
Throws anIOException
as writing is not supported.void
writeInt(int v)
Throws anIOException
as writing is not supported.void
writeLong(long v)
Throws anIOException
as writing is not supported.void
writeShort(int v)
Throws anIOException
as writing is not supported.
-
-
-
Constructor Detail
-
IISRandomAccessIO
public IISRandomAccessIO(ImageInputStream iis)
Creates aRandomAccessIO
instance from the suppliedImageInputStream
.- Parameters:
iis
- The sourceImageInputStream
.
-
-
Method Detail
-
close
public void close() throws IOException
Description copied from interface:RandomAccessIO
Closes the I/O stream. Prior to closing the stream, any buffered data (at the bit and byte level) should be written.- Specified by:
close
in interfaceRandomAccessIO
- Throws:
IOException
- If an I/O error ocurred.
-
getPos
public int getPos() throws IOException
Returns the stream position clamped to a maximum ofInteger.MAX_VALUE
.- Specified by:
getPos
in interfaceRandomAccessIO
- Returns:
- The offset of the current position, in bytes.
- Throws:
IOException
- If an I/O error ocurred.
-
seek
public void seek(int off) throws IOException
Description copied from interface:RandomAccessIO
Moves the current position for the next read or write operation to offset. The offset is measured from the beginning of the stream. The offset may be set beyond the end of the file, if in write mode. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.- Specified by:
seek
in interfaceRandomAccessIO
- Parameters:
off
- The offset where to move to.- Throws:
EOFException
- If in read-only and seeking beyond EOF.IOException
- If an I/O error ocurred.
-
length
public int length() throws IOException
Returns the length of the data stream.If the length of the
ImageInputStream
is not-1
, then it is returned after being clamped to a maximum value ofInteger.MAX_VALUE
. If theImageInputStream
is-1
, the stream is read to a maximum position ofInteger.MAX_VALUE
and its final position is returned. The position of the stream is unchanged from the value it had prior to the call.- Specified by:
length
in interfaceRandomAccessIO
- Returns:
- The length of the stream, in bytes.
- Throws:
IOException
- If an I/O error ocurred.
-
read
public int read() throws IOException
Description copied from interface:RandomAccessIO
Reads a byte of data from the stream. Prior to reading, the stream is realigned at the byte level.- Specified by:
read
in interfaceRandomAccessIO
- Returns:
- The byte read, as an int.
- Throws:
EOFException
- If the end-of file was reached.IOException
- If an I/O error ocurred.
-
readFully
public void readFully(byte[] b, int off, int n) throws IOException
Description copied from interface:RandomAccessIO
Reads up to len bytes of data from this file into an array of bytes. This method reads repeatedly from the stream until all the bytes are read. This method blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown.- Specified by:
readFully
in interfaceRandomAccessIO
- Parameters:
b
- The buffer into which the data is to be read. It must be long enough.off
- The index in 'b' where to place the first byte read.n
- The number of bytes to read.- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
getByteOrdering
public int getByteOrdering()
Description copied from interface:BinaryDataInput
Returns the endianess (i.e., byte ordering) of the implementing class. Note that an implementing class may implement only one type of endianness or both, which would be decided at creatiuon time.- Specified by:
getByteOrdering
in interfaceBinaryDataInput
- Specified by:
getByteOrdering
in interfaceBinaryDataOutput
- Returns:
- Either EndianType.BIG_ENDIAN or EndianType.LITTLE_ENDIAN
- See Also:
EndianType
-
readByte
public byte readByte() throws IOException
Description copied from interface:BinaryDataInput
Should read a signed byte (i.e., 8 bit) from the input. reading, the input should be realigned at the byte level.- Specified by:
readByte
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned signed byte (8 bit) from the input.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readUnsignedByte
public int readUnsignedByte() throws IOException
Description copied from interface:BinaryDataInput
Should read an unsigned byte (i.e., 8 bit) from the input. It is returned as an int since Java does not have an unsigned byte type. Prior to reading, the input should be realigned at the byte level.- Specified by:
readUnsignedByte
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned unsigned byte (8 bit) from the input, as an int.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readShort
public short readShort() throws IOException
Description copied from interface:BinaryDataInput
Should read a signed short (i.e., 16 bit) from the input. Prior to reading, the input should be realigned at the byte level.- Specified by:
readShort
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned signed short (16 bit) from the input.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readUnsignedShort
public int readUnsignedShort() throws IOException
Description copied from interface:BinaryDataInput
Should read an unsigned short (i.e., 16 bit) from the input. It is returned as an int since Java does not have an unsigned short type. Prior to reading, the input should be realigned at the byte level.- Specified by:
readUnsignedShort
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned unsigned short (16 bit) from the input, as an int.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readInt
public int readInt() throws IOException
Description copied from interface:BinaryDataInput
Should read a signed int (i.e., 32 bit) from the input. Prior to reading, the input should be realigned at the byte level.- Specified by:
readInt
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned signed int (32 bit) from the input.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readUnsignedInt
public long readUnsignedInt() throws IOException
Description copied from interface:BinaryDataInput
Should read an unsigned int (i.e., 32 bit) from the input. It is returned as a long since Java does not have an unsigned short type. Prior to reading, the input should be realigned at the byte level.- Specified by:
readUnsignedInt
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned unsigned int (32 bit) from the input, as a long.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readLong
public long readLong() throws IOException
Description copied from interface:BinaryDataInput
Should read a signed long (i.e., 64 bit) from the input. Prior to reading, the input should be realigned at the byte level.- Specified by:
readLong
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned signed long (64 bit) from the input.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readFloat
public float readFloat() throws IOException
Description copied from interface:BinaryDataInput
Should read an IEEE single precision (i.e., 32 bit) floating-point number from the input. Prior to reading, the input should be realigned at the byte level.- Specified by:
readFloat
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned IEEE float (32 bit) from the input.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
readDouble
public double readDouble() throws IOException
Description copied from interface:BinaryDataInput
Should read an IEEE double precision (i.e., 64 bit) floating-point number from the input. Prior to reading, the input should be realigned at the byte level.- Specified by:
readDouble
in interfaceBinaryDataInput
- Returns:
- The next byte-aligned IEEE double (64 bit) from the input.
- Throws:
EOFException
- If the end-of file was reached before getting all the necessary data.IOException
- If an I/O error ocurred.
-
skipBytes
public int skipBytes(int n) throws IOException
Description copied from interface:BinaryDataInput
Skips n bytes from the input. Prior to skipping, the input should be realigned at the byte level.- Specified by:
skipBytes
in interfaceBinaryDataInput
- Parameters:
n
- The number of bytes to skip- Throws:
EOFException
- If the end-of file was reached before all the bytes could be skipped.IOException
- If an I/O error ocurred.
-
flush
public void flush()
A null operation as writing is not supported.- Specified by:
flush
in interfaceBinaryDataOutput
-
write
public void write(int b) throws IOException
Throws anIOException
as writing is not supported.- Specified by:
write
in interfaceRandomAccessIO
- Parameters:
b
- The byte to write. The lower 8 bits of b are written.- Throws:
IOException
- If an I/O error ocurred.
-
writeByte
public void writeByte(int v) throws IOException
Throws anIOException
as writing is not supported.- Specified by:
writeByte
in interfaceBinaryDataOutput
- Parameters:
v
- The value to write to the output- Throws:
IOException
- If an I/O error ocurred.
-
writeShort
public void writeShort(int v) throws IOException
Throws anIOException
as writing is not supported.- Specified by:
writeShort
in interfaceBinaryDataOutput
- Parameters:
v
- The value to write to the output- Throws:
IOException
- If an I/O error ocurred.
-
writeInt
public void writeInt(int v) throws IOException
Throws anIOException
as writing is not supported.- Specified by:
writeInt
in interfaceBinaryDataOutput
- Parameters:
v
- The value to write to the output- Throws:
IOException
- If an I/O error ocurred.
-
writeLong
public void writeLong(long v) throws IOException
Throws anIOException
as writing is not supported.- Specified by:
writeLong
in interfaceBinaryDataOutput
- Parameters:
v
- The value to write to the output- Throws:
IOException
- If an I/O error ocurred.
-
writeFloat
public void writeFloat(float v) throws IOException
Throws anIOException
as writing is not supported.- Specified by:
writeFloat
in interfaceBinaryDataOutput
- Parameters:
v
- The value to write to the output- Throws:
IOException
- If an I/O error ocurred.
-
writeDouble
public void writeDouble(double v) throws IOException
Throws anIOException
as writing is not supported.- Specified by:
writeDouble
in interfaceBinaryDataOutput
- Parameters:
v
- The value to write to the output- Throws:
IOException
- If an I/O error ocurred.
-
-