Module ibm.jzos
Package com.ibm.jzos

Class FileFactory


  • public class FileFactory
    extends java.lang.Object
    A class with static methods for building a BufferedReader, BufferedWriter, InputStream, or OutputStream on a text file or MVS dataset.

    If the file name given starts with "//", then the underlying file stream will be constructed using a ZFile on an MVS dataset, otherwise the file will be constructed using java.io.

    The default encoding for BufferedReaders and BufferedWriters is the ZUtil.defaultPlatformEncoding for ZFiles, and the default JVM file.encoding property for other files.

    This class may be used on non-z/OS platforms so long as MVS filenames are not used, so as to allow for portable text-based IO applications.

    see: ZFile for more information on specifying MVS dataset names

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getDefaultEncoding​(java.lang.String filename)
      Answer the default encoding assumed for a given filename
      static java.lang.String getDefaultJavaIoEncoding()
      Answer the default encoding for a java.io file encoding, which defaults to the Java System property "file.encoding".
      static java.lang.String getDefaultZFileEncoding()
      Answer the default (EBCDIC) encoding for a ZFile
      static java.io.BufferedInputStream newBufferedInputStream​(java.lang.String filename)
      Open a new BufferedInputStream on a file with the given name.
      static java.io.BufferedInputStream newBufferedInputStream​(java.lang.String filename, int bsize)
      Open a new BufferedInputStream on a file with the given name.
      static java.io.BufferedOutputStream newBufferedOutputStream​(java.lang.String filename)
      Open a new BufferedOutputStream on a file with the given name.
      static java.io.BufferedOutputStream newBufferedOutputStream​(java.lang.String filename, int bsize)
      Open a new BufferedOutputStream on a file with the given name and buffer size.
      static java.io.BufferedReader newBufferedReader​(java.lang.String filename)
      Open a new BufferedReader on a file with the given name, default encoding, and a default buffersize.
      static java.io.BufferedReader newBufferedReader​(java.lang.String filename, java.lang.String encoding)
      Open a new BufferedReader on a file with the given name, encoding, and a default buffersize.
      static java.io.BufferedReader newBufferedReader​(java.lang.String filename, java.lang.String encoding, int bsize)
      Open a new BufferedReader on a file with the given name, encoding, and buffersize.
      static java.io.BufferedWriter newBufferedWriter​(java.lang.String filename)
      Open a new BufferedWriter on a file with the given name, default encoding, and default buffersize.
      static java.io.BufferedWriter newBufferedWriter​(java.lang.String filename, java.lang.String encoding)
      Open a new BufferedWriter on a file with the given name, encoding, and default buffersize.
      static java.io.BufferedWriter newBufferedWriter​(java.lang.String filename, java.lang.String encoding, int bsize)
      Open a new BufferedWriter on a file with the given name, encoding, and buffersize.
      static java.io.InputStream newInputStream​(java.lang.String filename)
      Open a new unbuffered InputStream on a file with the given name.
      static java.io.OutputStream newOutputStream​(java.lang.String filename)
      Open a new unbuffered OutputStream on a file with the given name.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newInputStream

        public static java.io.InputStream newInputStream​(java.lang.String filename)
                                                  throws java.io.IOException
        Open a new unbuffered InputStream on a file with the given name.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this InputStream.

        Throws:
        java.io.IOException
      • newBufferedInputStream

        public static java.io.BufferedInputStream newBufferedInputStream​(java.lang.String filename,
                                                                         int bsize)
                                                                  throws java.io.IOException
        Open a new BufferedInputStream on a file with the given name.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this InputStream.

        Throws:
        java.io.IOException
      • newBufferedInputStream

        public static java.io.BufferedInputStream newBufferedInputStream​(java.lang.String filename)
                                                                  throws java.io.IOException
        Open a new BufferedInputStream on a file with the given name.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this InputStream.

        Throws:
        java.io.IOException
      • newOutputStream

        public static java.io.OutputStream newOutputStream​(java.lang.String filename)
                                                    throws java.io.IOException
        Open a new unbuffered OutputStream on a file with the given name.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this OutputStream.

        Throws:
        java.io.IOException
      • newBufferedOutputStream

        public static java.io.BufferedOutputStream newBufferedOutputStream​(java.lang.String filename,
                                                                           int bsize)
                                                                    throws java.io.IOException
        Open a new BufferedOutputStream on a file with the given name and buffer size.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this OutputStream.

        Throws:
        java.io.IOException
      • newBufferedOutputStream

        public static java.io.BufferedOutputStream newBufferedOutputStream​(java.lang.String filename)
                                                                    throws java.io.IOException
        Open a new BufferedOutputStream on a file with the given name.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this OutputStream.

        Throws:
        java.io.IOException
      • newBufferedReader

        public static java.io.BufferedReader newBufferedReader​(java.lang.String filename,
                                                               java.lang.String encoding,
                                                               int bsize)
                                                        throws java.io.IOException
        Open a new BufferedReader on a file with the given name, encoding, and buffersize.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this reader.

        Throws:
        java.io.IOException
      • newBufferedReader

        public static java.io.BufferedReader newBufferedReader​(java.lang.String filename,
                                                               java.lang.String encoding)
                                                        throws java.io.IOException
        Open a new BufferedReader on a file with the given name, encoding, and a default buffersize.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this reader.

        Throws:
        java.io.IOException
      • newBufferedReader

        public static java.io.BufferedReader newBufferedReader​(java.lang.String filename)
                                                        throws java.io.IOException
        Open a new BufferedReader on a file with the given name, default encoding, and a default buffersize.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this reader.

        Throws:
        java.io.IOException
      • newBufferedWriter

        public static java.io.BufferedWriter newBufferedWriter​(java.lang.String filename,
                                                               java.lang.String encoding,
                                                               int bsize)
                                                        throws java.io.IOException
        Open a new BufferedWriter on a file with the given name, encoding, and buffersize.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this reader.

        Throws:
        java.io.IOException
      • newBufferedWriter

        public static java.io.BufferedWriter newBufferedWriter​(java.lang.String filename,
                                                               java.lang.String encoding)
                                                        throws java.io.IOException
        Open a new BufferedWriter on a file with the given name, encoding, and default buffersize.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this reader.

        Throws:
        java.io.IOException
      • newBufferedWriter

        public static java.io.BufferedWriter newBufferedWriter​(java.lang.String filename)
                                                        throws java.io.IOException
        Open a new BufferedWriter on a file with the given name, default encoding, and default buffersize.

        File names starting with "//" are assumed to be MVS datasets and are opened using ZFile. Others are opened with regular java.io files.

        NB: the client is responsible for closing this reader.

        Throws:
        java.io.IOException
      • getDefaultEncoding

        public static java.lang.String getDefaultEncoding​(java.lang.String filename)
        Answer the default encoding assumed for a given filename
      • getDefaultZFileEncoding

        public static java.lang.String getDefaultZFileEncoding()
        Answer the default (EBCDIC) encoding for a ZFile
      • getDefaultJavaIoEncoding

        public static java.lang.String getDefaultJavaIoEncoding()
        Answer the default encoding for a java.io file encoding, which defaults to the Java System property "file.encoding".