Class FileImageInputStream
java.lang.Object
javax.imageio.stream.ImageInputStreamImpl
javax.imageio.stream.FileImageInputStream
- All Implemented Interfaces:
Closeable, DataInput, AutoCloseable, ImageInputStream
An implementation of
ImageInputStream that gets its
input from a File or RandomAccessFile.
The file contents are assumed to be stable during the lifetime of
the object.-
Field Summary
Fields declared in class ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPosModifier and TypeFieldDescriptionprotected intThe current bit offset within the stream.protected ByteOrderThe byte order of the stream as an instance of the enumeration classjava.nio.ByteOrder, whereByteOrder.BIG_ENDIANindicates network byte order andByteOrder.LITTLE_ENDIANindicates the reverse order.protected longThe position prior to which data may be discarded.protected longThe current read position within the stream. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aFileImageInputStreamthat will read from a givenFile.Constructs aFileImageInputStreamthat will read from a givenRandomAccessFile. -
Method Summary
Modifier and TypeMethodDescriptionlonglength()Returns the length of the underlying file, or-1if it is unknown.intread()Reads a single byte from the stream and returns it as anintbetween 0 and 255.intread(byte[] b, int off, int len) Reads up tolenbytes from the stream, and stores them intobstarting at indexoff.Methods declared in class ImageInputStreamImpl
checkClosed, close, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, mark, read, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, reset, seek, setBitOffset, setByteOrder, skipBytes, skipBytesModifier and TypeMethodDescriptionprotected final voidThrows anIOExceptionif the stream has been closed.voidclose()Closes the stream.voidflush()Discards the initial position of the stream prior to the current stream position.voidflushBefore(long pos) Discards the initial portion of the stream prior to the indicated position.intReturns the current bit offset, as an integer between 0 and 7, inclusive.Returns the byte order with which data values will be read from this stream as an instance of thejava.nio.ByteOrderenumeration.longReturns the earliest position in the stream to which seeking may be performed.longReturns the current byte position of the stream.booleanisCached()Default implementation returns false.booleanDefault implementation returns false.booleanDefault implementation returns false.voidmark()Pushes the current stream position onto a stack of marked positions.intread(byte[] b) A convenience method that callsread(b, 0, b.length).intreadBit()Reads a single bit from the stream and returns it as anintwith the value0or1.longreadBits(int numBits) Reads a bitstring from the stream and returns it as along, with the first bit read becoming the most significant bit of the output.booleanReads a byte from the stream and returns abooleanvalue oftrueif it is nonzero,falseif it is zero.bytereadByte()Reads a byte from the stream and returns it as abytevalue.voidreadBytes(IIOByteBuffer buf, int len) Reads up tolenbytes from the stream, and modifies the suppliedIIOByteBufferto indicate the byte array, offset, and length where the data may be found.charreadChar()Equivalent toreadUnsignedShort, except that the result is returned using thechardatatype.doubleReads 8 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as adouble.floatReads 4 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as afloat.voidreadFully(byte[] b) Readsb.lengthbytes from the stream, and stores them intobstarting at index0.voidreadFully(byte[] b, int off, int len) Readslenbytes from the stream, and stores them intobstarting at indexoff.voidreadFully(char[] c, int off, int len) Readslenchars (unsigned 16-bit integers) from the stream according to the current byte order, and stores them intocstarting at indexoff.voidreadFully(double[] d, int off, int len) Readslendoubles (64-bit IEEE double-precision floats) from the stream according to the current byte order, and stores them intodstarting at indexoff.voidreadFully(float[] f, int off, int len) Readslenfloats (32-bit IEEE single-precision floats) from the stream according to the current byte order, and stores them intofstarting at indexoff.voidreadFully(int[] i, int off, int len) Readslenints (signed 32-bit integers) from the stream according to the current byte order, and stores them intoistarting at indexoff.voidreadFully(long[] l, int off, int len) Readslenlongs (signed 64-bit integers) from the stream according to the current byte order, and stores them intolstarting at indexoff.voidreadFully(short[] s, int off, int len) Readslenshorts (signed 16-bit integers) from the stream according to the current byte order, and stores them intosstarting at indexoff.intreadInt()Reads 4 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as anint.readLine()Reads the next line of text from the input stream.longreadLong()Reads 8 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as along.shortReads two bytes from the stream, and (conceptually) concatenates them according to the current byte order, and returns the result as ashortvalue.intReads a byte from the stream, and (conceptually) converts it to an int, masks it with0xffin order to strip off any sign-extension bits, and returns it as abytevalue.longReads 4 bytes from the stream, and (conceptually) concatenates them according to the current byte order, converts the result to a long, masks it with0xffffffffLin order to strip off any sign-extension bits, and returns the result as an unsignedlongvalue.intReads two bytes from the stream, and (conceptually) concatenates them according to the current byte order, converts the resulting value to anint, masks it with0xffffin order to strip off any sign-extension buts, and returns the result as an unsignedintvalue.readUTF()Reads in a string that has been encoded using a modified UTF-8 format.voidreset()Resets the current stream byte and bit positions from the stack of marked positions.voidseek(long pos) Sets the current stream position to the desired location.voidsetBitOffset(int bitOffset) Sets the bit offset to an integer between 0 and 7, inclusive.voidsetByteOrder(ByteOrder byteOrder) Sets the desired byte order for future reads of data values from this stream.intskipBytes(int n) Advances the current stream position by callingseek(getStreamPosition() + n).longskipBytes(long n) Advances the current stream position by callingseek(getStreamPosition() + n).Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
FileImageInputStream
Constructs aFileImageInputStreamthat will read from a givenFile.The file contents must not change between the time this object is constructed and the time of the last call to a read method.
- Parameters:
f- aFileto read from.- Throws:
IllegalArgumentException- iffisnull.FileNotFoundException- iffis a directory or cannot be opened for reading for any other reason.IOException- if an I/O error occurs.
-
FileImageInputStream
Constructs aFileImageInputStreamthat will read from a givenRandomAccessFile.The file contents must not change between the time this object is constructed and the time of the last call to a read method.
- Parameters:
raf- aRandomAccessFileto read from.- Throws:
IllegalArgumentException- ifrafisnull.
-
-
Method Details
-
read
Description copied from class:ImageInputStreamImplReads a single byte from the stream and returns it as anintbetween 0 and 255. If EOF is reached,-1is 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.
- Specified by:
readin interfaceImageInputStream- Specified by:
readin classImageInputStreamImpl- Returns:
- the value of the next byte in the stream, or
-1if EOF is reached. - Throws:
IOException- if the stream has been closed.
-
read
Description copied from class:ImageInputStreamImplReads up tolenbytes from the stream, and stores them intobstarting at indexoff. If no bytes can be read because the end of the stream has been reached,-1is 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.
- Specified by:
readin interfaceImageInputStream- Specified by:
readin classImageInputStreamImpl- Parameters:
b- an array of bytes to be written to.off- the starting position withinbto write to.len- the maximum number of bytes to read.- Returns:
- the number of bytes actually read, or
-1to indicate EOF. - Throws:
IOException- if an I/O error occurs.
-
length
public long length()Returns the length of the underlying file, or-1if it is unknown.- Specified by:
lengthin interfaceImageInputStream- Overrides:
lengthin classImageInputStreamImpl- Returns:
- the file length as a
long, or-1.
-