Qore FixedLengthUtil Module Reference  1.0
FixedLengthUtil::FixedLengthDataWriter Class Reference

Writer class for fixed-length-line data. More...

Inheritance diagram for FixedLengthUtil::FixedLengthDataWriter:

Public Member Functions

 constructor (hash specs, *hash opts)
 Instantiates the FixedLengthDataWriter object. More...
 
string write (list lines)
 iterates the input records and returns a string corresponding to the rendered versions of all input records More...
 
string write (hash line)
 Return a single line for a single input record hash. More...
 
string write (Qore::AbstractIterator lines)
 iterates the input records and returns a string corresponding to the rendered versions of all input records More...
 
- Public Member Functions inherited from FixedLengthUtil::FixedLengthAbstractWriter
bool checkTransition (*string from, *string to)
 A verification function to be called for each line. This method can be overridden to achieve a begin-to-end validation of the whole input file. More...
 
 constructor (hash specs, *hash opts)
 creates the FixedLengthAbstractWriter object More...
 
string formatLine (hash line)
 Formats a single line from a hash describing the record type and its contents. More...
 
int linesCount ()
 get processed lines count
 

Detailed Description

Writer class for fixed-length-line data.

Example:
1 const Spec = (
2  "header": (
3  "flow_type": ("length": 3, "type": "string", "value": "001"),
4  "record_type": ("length": 3, "type": "int", "padding_char": "0"),
5  "number_of_records": ("length": 8, "type": "int", "padding_char": "0"),
6  ),
7  "line": (
8  "flow_type": ("length": 3, "type": "string"),
9  "record_type": ("length": 3, "type": "int", "padding_char": "0"),
10  "processing_id": ("length": 10, "type": "int", "padding_char": "0"),
11  "processing_name": ("length": 10, "type": "string"),
12  "po_number": ("length": 10, "type": "int", "padding_char": "0"),
13  ),
14  "trailer": (
15  "flow_type": ("length": 3, "type": "string", "value": "003"),
16  "record_type": ("length": 3, "type": "int", "padding_char": "0"),
17  "number_of_records": ("length": 8, "type": "int", "padding_char": "0"),
18  ),
19 );
20 FixedLengthDataWriter w(Spec);
21 AbstractIterator i = get_record_iterator();
22 string data = w.write(i);
See also
FixedLengthFileWriter

Member Function Documentation

FixedLengthUtil::FixedLengthDataWriter::constructor ( hash  specs,
*hash  opts 
)

Instantiates the FixedLengthDataWriter object.

Parameters
specsFixed-length line specification; see Specification Hash for more information
optsGlobal formatting options; see Global Options for valid values
string FixedLengthUtil::FixedLengthDataWriter::write ( list  lines)

iterates the input records and returns a string corresponding to the rendered versions of all input records

Example:
1 FixedLengthDataWriter w(Spec);
2 string file = w.write(input_list);
Parameters
linesAn iterator to stream input records; each iterator value must be a hash with the following keys:
  • "type": a string giving the record type (must be defined in Specification Hash given in the constructor)
  • "record": a hash giving the input record to be rendered (with keys as defined in the Record Description Hash for the record identified by the type argument)
Returns
the rendered string for all input records
Exceptions
INVALID-RECORDrecord name (type key in the record hash) not recognized
FIELD-INPUT-ERRORthe input value is too large to render into the output field
RECORD-TRANSITION-ERRORa record transition error occurred; an invalid record sequence was given in the input data
string FixedLengthUtil::FixedLengthDataWriter::write ( hash  line)

Return a single line for a single input record hash.

Example:
1 const Spec = (
2  "header": (
3  "flow_type": ("length": 3, "type": "string"),
4  "record_type": ("length": 3, "type": "int", "padding_char": "0"),
5  "number_of_records": ("length": 8, "type": "int", "padding_char": "0"),
6  ),
7 );
8 hash hh = (
9  "type": "header",
10  "record": (
11  "flow_type": "WTS",
12  "record_type": "950",
13  "number_of_records": 1,
14  ),
15 );
16 FixedLengthDataWriter w(Spec);
17 string line = w.write(hh);
Parameters
lineA hash representing input data to be rendered as a string; the hash must have the following keys:
  • "type": a string giving the record type (must be defined in Specification Hash given in the constructor)
  • "record": a hash giving the input record to be rendered (with keys as defined in the Record Description Hash for the record identified by the type argument)
Returns
a single line for a single input record hash
Exceptions
INVALID-RECORDrecord name (type key in the record hash) not recognized
FIELD-INPUT-ERRORthe input value is too large to render into the output field
RECORD-TRANSITION-ERRORa record transition error occurred; an invalid record sequence was given in the input data
string FixedLengthUtil::FixedLengthDataWriter::write ( Qore::AbstractIterator  lines)

iterates the input records and returns a string corresponding to the rendered versions of all input records

Example:
1 FixedLengthDataWriter w(Spec);
2 string file = w.write(i);
Parameters
linesAn iterator to stream input records; each iterator value must be a hash with the following keys:
  • "type": a string giving the record type (must be defined in Specification Hash given in the constructor)
  • "record": a hash giving the input record to be rendered (with keys as defined in the Record Description Hash for the record identified by the type argument)
Returns
the rendered string for all input records
Exceptions
INVALID-RECORDrecord name (type key in the record hash) not recognized
FIELD-INPUT-ERRORthe input value is too large to render into the output field
RECORD-TRANSITION-ERRORa record transition error occurred; an invalid record sequence was given in the input data