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
ConstructorDescriptionClosingFileReader
(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 TypeMethodDescriptionvoid
finalize()
Finalizes this object prior to garbage collection.boolean
int
read()
Reads a single byte from the stream and returns it as anint
between 0 and 255.int
read
(byte[] buffer) Currently this attempts to fill the entire bufferint
read
(byte[] buffer, int bStart, int length) Reads up tolen
bytes from the stream, and stores them intob
starting at indexoff
.byte[]
readBytes
(int n) void
Methods 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:
FileNotFoundException
IOException
-
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:
FileNotFoundException
IOException
-
-
Method Details
-
readBytes
- Throws:
IOException
-
finalize
Description copied from class:javax.imageio.stream.ImageInputStreamImpl
Finalizes this object prior to garbage collection. Theclose
method is called to close any open input source. This method should not be called from application code.- Overrides:
finalize
in classImageInputStreamImpl
- Throws:
Throwable
- if an error occurs during superclass finalization.
-
read
Description copied from class:javax.imageio.stream.ImageInputStreamImpl
Reads up tolen
bytes from the stream, and stores them intob
starting at indexoff
. 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.
- Specified by:
read
in interfaceImageInputStream
- Specified by:
read
in 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:
read
in interfaceImageInputStream
- Overrides:
read
in classImageInputStreamImpl
- Parameters:
buffer
- an array of bytes to be written to.- Returns:
- the number of bytes actually read, or
-1
to indicate EOF. - Throws:
IOException
- if an I/O error occurs.
-
read
Description copied from class:javax.imageio.stream.ImageInputStreamImpl
Reads a single byte from the stream and returns it as anint
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.
- Specified by:
read
in interfaceImageInputStream
- Specified by:
read
in classImageInputStreamImpl
- Returns:
- the value of the next byte in the stream, or
-1
if 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:
releaseResources
in interfaceResourceReleaser
- Throws:
IOException
-