-
-
Notifications
You must be signed in to change notification settings - Fork 36
Writing EDI Data (Configuration)
This article assumes the reader has basic knowledge of EDI structures and terminology
The EDIStreamWriter
can be configured using several properties (set on the EDIOutputFactory
) to modify the writers's behavior.
// (1) Create an EDIOutputFactory
EDIOutputFactory factory = EDIOutputFactory.newFactory();
// (2) Optionally specify delimiters - here the given values are the same as default
factory.setProperty(EDIStreamConstants.Delimiters.SEGMENT, '~');
factory.setProperty(EDIStreamConstants.Delimiters.DATA_ELEMENT, '*');
// Write each segment on a new line
factory.setProperty(EDIOutputFactory.PRETTY_PRINT, true);
// (3) Create an EDIStreamWriter. Any OutputStream may be used - here we are writing to the console
EDIStreamWriter writer = factory.createEDIStreamWriter(System.out);
// Continue processing with the writer...
Default: false
Setting this value to true
will configure the writer to output a line separate string (as determined by the line.separator
system property).
Default: false
Setting this value to true
indicates to the writer that trailing empty elements should not be written to the output.
For example, the following two segments are the same, with the exception that the first example has trailing empty segments present in the ouput.
When false
: SEG*E1*****~
When true
: SEG*E1~
The delimiters used in the output may be configured using the following configuration keys:
EDIStreamConstants.Delimiters.SEGMENT
EDIStreamConstants.Delimiters.DATA_ELEMENT
EDIStreamConstants.Delimiters.COMPONENT_ELEMENT
-
EDIStreamConstants.Delimiters.REPETITION
(when supported by interchange version) -
EDIStreamConstants.Delimiters.DECIMAL
(EDIFACT only) -
EDIStreamConstants.Delimiters.RELEASE
(when supported by interchange version)
Note, when writing EDIFACT data and any of the delimiters have been specified, the writer will automatically output a UNA
segment with the configured delimiters (or the default values for those that have not been configured).
Since: 1.11
Default: false
Setting this value to true
will configure the writer to format element values to meet minimum length requirements. Use of this configuration option is dependent upon the use of a schema. Depending on which segment is being written, either the control schema (EDIStreamWriter#setControlSchema
) or the transaction schema (EDIStreamWriter#setTransactionSchema
) will be consulted for the type and length requirements. Padding occurs before the minimum length is validated using the same schema.
For example, if an element has a minimum length of 10 and an application writes the value "VALUE"
, the string actually written to the output EDI stream will be padded to "VALUE "
, which has 5 trailing spaces.
By default, StAEDI will write EDI output using the UTF-8 standard character set. The character set may be overridden by creating an instance of EDIStreamWriter
(via EDIOutputFactory
) with the name of an alternate Charset
. Names of Charset
s that return true
for a call to Charset#isSupported
may be used.