com.ibm.as400.access

Class IFSFileWriter

  • java.lang.Object
    • java.io.Writer
      • com.ibm.as400.access.IFSFileWriter
  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable


    public class IFSFileWriter
    extends java.io.Writer
    Convenience class for writing character files in the integrated file system. The behavior of this class is comparable to java.io.FileWriter.
    IFSFileWriter is meant for writing streams of characters. For writing streams of raw bytes, use IFSFileOutputStream. If an OutputStream is required, use IFSTextFileOutputStream.

    The following example illustrates the use of IFSFileWriter:

    import java.io.PrintWriter;
    import java.io.BufferedWriter;
    // Work with /File1 on the system eniac.
    AS400 as400 = new AS400("eniac");
    IFSFile file = new IFSFile(system, "/File1");
    PrintWriter writer = new PrintWriter(new BufferedWriter(new IFSFileWriter(file)));
    // Write a line of text to the file, converting characters.
    writer.println(text);
    // Close the file.
    writer.close();
    
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      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.
      • Fields inherited from class java.io.Writer

        lock
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void close()
      Closes the stream, flushing it first.
      void flush()
      Flushes the underlying output stream.
      int getCCSID()
      Returns the CCSID used by this IFSFileWriter.
      java.lang.String getEncoding()
      Returns the encoding used by this IFSFileWriter.
      IFSKey lockBytes(int length)
      Deprecated. 
      Replaced by lock(long)
      IFSKey lockBytes(long length)
      Places a lock on the file at the current position for the specified number of bytes.
      void unlockBytes(IFSKey key)
      Undoes a lock on the file.
      void write(char[] buffer)
      Writes the specified array of characters.
      void write(char[] buffer, int offset, int length)
      Writes a portion of an array of characters.
      void write(int c)
      Writes a single character.
      void write(java.lang.String data)
      Writes a String.
      void write(java.lang.String data, int offset, int length)
      Writes a portion of a String.
      • Methods inherited from class java.io.Writer

        append, append, append
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, 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

      • IFSFileWriter

        public IFSFileWriter(IFSFile file)
                      throws AS400SecurityException,
                             java.io.IOException
        Constructs an IFSFileWriter object. Other readers and writers are allowed to access the file. The file is opened if it exists; otherwise an exception is thrown. The file's CCSID is obtained by referencing the file's "coded character set ID" tag on the system. Any data currently in the file will be overwritten. Other readers and writers are allowed to access the file.
        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.
        See Also:
        IFSFile.createNewFile()
      • IFSFileWriter

        public IFSFileWriter(IFSFile file,
                     int ccsid)
                      throws AS400SecurityException,
                             java.io.IOException
        Constructs an IFSFileWriter object. The file is opened if it exists; otherwise an exception is thrown. Any data currently in the file will be overwritten. Other readers and writers are allowed to access the file.
        Parameters:
        file - The file to be opened for writing.
        ccsid - The CCSID to convert the data to when writing to the file. The file's "data CCSID" tag on the system is not changed.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        IFSFile.createNewFile()
      • IFSFileWriter

        public IFSFileWriter(IFSFile file,
                     boolean append)
                      throws AS400SecurityException,
                             java.io.IOException
        Constructs an IFSFileWriter object. The file is opened if it exists; otherwise an exception is thrown. The file's CCSID is obtained by referencing the file's "coded character set ID" tag on the system. Other readers and writers are allowed to access the file.
        Parameters:
        file - The file to be opened for writing.
        append - If true, output is appended to the file; otherwise, any data currently in the file will be overwritten.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        IFSFile.createNewFile()
      • IFSFileWriter

        public IFSFileWriter(IFSFile file,
                     boolean append,
                     int shareOption)
                      throws AS400SecurityException,
                             java.io.IOException
        Constructs an IFSFileWriter object. The file is opened if it exists; otherwise an exception is thrown. The file's CCSID is obtained by referencing the file's "coded character set ID" tag on the system.
        Parameters:
        file - The file to be opened for writing.
        append - If true, output is appended to the file; otherwise, any data currently in the file will be overwritten.
        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.
        See Also:
        IFSFile.createNewFile()
      • IFSFileWriter

        public IFSFileWriter(IFSFile file,
                     boolean append,
                     int shareOption,
                     int ccsid)
                      throws AS400SecurityException,
                             java.io.IOException
        Constructs an IFSFileWriter object. The file is opened if it exists; otherwise an exception may be thrown.
        Parameters:
        file - The file to be opened for writing.
        append - If true, output is appended to the file; otherwise, any data currently in the file will be overwritten.
        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
        ccsid - The CCSID to convert the data to when writing to the file. The file's "data CCSID" tag on the system is not changed.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        IFSFile.createNewFile()
      • IFSFileWriter

        public IFSFileWriter(IFSFileDescriptor fd)
                      throws AS400SecurityException,
                             java.io.IOException
        Constructs an IFSFileWriter object. The file is opened if it exists; otherwise an exception is thrown.
        Parameters:
        fd - The file descriptor 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.
        See Also:
        IFSFile.createNewFile()
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Closes the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect.
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Writer
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • flush

        public void flush()
                   throws java.io.IOException
        Flushes the underlying output stream.
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • getCCSID

        public int getCCSID()
        Returns the CCSID used by this IFSFileWriter.
        Returns:
        The CCSID, or -1 if the CCSID is not known.
      • getEncoding

        public java.lang.String getEncoding()
        Returns the encoding used by this IFSFileWriter.
        Returns:
        The encoding, or null if the encoding is not known.
      • lockBytes

        public IFSKey lockBytes(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:
        java.io.IOException - If an error occurs while communicating with the system.
        See Also:
        unlockBytes(com.ibm.as400.access.IFSKey)
      • lockBytes

        public IFSKey lockBytes(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:
        unlockBytes(com.ibm.as400.access.IFSKey)
      • unlockBytes

        public void unlockBytes(IFSKey key)
                         throws java.io.IOException
        Undoes a lock on the 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:
        lockBytes(long)
      • write

        public void write(int c)
                   throws java.io.IOException
        Writes a single character.
        Overrides:
        write in class java.io.Writer
        Parameters:
        c - int specifying a character to be written.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • write

        public void write(char[] buffer)
                   throws java.io.IOException
        Writes the specified array of characters.
        Overrides:
        write in class java.io.Writer
        Parameters:
        buffer - The characters to be written.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • write

        public void write(char[] buffer,
                 int offset,
                 int length)
                   throws java.io.IOException
        Writes a portion of an array of characters.
        Specified by:
        write in class java.io.Writer
        Parameters:
        buffer - The characters to be written.
        offset - The offset into the array from which to begin extracting characters to write.
        length - The number of characters to write.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • write

        public void write(java.lang.String data)
                   throws java.io.IOException
        Writes a String.
        Overrides:
        write in class java.io.Writer
        Parameters:
        data - The String to write.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • write

        public void write(java.lang.String data,
                 int offset,
                 int length)
                   throws java.io.IOException
        Writes a portion of a String.
        Overrides:
        write in class java.io.Writer
        Parameters:
        data - The String to write.
        offset - The offset into the String from which to begin extracting characters to write.
        length - The number of characters to write.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.