Class VRecordReader

java.lang.Object
com.blackhillsoftware.smf.VRecordReader
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<VRecord>

public abstract class VRecordReader extends Object implements Iterable<VRecord>, Closeable
VRecordReader reads variable length records from a z/OS DD, a file, an InputStream or a sequence of byte arrays. Create a VRecordReader using:

VRecordReader implements Closeable and should normally be used in a try with resources block so that it will be closed automatically:

 
 try (VRecordReader reader = VRecordReader.fromName("//DD:INPUT"))             
 {
     for (VRecord record : reader)           
     {
         // process record 
     }
 }
 
 
  • Method Details

    • fromDD

      public static VRecordReader fromDD(String dd) throws IOException
      Create a new VRecordReader to read from an allocated DD.

      Set up a a try-with-resources block to automatically close the dataset, or call close() when finished reading.

      Parameters:
      dd - The DDNAME for the dataset. The DD must be already allocated e.g. via JCL.
      Returns:
      a new VRecordReader to read from the DD
      Throws:
      IOException - if the JZOS RecordReader throws an exception
    • fromName

      public static VRecordReader fromName(String name) throws IOException, FileNotFoundException
      Create a new VRecordReader to read from a named file or dataset. Names can take several forms:
      • If the name begins with "//DD:" the VRecordReader will open and read from the preallocated DD name.
         "//DD:INPUT"
      • If the name begins with with "//" but not "///" the VRecordReader will open and read from a MVS dataset using the same syntax as the C fopen() function. Use single quotes to specify the complete dataset name, otherwise the user's prefix is added.
         "//'MVS.DATASET.NAME'"
         "//'MVS.DATASET.NAME(0)'"
      • Otherwise the VRecordReader will open a FileInputStream using that name (typically reading from a Windows/Linux/HFS etc. file).

      Set up a a try-with-resources block to automatically close the input source, or call close() when finished reading.

      Parameters:
      name - The name of the resource to open, in the formats documented above.
      Returns:
      a new VRecordReader
      Throws:
      IOException - if the JZOS RecordReader or FileInputStream throws an exception
      FileNotFoundException - if the FileInputStream cannot find the file
    • fromStream

      public static VRecordReader fromStream(InputStream stream)
      Create a new VRecordReader to read from an existing stream.

      The stream must contain complete variable length records, including the RDW

      Set up a a try-with-resources block to automatically close the stream, or call close() when finished reading.

      Parameters:
      stream - the InputStream to read.
      Returns:
      a new VRecordReader to read from the stream
    • fromStream

      public static VRecordReader fromStream(InputStream stream, SmfRecordReader.RecordFormat format)
      Create a new VRecordReader to read from an existing stream specifying the record format.

      The stream must contain complete variable length records, including the RDW, and the BDW if RecordFormat.U is specified

      RecordFormat.AUTODETECT is only supported by SmfRecordReader for SMF data.

      Set up a a try-with-resources block to automatically close the stream, or call close() when finished reading.

      Parameters:
      stream - the InputStream to read.
      format - the SmfRecordReader.RecordFormat of the records in the stream - U, V or AutoDetect
      Returns:
      a new VRecordReader to read from the stream
    • close

      public abstract void close() throws IOException
      Close the input source.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs
    • read

      public abstract VRecord read() throws IOException
      Read a record, returning null at end of input.
      Returns:
      a VRecord or null
      Throws:
      IOException - if an I/O error occurs
    • read

      public abstract int read(byte[] buffer) throws IOException
      Read a record into an existing array.
      Returns:
      the number of bytes read, -1 at end of input.
      Throws:
      IOException - if an I/O error occurs
    • iterator

      public Iterator<VRecord> iterator()
      Get an Iterator to read VRecords from the input source.
      Specified by:
      iterator in interface Iterable<VRecord>
      Returns:
      Iterator<VRecord>
    • spliterator

      public Spliterator<VRecord> spliterator()
      Specified by:
      spliterator in interface Iterable<VRecord>
    • stream

      public Stream<VRecord> stream()
      Get a Java Stream to read VRecord from the input stream or DD.
      Returns:
      Stream<VRecord>
      See Also: