com.ibm.as400.access

Class PrintObjectPageInputStream

  • java.lang.Object
    • java.io.InputStream
      • com.ibm.as400.access.PrintObjectPageInputStream
  • All Implemented Interfaces:
    java.io.Closeable


    public class PrintObjectPageInputStream
    extends java.io.InputStream
    Reads data out of a system spooled file one page at a time. The page of data may be transformed, depending on the PrintParameterList used to create an instance of the class.

    The number of pages in the spooled file may be estimated. To help process spooled files with estimated page counts, methods nextPage, previousPage, and selectPage will return false if the requested page is not available.

    An instance of this class is created using the getPageInputStream method from the class SpooledFile.

    NOTE: This class is supported on OS/400 V4R4 or later. Not all spooled file formats are supported for transform.

    • Method Summary

      Methods 
      Modifier and Type Method and Description
      int available()
      Returns the number of bytes remaining in the current page.
      void close()
      Closes the input stream and releases any resources associated with it.
      int getCurrentPageNumber()
      Returns the number of the current page of the input stream.
      int getNumberOfPages()
      Returns the number of pages in the stream.
      boolean isPagesEstimated()
      Indicates if the number of pages is estimated.
      void mark(int readLimit)
      Marks the current position of the current page of the input stream.
      boolean markSupported()
      Returns a boolean indicating whether this stream type supports mark and reset.
      boolean nextPage()
      Repositions the stream to the next page.
      boolean previousPage()
      Repositions the stream to the previous page.
      int read()
      Reads the next byte of data from this input stream.
      int read(byte[] data)
      Reads up to data.length bytes of data from the page input stream into data.
      int read(byte[] data, int dataOffset, int length)
      Reads up to length bytes of data from this input stream into data, starting at the array offset dataOffset.
      void reset()
      Repositions the stream to the last marked position.
      boolean selectPage(int page)
      Repositions the stream to page page.
      long skip(long bytesToSkip)
      Skips over the next bytesToSkip bytes in the stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • available

        public int available()
                      throws java.io.IOException
        Returns the number of bytes remaining in the current page.
        Overrides:
        available in class java.io.InputStream
        Returns:
        The number of available bytes (without blocking) in the current page.
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Closes the input stream and releases any resources associated with it.
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • getCurrentPageNumber

        public int getCurrentPageNumber()
        Returns the number of the current page of the input stream.
        Returns:
        The number of the current page.
      • getNumberOfPages

        public int getNumberOfPages()
        Returns the number of pages in the stream.
        Returns:
        The number of pages in the stream.
      • isPagesEstimated

        public boolean isPagesEstimated()
        Indicates if the number of pages is estimated.
        Returns:
        True if the number of pages is estimated; false otherwise.
      • mark

        public void mark(int readLimit)
        Marks the current position of the current page of the input stream. A subsequent call to reset() will reposition the stream at the last marked position, so that subsequent reads will reread the same bytes. The stream promises to allow readLimit bytes to be read before the mark position gets invalidated, provided readLimit does not exceed amount of page data available, in which case the readLimit is set to a value equal to the amount of data available until the end of the page is reached.
        Overrides:
        mark in class java.io.InputStream
        Parameters:
        readLimit - The maximum limit of bytes allowed to be read before the mark position is no longer valid.
      • markSupported

        public boolean markSupported()
        Returns a boolean indicating whether this stream type supports mark and reset.
        Overrides:
        markSupported in class java.io.InputStream
        Returns:
        Always true. Objects of this class will support the mark and reset methods.
      • nextPage

        public boolean nextPage()
                         throws java.io.IOException
        Repositions the stream to the next page.
        Returns:
        True if the stream is positioned to the next page; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • previousPage

        public boolean previousPage()
                             throws java.io.IOException
        Repositions the stream to the previous page.
        Returns:
        True if the stream is positioned to the previous page; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • read

        public int read()
                 throws java.io.IOException
        Reads the next byte of data from this input stream.
        Specified by:
        read in class java.io.InputStream
        Returns:
        The byte read, or -1 if the end of the page stream is reached.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • read

        public int read(byte[] data)
                 throws java.io.IOException
        Reads up to data.length bytes of data from the page input stream into data.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        data - The buffer into which the data is read.
        Returns:
        The total number of bytes read into the buffer or -1 if there is no more data because the end of the page stream has been reached.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • read

        public int read(byte[] data,
               int dataOffset,
               int length)
                 throws java.io.IOException
        Reads up to length bytes of data from this input stream into data, starting at the array offset dataOffset.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        data - The buffer into which the data is read.
        dataOffset - The start offset of the data.
        length - The maximum number of bytes to read.
        Returns:
        The total number of bytes read into the buffer, or -1 if there is no more data because the end of the page stream has been reached.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • reset

        public void reset()
                   throws java.io.IOException
        Repositions the stream to the last marked position. If the stream has not been marked or if the mark has been invalidated, an IOException is thrown.
        Overrides:
        reset in class java.io.InputStream
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • selectPage

        public boolean selectPage(int page)
                           throws java.io.IOException,
                                  java.lang.IllegalArgumentException
        Repositions the stream to page page.
        Parameters:
        page - The page at which to reposition the input stream.
        Returns:
        True if the stream is positioned to the specified page; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system, or an error occurs selecting the specified page.
        java.lang.IllegalArgumentException - If page is negative.
      • skip

        public long skip(long bytesToSkip)
                  throws java.io.IOException
        Skips over the next bytesToSkip bytes in the stream. This method may skip less bytes than specified if the end of the page is reached. The actual number of bytes skipped is returned. No action is taken if the number of bytes to skip is not positive.
        Overrides:
        skip in class java.io.InputStream
        Parameters:
        bytesToSkip - The number of bytes to be skipped.
        Returns:
        The actual number of bytes skipped.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.