Module openj9.dtfj

Class 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
    • Method Detail

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