Module openj9.dtfj

Class ClosingFileReader

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
  • Constructor Details

  • Method Details

    • readBytes

      public byte[] readBytes(int n) throws IOException
      Throws:
      IOException
    • finalize

      public void finalize() throws Throwable
      Description copied from class: javax.imageio.stream.ImageInputStreamImpl
      Finalizes this object prior to garbage collection. The close method is called to close any open input source. This method should not be called from application code.
      Overrides:
      finalize in class ImageInputStreamImpl
      Throws:
      Throwable - if an error occurs during superclass finalization.
    • read

      public int read(byte[] buffer, int bStart, int length) throws IOException
      Description copied from class: javax.imageio.stream.ImageInputStreamImpl
      Reads up to len bytes from the stream, and stores them into b starting at index off. 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 interface ImageInputStream
      Specified by:
      read in class ImageInputStreamImpl
      Parameters:
      buffer -
      bStart -
      length -
      Returns:
      The number of bytes actually read
      Throws:
      IOException
    • read

      public int read(byte[] buffer) throws IOException
      Currently this attempts to fill the entire buffer
      Specified by:
      read in interface ImageInputStream
      Overrides:
      read in class ImageInputStreamImpl
      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

      public int read() throws IOException
      Description copied from class: javax.imageio.stream.ImageInputStreamImpl
      Reads a single byte from the stream and returns it as an int 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 interface ImageInputStream
      Specified by:
      read in class ImageInputStreamImpl
      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

      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()
    • releaseResources

      public void releaseResources() throws IOException
      Specified by:
      releaseResources in interface ResourceReleaser
      Throws:
      IOException