Module ibm.jzos
Package com.ibm.jzos

Class FileFactory

java.lang.Object
com.ibm.jzos.FileFactory

public class FileFactory extends 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 Details

    • newInputStream

      public static InputStream newInputStream(String filename) throws 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:
      IOException
    • newBufferedInputStream

      public static BufferedInputStream newBufferedInputStream(String filename, int bsize) throws 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:
      IOException
    • newBufferedInputStream

      public static BufferedInputStream newBufferedInputStream(String filename) throws 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:
      IOException
    • newOutputStream

      public static OutputStream newOutputStream(String filename) throws 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:
      IOException
    • newBufferedOutputStream

      public static BufferedOutputStream newBufferedOutputStream(String filename, int bsize) throws 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:
      IOException
    • newBufferedOutputStream

      public static BufferedOutputStream newBufferedOutputStream(String filename) throws 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:
      IOException
    • newBufferedReader

      public static BufferedReader newBufferedReader(String filename, String encoding, int bsize) throws 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:
      IOException
    • newBufferedReader

      public static BufferedReader newBufferedReader(String filename, String encoding) throws 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:
      IOException
    • newBufferedReader

      public static BufferedReader newBufferedReader(String filename) throws 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:
      IOException
    • newBufferedWriter

      public static BufferedWriter newBufferedWriter(String filename, String encoding, int bsize) throws 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:
      IOException
    • newBufferedWriter

      public static BufferedWriter newBufferedWriter(String filename, String encoding) throws 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:
      IOException
    • newBufferedWriter

      public static BufferedWriter newBufferedWriter(String filename) throws 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:
      IOException
    • getDefaultEncoding

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

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

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