com.ibm.as400.access

Class IFSFileReader

  • All Implemented Interfaces:
    Closeable, Readable


    public class IFSFileReader
    extends Reader
    Convenience class for reading character files in the integrated file system. The behavior of this class is comparable to java.io.FileReader.
    IFSFileReader is meant for reading streams of characters. For reading streams of raw bytes, use IFSFileInputStream. If an InputStream is required, use IFSTextFileInputStream.

    The following example illustrates the use of IFSFileReader:

    import java.io.BufferedReader;
    // Work with /File1 on the system eniac.
    AS400 system = new AS400("eniac");
    IFSFile file = new IFSFile(system, "/File1");
    BufferedReader reader = new BufferedReader(new IFSFileReader(file));
    // Read the first line of the file, converting characters.
    String line1 = reader.readLine();
    // Display the String that was read.
    System.out.println(line1);
    // Close the reader.
    reader.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.
    • 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

      • IFSFileReader

        public IFSFileReader(IFSFile file)
                      throws AS400SecurityException,
                             IOException
        Constructs an IFSFileReader 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. 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.
        IOException - If an error occurs while communicating with the system.
      • IFSFileReader

        public IFSFileReader(IFSFile file,
                     int ccsid)
                      throws AS400SecurityException,
                             IOException
        Constructs an IFSFileReader object. The file is opened if it exists; otherwise an exception is thrown. Other readers and writers are allowed to access the file.
        Parameters:
        file - The file to be opened for reading.
        ccsid - The CCSID that the file data is currently in.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • IFSFileReader

        public IFSFileReader(IFSFile file,
                     int ccsid,
                     int shareOption)
                      throws AS400SecurityException,
                             IOException
        Constructs an IFSFileReader object. The file is opened if it exists; otherwise an exception is thrown.
        Parameters:
        file - The file to be opened for reading.
        ccsid - The CCSID that the file data is currently in.
        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.
        IOException - If an error occurs while communicating with the system.

    • Method Detail

      • close

        public void close()
                   throws IOException
        Closes the stream. Once a stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.
        Specified by:
        close in interface Closeable
        Specified by:
        close in class Reader
        Throws:
        IOException - If an error occurs while communicating with the system.
      • getCCSID

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

        public String getEncoding()
        Returns the encoding used by this IFSFileReader.
        Returns:
        The encoding, or null if the encoding is not known.
      • markSupported

        public boolean markSupported()
        IFSFileReader does not support the mark() operation.
        Overrides:
        markSupported in class Reader
        Returns:
        false.
      • read

        public int read()
                 throws IOException
        Reads a single character.
        Overrides:
        read in class Reader
        Returns:
        The character read, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If an error occurs while communicating with the system.
      • read

        public int read(char[] cbuf)
                 throws IOException
        Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
        Overrides:
        read in class Reader
        Parameters:
        cbuf - Destination buffer.
        Returns:
        The number of characters read, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If an error occurs while communicating with the system.
      • read

        public int read(char[] cbuf,
               int off,
               int len)
                 throws IOException
        Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
        Specified by:
        read in class Reader
        Parameters:
        cbuf - Destination buffer.
        off - Offset at which to start storing characters.
        len - Maximum number of characters to read.
        Returns:
        The number of characters read, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If an error occurs while communicating with the system.
      • ready

        public boolean ready()
                      throws IOException
        Tells whether this stream is ready to be read.
        Overrides:
        ready in class Reader
        Returns:
        true if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
        Throws:
        IOException - If an error occurs while communicating with the system.
      • reset

        public void reset()
                   throws IOException
        Resets the stream. After this call, the stream will read from the beginning.
        Overrides:
        reset in class Reader
        Throws:
        IOException - If an error occurs while communicating with the system.
      • skip

        public long skip(long charsToSkip)
                  throws IOException
        Skip characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.
        Overrides:
        skip in class Reader
        Parameters:
        charsToSkip - The number of characters to skip.
        Returns:
        The number of characters actually skipped.
        Throws:
        IOException - If an error occurs while communicating with the system.
      • lockBytes

        public IFSKey lockBytes(int length)
                         throws 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:
        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 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:
        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 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:
        IOException - If an error occurs while communicating with the system.
        See Also:
        lockBytes(long)