Qore FixedLengthUtil Module Reference  1.0
FixedLengthUtil::FixedLengthFileWriter Class Reference

Writer for fixed-length-line output files. More...

Inheritance diagram for FixedLengthUtil::FixedLengthFileWriter:

Public Member Functions

 constructor (string file_name, hash specs, *hash opts)
 Instantiates the FixedLengthFileWriter object. More...
 
string getFileName ()
 Return the file name.
 
 write (hash line)
 Renders a single line for a single input record hash to the output file. More...
 
 write (list lines)
 iterates the input records and writes rendered versions of all input records to the file More...
 
 write (Qore::AbstractIterator lines)
 iterates the input records and writes rendered versions of all input records to the file 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 for fixed-length-line output files.

Example:
1 #!/usr/bin/env qore
2 
3 %new-style
4 %enable-all-warnings
5 %require-types
6 %strict-args
7 
8 %requires FixedLengthUtil
9 
10 list data = (
11  ("type": "type1", "record": {"col1" : 11111, "col2" : "bb"}),
12  ("type": "type2", "record": {"col3" : "c", "col4" : "ddd", "col5" : "31122014"}),
13  ("type": "type1", "record": {"col1" : 22222, "col2" : "gg"}),
14 );
15 
16 hash specs = (
17  "type1" : (
18  "col1": ("length": 5, "type": "int"),
19  "col2": ("length": 2, "type": "string"),
20  ),
21  "type2" : (
22  "col3" : ("length": 1, "type": "string"),
23  "col4" : ("length" : 3, "type": "string"),
24  "col5" : ("length" : 8, "type": "date", "format": "DDMMYYYY", "timezone" : "Europe/Prague"),
25  ),
26 );
27 
28 hash global_options = (
29  "eol" : "\n",
30 );
31 
32 FixedLengthFileWriter w(file, specs, global_options);
33 w.write(data);
See also
FixedLengthDataWriter

Member Function Documentation

FixedLengthUtil::FixedLengthFileWriter::constructor ( string  file_name,
hash  specs,
*hash  opts 
)

Instantiates the FixedLengthFileWriter object.

Parameters
file_namethe output file path
specsFixed-length line specification; see Specification Hash for more information
optsGlobal options; see Global Options for valid values
FixedLengthUtil::FixedLengthFileWriter::write ( hash  line)

Renders a single line for a single input record hash to the output file.

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 FixedLengthFileWriter w(Spec);
17 w.write(hh);
Parameters
lineA hash representing input data to be writen to the file; 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)
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
FixedLengthUtil::FixedLengthFileWriter::write ( list  lines)

iterates the input records and writes rendered versions of all input records to the file

Example:
1 FixedLengthFileWriter w(output_file, Spec);
2 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)
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
FixedLengthUtil::FixedLengthFileWriter::write ( Qore::AbstractIterator  lines)

iterates the input records and writes rendered versions of all input records to the file

Example:
1 FixedLengthFileWriter w(output_file, Spec);
2 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)
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