com.ibm.as400.access

Class IFSFileInputStream

  • java.lang.Object
    • java.io.InputStream
      • com.ibm.as400.access.IFSFileInputStream
  • All Implemented Interfaces:
    java.io.Closeable, java.io.Serializable
    Direct Known Subclasses:
    IFSTextFileInputStream


    public class IFSFileInputStream
    extends java.io.InputStream
    implements java.io.Serializable
    Represents an integrated file system input stream. An integrated file system file input stream is an input stream for reading data from integrated file system objects.
    IFSFileInputStream objects are capable of generating file events that call the following FileListener methods: fileClosed and fileOpened.
    The following example illustrates the use of IFSFileInputStream:
     // Work with /Dir/File on the system eniac.
     AS400 as400 = new AS400("eniac");
     IFSFileInputStream file = new IFSFileInputStream(as400, "/Dir/File");
    // Determine how many bytes are available on the stream. int available = file.available();
    // Lock the first 8 bytes of the file. IFSKey key = file.lock(8);
    // Read the first 8 bytes. byte[] data = new byte[8]; int bytesRead = file.read(data, 0, 8);
    // Unlock the first 8 bytes of the file. file.unlock(key);
    // Close the file. file.close();

    Note on the use of IFS classes when accessing QSYS files:
    The IFS classes are of limited usefulness when accessing formatted file objects under QSYS, such as physical files and save files. The IFS classes perform their work via datastream requests that are sent to the "File Server" job on the IBM i system. The File Server has no awareness of, or respect for, file record structure. When accessing QSYS file objects, consider the use of other classes such as SequentialFile, KeyedFile, and SaveFile.

    See Also:
    FileEvent, addFileListener(com.ibm.as400.access.FileListener), removeFileListener(com.ibm.as400.access.FileListener), Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected IFSFileDescriptor fd_ 
      static int SHARE_ALL
      Share option that allows read and write access by other users.
      static int SHARE_NONE
      Share option that does not allow read or write access by other users.
      static int SHARE_READERS
      Share option that allows only read access by other users.
      static int SHARE_WRITERS
      Share option that allows only write access by other users.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void addFileListener(FileListener listener)
      Adds a file listener to receive file events from this IFSFileInputStream.
      void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
      Adds a property change listener.
      void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
      Adds a vetoable change listener.
      int available()
      Returns the number of bytes that can be read from this file input stream.
      void close()
      Closes this file input stream and releases any system resources associated with the stream.
      protected void finalize()
      Ensures that the file input stream is closed when there are no more references to it.
      IFSFileDescriptor getFD()
      Returns the opaque file descriptor associated with this stream.
      java.lang.String getPath()
      Returns the integrated file system path name of the object represented by this IFSFileInputStream object.
      int getShareOption()
      Returns the share option for this object.
      AS400 getSystem()
      Returns the AS400 system object for this file input stream.
      IFSKey lock(int length)
      Deprecated. 
      Replaced by lock(long)
      IFSKey lock(long length)
      Places a lock on the file at the current position for the specified number of bytes.
      protected void open()
      Opens the specified file.
      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 this 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 removeFileListener(FileListener listener)
      Removes a file listener so that it no longer receives file events from this IFSFileInputStream.
      void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
      Removes a property change listener.
      void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
      Removes a vetoable change listener.
      void reset()
      Rewinds the input stream.
      void rewind()
      Deprecated. 
      Use reset() instead.
      void setFD(IFSFileDescriptor fd)
      Sets the file descriptor.
      void setPath(java.lang.String path)
      Sets the integrated file system path name.
      void setShareOption(int shareOption)
      Sets the share option.
      void setSystem(AS400 system)
      Sets the system.
      long skip(long bytesToSkip)
      Skips over the next bytesToSkip bytes in the file input stream.
      void unlock(IFSKey key)
      Undoes a lock on this file.
      • Methods inherited from class java.io.InputStream

        mark, markSupported
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SHARE_ALL

        public static final int SHARE_ALL
        Share option that allows read and write access by other users.
        See Also:
        Constant Field Values
      • SHARE_NONE

        public static final int SHARE_NONE
        Share option that does not allow read or write access by other users.
        See Also:
        Constant Field Values
      • SHARE_READERS

        public static final int SHARE_READERS
        Share option that allows only read access by other users.
        See Also:
        Constant Field Values
      • SHARE_WRITERS

        public static final int SHARE_WRITERS
        Share option that allows only write access by other users.
        See Also:
        Constant Field Values
    • Constructor Detail

      • IFSFileInputStream

        public IFSFileInputStream()
        Constructs an IFSFileInputStream. It creates a default file input stream.
      • IFSFileInputStream

        public IFSFileInputStream(AS400 system,
                          java.lang.String name)
                           throws AS400SecurityException,
                                  java.io.IOException
        Constructs an IFSFileInputStream. It creates a file input stream to read from the file name. Other readers and writers are allowed to access the file. The file is opened if it exists; otherwise, an exception is thrown.
        Parameters:
        system - The AS400 that contains the file.
        name - The integrated file system name.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileInputStream

        public IFSFileInputStream(AS400 system,
                          java.lang.String name,
                          int shareOption)
                           throws AS400SecurityException,
                                  java.io.IOException
        Constructs an IFSFileInputStream. It creates a file input stream to read from the file name.
        Parameters:
        system - The system that contains the file.
        name - The integrated file system name.
        shareOption - Indicates how users can access the file.
        • SHARE_ALL Share access with readers and writers
        • SHARE_NONE Share access with none
        • SHARE_READERS Share access with readers
        • SHARE_WRITERS Share access with writers
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileInputStream

        public IFSFileInputStream(IFSFile file)
                           throws AS400SecurityException,
                                  java.io.IOException
        Creates a file input stream to read from the file specified by file. Other readers and writers are allowed to access the file. The file is opened if it exists; otherwise, an exception is thrown.
        Parameters:
        file - The file to be opened for reading.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileInputStream

        public IFSFileInputStream(AS400 system,
                          IFSFile file,
                          int shareOption)
                           throws AS400SecurityException,
                                  java.io.IOException
        Deprecated. Use IFSFileInputStream(IFSFile, int) instead.
        Creates a file input stream to read from the file specified by file.
        Parameters:
        system - The system that contains the file.
        file - The file to be opened for reading.
        shareOption - Indicates how users can access the file.
        • SHARE_ALL Share access with readers and writers
        • SHARE_NONE Share access with none
        • SHARE_READERS Share access with readers
        • SHARE_WRITERS Share access with writers
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileInputStream

        public IFSFileInputStream(IFSFile file,
                          int shareOption)
                           throws AS400SecurityException,
                                  java.io.IOException
        Creates a file input stream to read from the file specified by file.
        Parameters:
        file - The file to be opened for reading.
        shareOption - Indicates how users can access the file.
        • SHARE_ALL Share access with readers and writers
        • SHARE_NONE Share access with none
        • SHARE_READERS Share access with readers
        • SHARE_WRITERS Share access with writers
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileInputStream

        public IFSFileInputStream(IFSFileDescriptor fd)
        Creates a file input stream to read from file descriptor fd.
        Parameters:
        fd - The file descriptor to be opened for reading.
      • IFSFileInputStream

        public IFSFileInputStream(IFSJavaFile file)
                           throws AS400SecurityException,
                                  java.io.IOException
        Creates a file input stream to read from the file specified by file. Other readers and writers are allowed to access the file.
        Parameters:
        file - The file to be opened for reading.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileInputStream

        public IFSFileInputStream(AS400 system,
                          IFSJavaFile file,
                          int shareOption)
                           throws AS400SecurityException,
                                  java.io.IOException
        Deprecated. Use IFSFileInputStream(IFSJavaFile, int) instead.
        Creates a file input stream to read from the file specified by file.
        Parameters:
        system - The system that contains the file.
        file - The file to be opened for reading.
        shareOption - Indicates how users can access the file.
        • SHARE_ALL Share access with readers and writers
        • SHARE_NONE Share access with none
        • SHARE_READERS Share access with readers
        • SHARE_WRITERS Share access with writers
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileInputStream

        public IFSFileInputStream(IFSJavaFile file,
                          int shareOption)
                           throws AS400SecurityException,
                                  java.io.IOException
        Creates a file input stream to read from the file specified by file.
        Parameters:
        file - The file to be opened for reading.
        shareOption - Indicates how users can access the file.
        • SHARE_ALL Share access with readers and writers
        • SHARE_NONE Share access with none
        • SHARE_READERS Share access with readers
        • SHARE_WRITERS Share access with writers
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
    • Method Detail

      • addFileListener

        public void addFileListener(FileListener listener)
        Adds a file listener to receive file events from this IFSFileInputStream.
        Parameters:
        listener - The file listener.
      • addPropertyChangeListener

        public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
        Adds a property change listener.
        Parameters:
        listener - The property change listener to add.
      • addVetoableChangeListener

        public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
        Adds a vetoable change listener.
        Parameters:
        listener - The vetoable change listener to add.
      • available

        public int available()
                      throws java.io.IOException
        Returns the number of bytes that can be read from this file input stream. If the actual number of available bytes exceeds Integer.MAX_VALUE, then Integer.MAX_VALUE is returned.
        Overrides:
        available in class java.io.InputStream
        Returns:
        The number of bytes that can be read from this file input stream, or Integer.MAX_VALUE, whichever is less.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • close

        public void close()
                   throws java.io.IOException
        Closes this file input stream and releases any system resources associated with the stream. This will not close the connection to the Host Server job held by the associated AS400 object.
        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.
      • finalize

        protected void finalize()
                         throws java.io.IOException
        Ensures that the file input stream is closed when there are no more references to it.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • getFD

        public final IFSFileDescriptor getFD()
                                      throws java.io.IOException
        Returns the opaque file descriptor associated with this stream.
        Returns:
        The file descriptor object associated with this stream.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • getPath

        public java.lang.String getPath()
        Returns the integrated file system path name of the object represented by this IFSFileInputStream object.
        Returns:
        The absolute path name of the object.
      • getShareOption

        public int getShareOption()
        Returns the share option for this object.
        Returns:
        The share option.
      • getSystem

        public AS400 getSystem()
        Returns the AS400 system object for this file input stream.
        Returns:
        The AS400 system object.
      • lock

        public IFSKey lock(int length)
                    throws java.io.IOException
        Deprecated. Replaced by lock(long)
        Places a lock on the file at the current position for the specified number of bytes. Note: This method is not supported for files under QSYS.
        Parameters:
        length - The number of bytes to lock.
        Returns:
        The key for undoing this lock.
        Throws:
        ExtendedIOException - If the specified bytes are already locked by another process.
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        IFSKey, unlock(com.ibm.as400.access.IFSKey)
      • lock

        public IFSKey lock(long length)
                    throws java.io.IOException
        Places a lock on the file at the current position for the specified number of bytes. Note: This method is not supported for files under QSYS.
        Parameters:
        length - The number of bytes to lock.
        Returns:
        The key for undoing this lock.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        IFSKey, unlock(com.ibm.as400.access.IFSKey)
      • open

        protected void open()
                     throws java.io.IOException
        Opens the specified file.
        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 next byte of data, or -1 if the end of file 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 this input stream into data.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        data - The buffer into which 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 file 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 in the buffer.
        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 file has been reached.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • removeFileListener

        public void removeFileListener(FileListener listener)
        Removes a file listener so that it no longer receives file events from this IFSFileInputStream.
        Parameters:
        listener - The file listener .
      • removePropertyChangeListener

        public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
        Removes a property change listener.
        Parameters:
        listener - The property change listener to remove.
      • removeVetoableChangeListener

        public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
        Removes a vetoable change listener.
        Parameters:
        listener - The vetoable change listener to remove.
      • reset

        public void reset()
                   throws java.io.IOException
        Rewinds the input stream. After this call, the stream will read from the beginning.
        Overrides:
        reset in class java.io.InputStream
        Throws:
        java.io.IOException
      • rewind

        public void rewind()
        Deprecated. Use reset() instead.
        Rewinds the input stream. After this call, the stream will read from the beginning.
      • setFD

        public void setFD(IFSFileDescriptor fd)
                   throws java.beans.PropertyVetoException
        Sets the file descriptor.
        Parameters:
        fd - The file descriptor.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setPath

        public void setPath(java.lang.String path)
                     throws java.beans.PropertyVetoException
        Sets the integrated file system path name.
        Parameters:
        path - The absolute integrated file system path name.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setShareOption

        public void setShareOption(int shareOption)
                            throws java.beans.PropertyVetoException
        Sets the share option.
        Parameters:
        shareOption - Indicates how users can access the file.
        • SHARE_ALL Share access with readers and writers
        • SHARE_NONE Share access with none
        • SHARE_READERS Share access with readers
        • SHARE_WRITERS Share access with writers
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setSystem

        public void setSystem(AS400 system)
                       throws java.beans.PropertyVetoException
        Sets the system. The system cannot be changed once a connection is made to the system.
        Parameters:
        system - The system object.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • skip

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

        public void unlock(IFSKey key)
                    throws java.io.IOException
        Undoes a lock on this file. Note: This method is not supported for files under QSYS.
        Parameters:
        key - The key for the lock.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        IFSKey, lock(long)