com.ibm.as400.access

Class IFSFileOutputStream

  • java.lang.Object
    • java.io.OutputStream
      • com.ibm.as400.access.IFSFileOutputStream
  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.io.Serializable
    Direct Known Subclasses:
    IFSTextFileOutputStream


    public class IFSFileOutputStream
    extends java.io.OutputStream
    implements java.io.Serializable
    Represents an integrated file system file output stream. An integrated file system file output stream is an output stream for writing data to integrated file system objects.
    IFSFileOutputStream objects are capable of generating file events that call the following FileListener methods: fileClosed, fileModified, and fileOpended.
    The following example illustrates the use of IFSFileOutputStream:
     // Work with /Dir/File on the system eniac.
     AS400 as400 = new AS400("eniac");
     IFSFileOutputStream file = new IFSFileOutputStream(as400, "/Dir/File");
    // Lock the first 8 bytes of the file. IFSKey key = file.lock(8);
    // Write 8 bytes to the file. byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7 }; file.write(data, 0, 8);
    // Unlock the first 8 bytes. file.unlock(key);
    // Close the file. file.close();
    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 java.beans.PropertyChangeSupport changes_ 
      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.
      protected java.beans.VetoableChangeSupport vetos_ 
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void addFileListener(FileListener listener)
      Adds a file listener to receive file events from this IFSFileOutputStream.
      void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
      Adds a property change listener.
      void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
      Adds a vetoable change listener.
      void close()
      Closes this file output stream and releases any system resources associated with this stream.
      protected void finalize()
      Ensures that the file output stream is closed when there are no more references to it.
      void flush()
      Forces any buffered output bytes to be written.
      IFSFileDescriptor getFD()
      Returns the file descriptor associated with this stream.
      java.lang.String getPath()
      Returns the integrated file system path name of the object represented by this IFSFileOutputStream object.
      int getShareOption()
      Returns the share option for this object.
      AS400 getSystem()
      Returns the AS400 system object for this 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(int fileDataCCSID)
      Opens the specified file.
      void removeFileListener(FileListener listener)
      Removes a file listener so that it no longer receives file events from this IFSFileOutputStream.
      void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
      Removes a property change listener.
      void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
      Removes a vetoable change listener.
      void setAppend(boolean append)
      Sets the append option.
      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.
      void unlock(IFSKey key)
      Undoes a lock on this file.
      void write(byte[] data)
      Writes data.length bytes of data from the byte array data to this file output stream.
      void write(byte[] data, int dataOffset, int length)
      Writes length bytes of data from the byte array data, starting at offset, to this file output stream.
      void write(int b)
      Writes the specified byte to this file output stream.
      • 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
      • changes_

        protected transient java.beans.PropertyChangeSupport changes_
      • vetos_

        protected transient java.beans.VetoableChangeSupport vetos_
    • Constructor Detail

      • IFSFileOutputStream

        public IFSFileOutputStream()
        Constructs an IFSFileOutputStream object. It is a default file output stream.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           java.lang.String name)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. It creates a file output stream to write to the file with the specified name. Other readers and writers are allowed to access the file. The file is replaced if it exists; otherwise, the file is created.
        Parameters:
        system - The system that contains the file.
        name - The file to be opened for writing.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           java.lang.String name,
                           int ccsid)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. It creates a file output stream to write to the file with the specified name and ccsid. Other readers and writers are allowed to access the file. The file is replaced if it exists; otherwise, the file is created.
        Parameters:
        system - The system that contains the file.
        name - The file to be opened for writing.
        ccsid - The CCSID with which to tag the data in the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           java.lang.String name,
                           int shareOption,
                           boolean append)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. It creates a file output stream to write to the file with the specified name.
        Parameters:
        system - The system that contains the file.
        name - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           java.lang.String name,
                           int shareOption,
                           boolean append,
                           int ccsid)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. It creates a file output stream to write to the file with the specified name and ccsid.
        Parameters:
        system - The system that contains the file.
        name - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        ccsid - The CCSID with which to tag the data in the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(IFSFile file)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. It creates a file output stream to write to the file specified by file. Other readers and writers are allowed to access the file. The file is replaced if it exists; otherwise, the file is created.
        Parameters:
        file - The file to be opened for writing.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           IFSFile file,
                           int shareOption,
                           boolean append)
                            throws AS400SecurityException,
                                   java.io.IOException
        Deprecated. Use IFSFileOutputStream(IFSFile, int, boolean) instead.
        Constructs an IFSFileOutputStream object. It creates a file output stream to write to the file specified by file.
        Parameters:
        system - The system that contains the file.
        file - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(IFSFile file,
                           int shareOption,
                           boolean append)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. It creates a file output stream to write to the file specified by file.
        Parameters:
        file - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           IFSFile file,
                           int shareOption,
                           boolean append,
                           int ccsid)
                            throws AS400SecurityException,
                                   java.io.IOException
        Deprecated. Use IFSFileOutputStream(IFSFile, int, boolean, int) instead.
        Constructs an IFSFileOutputStream object. Creates a file output stream to write to the file specified by file, tagging the data with the CCSID specified by ccsid.
        Parameters:
        system - The system that contains the file.
        file - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        ccsid - The CCSID with which to tag the data in the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(IFSFile file,
                           int shareOption,
                           boolean append,
                           int ccsid)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. Creates a file output stream to write to the file specified by file, tagging the data with the CCSID specified by ccsid.
        Parameters:
        file - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        ccsid - The CCSID with which to tag the data in the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(IFSFileDescriptor fd)
        Creates a file output stream to write to file descriptor fd.
        Parameters:
        fd - The file descriptor to be opened for writing.
      • IFSFileOutputStream

        public IFSFileOutputStream(IFSJavaFile file)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. Creates a file output stream to write to the file specified by file. Other readers and writers are allowed to access the file. The file is replaced if it exists; otherwise, the file is created.
        Parameters:
        file - The file to be opened for writing.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           IFSJavaFile file,
                           int shareOption,
                           boolean append)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. Creates a file output stream to write to the file specified by file.
        Parameters:
        system - The system that contains the file.
        file - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
      • IFSFileOutputStream

        public IFSFileOutputStream(AS400 system,
                           IFSJavaFile file,
                           int shareOption,
                           boolean append,
                           int ccsid)
                            throws AS400SecurityException,
                                   java.io.IOException
        Constructs an IFSFileOutputStream object. Creates a file output stream to write to the file specified by file, tagging the data with the CCSID specified by ccsid.
        Parameters:
        system - The system that contains the file.
        file - The file to be opened for writing.
        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
        append - Controls the behavior of the file. If true, output is appended to the file; otherwise, the current contents of the file are erased, and output replaces the file contents.
        ccsid - The CCSID with which to tag the data in the file.
        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 IFSFileOutputStream.
        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.
      • close

        public void close()
                   throws java.io.IOException
        Closes this file output stream and releases any system resources associated with this stream.
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        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 output 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.
      • flush

        public void flush()
                   throws java.io.IOException
        Forces any buffered output bytes to be written.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • getFD

        public final IFSFileDescriptor getFD()
                                      throws java.io.IOException
        Returns the file descriptor associated with this stream.
        Returns:
        The file descriptor 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 IFSFileOutputStream 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 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:
        A 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:
        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:
        A key for undoing this lock.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        unlock(com.ibm.as400.access.IFSKey)
      • open

        protected void open(int fileDataCCSID)
                     throws java.io.IOException
        Opens the specified file. If the file is already open, does nothing.
        Parameters:
        fileDataCCSID - The CCSID with which to tag the data in the file.
        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 IFSFileOutputStream.
        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.
      • setAppend

        public void setAppend(boolean append)
                       throws java.beans.PropertyVetoException
        Sets the append option.
        Parameters:
        append - If true, data is appended to an existing file; otherwise, output replaces the file contents.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • 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.
      • 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)
      • write

        public void write(int b)
                   throws java.io.IOException
        Writes the specified byte to this file output stream.
        Specified by:
        write in class java.io.OutputStream
        Parameters:
        b - The byte to be written.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • write

        public void write(byte[] data)
                   throws java.io.IOException
        Writes data.length bytes of data from the byte array data to this file output stream.
        Overrides:
        write in class java.io.OutputStream
        Parameters:
        data - The data to be written.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • write

        public void write(byte[] data,
                 int dataOffset,
                 int length)
                   throws java.io.IOException
        Writes length bytes of data from the byte array data, starting at offset, to this file output stream.
        Overrides:
        write in class java.io.OutputStream
        Parameters:
        data - The data to be written.
        dataOffset - The start offset in the data.
        length - The number of bytes to write.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.