java.lang.Object
javax.imageio.stream.ImageInputStreamImpl
com.ibm.dtfj.corereaders.ClosingFileReader
- All Implemented Interfaces:
ResourceReleaser,Closeable,DataInput,AutoCloseable,ImageInputStream
A wrapper around the functionality that we require from RandomAccessFiles but with the added auto-closing
functionality that we require. Since it is not always easy to determine who "owns" a file and we do not want
to introduce the concept of state, this class will manage all such file ownership.
We now also extend javax.imageio.stream.ImageInputStreamImpl as a convenient common interface that we can
share with the zebedee corefile reader
-
Field Summary
Fields declared in class javax.imageio.stream.ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPos -
Constructor Summary
ConstructorsConstructorDescriptionClosingFileReader(File file) ClosingFileReader(File file, boolean deleteOnCloseOrExit) Create a closing file reader which can close/delete the backing file on shutdownCreate a closing file reader from a stream -
Method Summary
Modifier and TypeMethodDescriptionvoidfinalize()Finalizes this object prior to garbage collection.booleanintread()Reads a single byte from the stream and returns it as anintbetween 0 and 255.intread(byte[] buffer) Currently this attempts to fill the entire bufferintread(byte[] buffer, int bStart, int length) Reads up tolenbytes from the stream, and stores them intobstarting at indexoff.byte[]readBytes(int n) voidMethods declared in class javax.imageio.stream.ImageInputStreamImpl
checkClosed, close, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, length, mark, 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, skipBytes
-
Constructor Details
-
ClosingFileReader
- Throws:
IOException
-
ClosingFileReader
Create a closing file reader from a stream- Parameters:
file- An ImageInputStream- Throws:
FileNotFoundExceptionIOException
-
ClosingFileReader
Create a closing file reader which can close/delete the backing file on shutdown- Parameters:
file-deleteOnCloseOrExit- Whether to delete the file when the file is closed or at shutdown- Throws:
FileNotFoundExceptionIOException
-
-
Method Details
-
readBytes
- Throws:
IOException
-
finalize
Description copied from class:javax.imageio.stream.ImageInputStreamImplFinalizes this object prior to garbage collection. Theclosemethod is called to close any open input source. This method should not be called from application code.- Overrides:
finalizein classImageInputStreamImpl- Throws:
Throwable- if an error occurs during superclass finalization.
-
read
Description copied from class:javax.imageio.stream.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:
buffer-bStart-length-- Returns:
- The number of bytes actually read
- Throws:
IOException
-
read
Currently this attempts to fill the entire buffer- Specified by:
readin interfaceImageInputStream- Overrides:
readin classImageInputStreamImpl- Parameters:
buffer- an array of bytes to be written to.- Returns:
- the number of bytes actually read, or
-1to indicate EOF. - Throws:
IOException- if an I/O error occurs.
-
read
Description copied from class:javax.imageio.stream.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.
-
streamFromFile
- Returns:
- A new stream for reading from the underlying file
- Throws:
FileNotFoundException- If this file has moved since the ClosingFileReader was created (since we would have failed in the constructor if the file was ever there)
-
getURIOfFile
-
getAbsolutePath
-
isMVSFile
public boolean isMVSFile() -
releaseResources
- Specified by:
releaseResourcesin interfaceResourceReleaser- Throws:
IOException
-