- java.lang.Object
-
- javax.imageio.stream.ImageInputStreamImpl
-
- com.ibm.dtfj.corereaders.ClosingFileReader
-
- All Implemented Interfaces:
ResourceReleaser,Closeable,DataInput,AutoCloseable,ImageInputStream
public class ClosingFileReader extends ImageInputStreamImpl implements ResourceReleaser
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
Constructors Constructor Description ClosingFileReader(File file)ClosingFileReader(File file, boolean deleteOnCloseOrExit)Create a closing file reader which can close/delete the backing file on shutdownClosingFileReader(ImageInputStream file)Create a closing file reader from a stream
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAbsolutePath()URIgetURIOfFile()booleanisMVSFile()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)InputStreamstreamFromFile()-
Methods declared in class javax.imageio.stream.ImageInputStreamImpl
checkClosed, close, finalize, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, length, 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, skipBytes
-
Methods declared in class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods declared in interface com.ibm.dtfj.corereaders.ResourceReleaser
releaseResources
-
-
-
-
Constructor Detail
-
ClosingFileReader
public ClosingFileReader(File file) throws IOException
- Throws:
IOException
-
ClosingFileReader
public ClosingFileReader(ImageInputStream file) throws IOException
Create a closing file reader from a stream- Parameters:
file- An ImageInputStream- Throws:
FileNotFoundExceptionIOException
-
ClosingFileReader
public ClosingFileReader(File file, boolean deleteOnCloseOrExit) throws IOException
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 Detail
-
readBytes
public byte[] readBytes(int n) throws IOException- Throws:
IOException
-
read
public int read(byte[] buffer, int bStart, int length) throws IOExceptionDescription 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
public int read(byte[] buffer) throws IOExceptionCurrently 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.
-
streamFromFile
public InputStream streamFromFile() throws FileNotFoundException
- 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
public URI getURIOfFile()
-
getAbsolutePath
public String getAbsolutePath()
-
isMVSFile
public boolean isMVSFile()
-
-