com.ibm.as400.access

Class IFSTextFileOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, Serializable


    public class IFSTextFileOutputStream
    extends IFSFileOutputStream
    implements Serializable
    The IFSTextFileOutputStream class represents an integrated file system output stream for character data.
    IFSTextFileOutputStream object is capable of generating file events which call the following FileListener methods: fileClosed, fileModified, and fileOpened.
    Note: By default, Unicode data is written to the file. To use another CCSID when writing to the file, use one of the constructors that has a ccsid parameter.
    Note: This class is provided for situations where an OutputStream is required. The preferred method of writing to a text file is via IFSFileWriter.

    The following example illustrates the use of IFSTextFileOutputStream:

    // Work with /File on the system eniac.
    AS400 as400 = new AS400("eniac");
    IFSTextFileOutputStream file = new IFSTextFileOutputStream(as400, "/File");
    // Write a String to the file (don't convert characters). file.write("Hello world"); // Close the file. file.close();
    See Also:
    FileEvent, IFSFileOutputStream.addFileListener(com.ibm.as400.access.FileListener), IFSFileOutputStream.removeFileListener(com.ibm.as400.access.FileListener), Serialized Form
    • Constructor Detail

      • IFSTextFileOutputStream

        public IFSTextFileOutputStream()
        Constructs an IFSTextFileOutputStream object.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               String name)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text 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. By default, Unicode data is written to the file.
        Parameters:
        system - The AS400 that contains the file.
        name - The file to be opened for writing.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               String name,
                               int ccsid)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text 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 AS400 that contains the file.
        name - The file to be opened for writing.
        ccsid - The CCSID of the data being written to the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               String name,
                               int shareOption,
                               boolean append)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text file with the specified name. By default, Unicode data is written to the file.
        Parameters:
        system - The AS400 that contains the file.
        name - The file to be opened for writing.
        shareOption - Indicates how other user's 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 when the file exists. 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.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               String name,
                               int shareOption,
                               boolean append,
                               int ccsid)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text file with the specified name and CCSID.
        Parameters:
        system - The AS400 that contains the file.
        name - The file to be opened for writing.
        shareOption - Indicates how other user's 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 when the file exists. 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 of the data being written to the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(IFSFile file)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text 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. By default, Unicode data is written to the file.
        Parameters:
        file - The file to be opened for writing.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               IFSFile file,
                               int shareOption,
                               boolean append)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text file specified by file. By default, Unicode data is written to the file.
        Parameters:
        system - The AS400 that contains the file.
        file - The file to be opened for writing.
        shareOption - Indicates how other user's 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 when the file exists. 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.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               IFSFile file,
                               int shareOption,
                               boolean append,
                               int ccsid)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text file specified by file using the CCSID specified by ccsid.
        Parameters:
        system - The AS400 that contains the file.
        file - The file to be opened for writing.
        shareOption - Indicates how other user's 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 when the file exists. 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 of the data being written to the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(IFSJavaFile file)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text 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.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               IFSJavaFile file,
                               int shareOption,
                               boolean append)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text file specified by file.
        Parameters:
        system - The AS400 that contains the file.
        file - The file to be opened for writing.
        shareOption - Indicates how other user's 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 when the file exists. 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.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(AS400 system,
                               IFSJavaFile file,
                               int shareOption,
                               boolean append,
                               int ccsid)
                                throws AS400SecurityException,
                                       IOException
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to the text file specified by file using the CCSID specified by ccsid.
        Parameters:
        system - The AS400 that contains the file.
        file - The file to be opened for writing.
        shareOption - Indicates how other user's 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 when the file exists. 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 of the data being written to the file.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • IFSTextFileOutputStream

        public IFSTextFileOutputStream(IFSFileDescriptor fd)
        Constructs an IFSTextFileOutputStream object. It creates a file output stream to write to file descriptor fd.
        Parameters:
        fd - The file descriptor to be opened for writing.

    • Method Detail

      • getCCSID

        public int getCCSID()
        Returns the CCSID. This is just the bean property, and does not necessarily represent the file's actual original CCSID on the system.
        Returns:
        The CCSID.
        See Also:
        IFSFile.getCCSID()
      • setCCSID

        public void setCCSID(int ccsid)
                      throws PropertyVetoException
        Sets the CCSID for the data written to the file.
        Note: This method is of limited usefulness, since it is invalid after a connection has been opened to the file on the system, and most of the constructors for this class open a connection. The preferred way to set the CCSID of the file is via a constructor that has a "ccsid" argument.
        Parameters:
        ccsid - The target CCSID.
        Throws:
        PropertyVetoException - If the change is vetoed.
      • write

        public void write(String data)
                   throws IOException
        Writes characters to this text file input stream. The characters that are written to the file are converted to the specified CCSID.
        Parameters:
        data - The characters to write to the stream.
        Throws:
        IOException - If an error occurs while communicating with the system.
        See Also:
        getCCSID(), setCCSID(int)