Class SmfRecordWriter

java.lang.Object
com.blackhillsoftware.smf.SmfRecordWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class SmfRecordWriter extends Object implements Closeable
SmfRecordWriter writes SMF records to a DD statement allocated to the job, or an OutputStream. SmfRecordWriter implements Closeable and so should be used with try with resources so that it will be closed automatically:
 
 try (SmfRecordWriter writer = SmfRecordWriter.fromName("//DD:OUTPUT"))             
 {
     ...
     writer.write(smfrecord);
 }
  
 
  • Method Details

    • fromDD

      public static SmfRecordWriter fromDD(String dd) throws IOException
      Create a new SmfRecordWriter to write to an allocated DD.
      Parameters:
      dd - The DDNAME for the SMF output data. The DD must be already allocated e.g. via JCL.
      Returns:
      a new SmfRecordReader to write to the DD
      Throws:
      IOException - if an I/O error occurs
    • fromStream

      public static SmfRecordWriter fromStream(OutputStream stream)
      Create a new SmfRecordWriter to write to an existing stream.

      Records written to the stream will include the RDW

      Parameters:
      stream - the OutputStream to write records to.
      Returns:
      a new SmfRecordWriter to write to the stream
    • fromName

      public static SmfRecordWriter fromName(String name) throws IOException, FileNotFoundException
      Create a new SmfRecordWriter to write to a named file or dataset. Names can take several forms:
      • If the name begins with "//DD:" the SmfRecordWriter will open and write to the preallocated DD name.
         "//DD:INPUT"
      • If the name begins with with "//" but not "///" the SmfRecordWriter will open and write to an existing 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 SmfRecordWriter will open a FileOutputStream using that name (typically writing to a Windows/Linux/HFS etc. file).

      The writer can be automatically closed using a try-with-resources block (recommended), or call close() when finished writing.

      Parameters:
      name - The name of the resource to open, in one of the formats documented above.
      Returns:
      a new SmfRecordWriter
      Throws:
      IOException - if an I/O error occurs
      FileNotFoundException - if the file is not found
    • close

      public void close() throws IOException
      Close the output dataset or stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs
    • write

      public void write(SmfRecord record) throws IOException
      Throws:
      IOException