Menu

#4 CobolIoProvider.getLineReader with InputStream instead of String filename?

closed
None
1
2019-04-30
2015-02-05
Nick Briggs
No

I would find it quite helpful to have a CobolIoProvider.getLineReader() which took an InputStream instead of a file name, especially for the copybook, but also for the input data... it's much more flexible.

Discussion

  • Bruce Martin

    Bruce Martin - 2015-02-05

    I will have look at doing this

     
  • Bruce Martin

    Bruce Martin - 2015-02-05
    • assigned_to: Bruce Martin
     
  • Bruce Martin

    Bruce Martin - 2015-02-05

    I am little concerned at having similar methods with a lot of parameters. I was thinking a Builder type approach might be better:

    IOBuilder builder = CobolIoProvider.newCobolIOBuilder(...);
    AbstractLineReader reader = builder.newLineReader(stream);
    AbstreactLineWriter writer = builder.newLineWriter(stream);
    
         /* or */
    
    AbstractLineReader reader = builder.newLineReader(filename);
    AbstreactLineWriter writer = builder.newLineWriter(filename);
    
         /* you could also do */
    
    AbstractLineReader reader = CobolIoProvider
                                     .newCobolIOBuilder(...)
                                     .newLineWriter(stream /* or filename */)
    

    It should lead to simpler clearer code !!!


    Also at the moment, You can do:

    ByteArrayInputStream bs = new ByteArrayInputStream(copybook.getBytes);
    LayoutDetail schema = new CobolCopybookLoader()
                       .loadCopyBook(   bs, "RedefTest", 
                                CopybookLoader.SPLIT_01_LEVEL, 0, "",
                            Cb2xmlConstants.USE_STANDARD_COLUMNS, 
                                Convert.FMT_INTEL, 0, new TextLog())
                    ..asLayoutDetail();
    
    AbstractLineReader reader = LineIOProvider.getInstance().getLineReader(schema);
    
    reader.open(inputStream, schema);
    

    I realize this is more long winded than the CobolIoProvider. CobolIoProvider was always intended handle just the simple cases, I would prefer not to complicate it to much

     
  • Nick Briggs

    Nick Briggs - 2015-02-05

    Thanks! I think the Builder approach would work well.

    In general when designing library interfaces which are processing some stream of bytes(characters) I try to stay far away from String filenames, File objects, or anything else which implies a particular set of operations that need to be applied before you can read(write) the data. I figure that the caller knows their source/sink better than my library, so they can arrange to apply the operations to get it into an Input(Output)Stream before calling the library.

     
  • Bruce Martin

    Bruce Martin - 2015-02-09

    I agree with what you said, if I was writing JRecord now I would do things quite differently. Basically with JRecord

    • I did not intend to write JRecord as a standalone library, The cope originally was part of the RecordEditor. JRecord was a Response to various requests
    • JRecord was originally written for Java 1.3/1.4 so no Generics, Enums etc.

    Please give me your thoughts on Builder approach. I am thinking of making it the standard way of accessing JRecord.

    I do have thoughts of doing a complete rewrite of JRecord with all the, so please pass through any suggestions

     
  • Bruce Martin

    Bruce Martin - 2015-02-14

    In version 0.80.8 I have created a new IOBuilder classes which can be used like

    ICobolIOBuilder iob = CobolIoProvider.getInstance()
                               .newIOBuilder(copybookStream, copybookname)
                                    .setSplitCopybook(CopybookLoader.SPLIT_REDEFINE); 
    AbstractLineReader reader = iob.newReader(salesstream);
    

    The IOBuilder will accept either filenames or streams as input for Cobol-Copyybooks, Input-Files and Output-Files.

     
  • Bruce Martin

    Bruce Martin - 2015-11-10

    This has been implemented now

     
  • Bruce Martin

    Bruce Martin - 2015-11-10
    • status: open --> pending
     
  • Anonymous

    Anonymous - 2016-11-29

    Hi, I amusing jrecord 0.82 but could not find newIOBuilder. Iwant to process input streams
    Please help

     
  • Bruce Martin

    Bruce Martin - 2016-11-29

    For a Cobol file you would start with JRecordInterface1

    i.e.

      JRecordInterface1.COBOL.newIOBuilder(...)
    

    or using the fully qualified class name

      net.sf.JRecord.JRecordInterface1
             .COBOL.newIOBuilder(...)
    

    For a Fixed-Width file (no Cobol Copybook):

      JRecordInterface1.FIXED_WIDTH.newIOBuilder(...)
    

    For a Csv File

      JRecordInterface1.CSV.newIOBuilder(...)
    

    etc

     
  • Anonymous

    Anonymous - 2016-11-30

    Hi Thanks for ur quick response. I tried above option but getting JRecordInterface1 cannt be resolved. Iam ajava developer and want to validate cobol datafile againstcobol copybook fileand both are in inputstreams . Iam using jrecord0.82. please letme know ifabove thing can be achieved using this version.

     
  • Bruce Martin

    Bruce Martin - 2016-11-30

    The latest JRecord is 0.81.4:

    Have a look in the Source/JRecord_IO_Builder_Examples this sub projects contains examples of using JRecord. In particular, src\net\sf\JRecord\zExamples\iob\cobol contains Cobol examples.

    I will come back to this later

     
  • Anonymous

    Anonymous - 2016-12-28

    Hi Bruce, Is there a way to validate data against the copybook schema. Now am able to parse the data but it does not seem to validate the datatypes and patterns. Please suggest

     
    • Bruce Martin

      Bruce Martin - 2016-12-29

      There is not anything builtin to validate the data. the Best option is to the CobolSchemaDetails class. You can use it like:

      • CobolSchemaDetails.newCobolSchemaReader("copybook-file-name")
      • CobolSchemaDetails.newCobolSchemaReader(Reader reader, "copybook-Name")

      This will return:

      • JRecord Layout (schema)
      • Cobol Item Tree (copybook and recordItems) which has the Cobol Tree + JRecord Field definitions added in to it.

      The IItem has a lot of Cobol definitions (e.g. Cobol Picture, Display-Length, decimal etc). It can be cast back to Item for extra details (like Cobol 88 level details). If you do need more details from Item let me know I can update IItem if neen be. Alternalively take a copy of net.sf.JRecord.schema. There are not a huge number of classes and it is based on the cb2xml Jaxb example.

      So you would need to write your own validation.


      Note: you can use

      JRecordInterface1.SCHEMA.newIOBuilder(cobolSchemaDetails.schema);
      

      to create an IOBuilder from a layout or schema.

       

      Last edit: Bruce Martin 2016-12-29
  • Bruce Martin

    Bruce Martin - 2017-11-01
    • status: pending --> closed
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB