- All Superinterfaces:
AutoCloseable,Closeable,EDIStreamConstants
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.xlate.edi.stream.EDIStreamConstants
EDIStreamConstants.Delimiters, EDIStreamConstants.Standards -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Frees any resources associated with this Reader.Returns an InputStream for reading the binary element data for the current element.Returns the control schema currently set on the reader.Retrieve a read-only map of delimiters in use for the stream being read.Returns an integer code that indicates the type of error the cursor is pointing to.Returns an integer code that indicates the type of the event the cursor is pointing to.Return the current location of the processor.getProperty(String name) Get the value of a feature/property from the underlying implementationReturn the reference code for the current element if a schema has been set and the current processing state is within an interchange.Returns anEDIReferencefor the schema type at the current point in the reader's input stream.Get the EDI standard name.getText()Returns the current value of the parse event as a string.char[]Returns an array which contains the characters from this event (as specified bygetText()).intgetTextCharacters(int sourceStart, char[] target, int targetStart, int length) Returns the the text associated with an event (as specified bygetText()).intReturns the length of the sequence of characters for this Text event within the text character array.intReturns the offset into the text character array where the first character (of this text event) is stored.Returns the schema currently set on the reader to be used for validation of the business transaction.The transaction type string as received in a standard-specific location.String[]Get the transaction version declared on the transaction header segment or the functional group header segment (X12 only).The transaction version string elements as a single, period-delimited value.String[]Get the interchange version declared on the interchange begin segment.booleanhasNext()Returns true if there are more parsing events and false if there are no more events.booleanhasText()Return true if the current event has text, false otherwise.next()Get next parsing eventnextTag()Skips any ELEMENT_DATA, START_COMPOSITE, and END_COMPOSITE until a START_SEGMENT is reached.voidsetBinaryDataLength(long length) Sets the number of bytes that should be read as binary data and not interpreted as EDI data.voidsetControlSchema(Schema schema) Sets the schema to be used for validation of the control structure for this stream reader.voidsetTransactionSchema(Schema schema) Sets the schema to be used for validation of the business transaction for this stream reader.
-
Method Details
-
getProperty
Get the value of a feature/property from the underlying implementation- Parameters:
name- - The name of the property, may not be null- Returns:
- The value of the property
- Throws:
IllegalArgumentException- if name is null
-
getDelimiters
Retrieve a read-only map of delimiters in use for the stream being read.- Returns:
- The value of the property
- Throws:
IllegalStateException- if called outside of an interchange
-
next
Get next parsing event- Returns:
- the integer code corresponding to the current parse event
- Throws:
NoSuchElementException- if this is called when hasNext() returns falseEDIStreamException- if there is an error processing the underlying EDI source
-
nextTag
Skips any ELEMENT_DATA, START_COMPOSITE, and END_COMPOSITE until a START_SEGMENT is reached.- Returns:
- the event type of the element read - START_SEGMENT
- Throws:
NoSuchElementException- if this is called when hasNext() returns false or there are no additional START_SEGMENT events in the streamEDIStreamException- if the current event is not following START_INTERCHANGE and preceding END_INTERCHANGE
-
hasNext
Returns true if there are more parsing events and false if there are no more events. This method will return false if the current state of the EDIStreamReader is END_INTERCHANGE- Returns:
- true if there are more events, false otherwise
- Throws:
EDIStreamException- if there is a fatal error detecting the next state
-
close
Frees any resources associated with this Reader. This method does not close the underlying input stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if there are errors freeing associated resources
-
getEventType
EDIStreamEvent getEventType()Returns an integer code that indicates the type of the event the cursor is pointing to.- Returns:
- code that indicates the type of the event the cursor is pointing to
-
getStandard
String getStandard()Get the EDI standard name. Calls to this method are only valid when the interchange type has been determined, after START_INTERCHANGE.- Returns:
- the name of the EDI standard
- Throws:
IllegalStateException- when the standard has not yet been determined, prior to the start of an interchange
-
getVersion
String[] getVersion()Get the interchange version declared on the interchange begin segment. Calls to this method are only valid when interchange type has been determined, after START_INTERCHANGE. The elements of the returned array are specific to the standard:For EDIFACT:
- Syntax identifier: UNB01-1
- Syntax version number: UNB01-2
- Service code list directory version number: UNB01-3 (syntax version 4+)
- Character encoding, coded: UNB01-4 (syntax version 4+)
- Syntax release number: UNB01-5 (syntax version and release 4.1+)
For X12:
- Interchange Control Version Number: ISA12
For TRADACOMS:
- Syntax rules identifier: STX01-1
- Syntax rules version: STX01-2
- Returns:
- the version
- Throws:
IllegalStateException- when the version has not yet been determined, prior to the start of an interchange
-
getTransactionVersion
String[] getTransactionVersion()Get the transaction version declared on the transaction header segment or the functional group header segment (X12 only). Calls to this method are only valid when interchange type has been determined, after START_INTERCHANGE, and the transaction version has been determined by reading the dialect-specific data elements containing the version value(s). The elements of the returned array are defined as:- Agency code
- Version
- Release
- Industry code
For EDIFACT:
- Agency code: UNH02-4
- Version: UNH02-2
- Release: UNH02-3
- Industry code: UNH02-5
For X12:
- Agency code: GS07
- Version/Release/Industry code: GS08 (or ST03, when used)
- Returns:
- the transaction version
- Throws:
IllegalStateException- when the version has not yet been determined, prior to the start of a transaction (or functional group when in use)- Since:
- 1.9
-
getTransactionVersionString
String getTransactionVersionString()The transaction version string elements as a single, period-delimited value. This value may be used to obtain version-specific schema information available from theEDIReferencereturned fromgetSchemaTypeReference().- Returns:
- the transaction version as a single, period-delimited value
- Throws:
IllegalStateException- when the version has not yet been determined, prior to the start of a transaction (or functional group when in use)- Since:
- 1.9
-
getTransactionType
String getTransactionType()The transaction type string as received in a standard-specific location. For example, the ST01 or UNH02-1 elements.- Returns:
- the transaction type
- Throws:
IllegalStateException- when the type has not yet been determined, prior to the parsing of the transaction begin segment- Since:
- 1.16
-
getControlSchema
Schema getControlSchema()Returns the control schema currently set on the reader. If none has been set, then null will be returned.- Returns:
- the control schema current set on this reader, may be null
- Since:
- 1.5
-
setControlSchema
Sets the schema to be used for validation of the control structure for this stream reader. This schema will be used to validate interchange, group, and transaction/message envelopes.
Calls to this method are only valid when the current event type is START_INTERCHANGE.
- Parameters:
schema- the schema instance to use for validation of control structures- Throws:
IllegalStateException- when the current event type is not START_INTERCHANGE
-
getTransactionSchema
Schema getTransactionSchema()Returns the schema currently set on the reader to be used for validation of the business transaction. If none has been set, then null will be returned.- Returns:
- the transaction schema current set on this reader, may be null
- Since:
- 1.5
-
setTransactionSchema
Sets the schema to be used for validation of the business transaction for this stream reader. This schema will be used to validate only the contents of a transaction/message, not including the begin/end control structures.
Calls to this method are only valid after a START_TRANSACTION event and up to and including the END_SEGMENT event representing the beginning of the transaction.
- Parameters:
schema- the schema instance to use for validation of business transaction structures- Throws:
IllegalStateException- when the reader is not positioned on the start transaction segment
-
getReferenceCode
String getReferenceCode()Return the reference code for the current element if a schema has been set and the current processing state is within an interchange. Otherwise, an IllegalStateException will be thrown. If the reader encounters an unknown type, the reference code will be null.- Returns:
- the reference code from the schema for the current EDIType
- Throws:
IllegalStateException- when the current event type is not within an interchange
-
getErrorType
EDIStreamValidationError getErrorType()Returns an integer code that indicates the type of error the cursor is pointing to. Calls to this method are only valid when the current event type is SEGMENT_ERROR or ELEMENT_ERROR.- Returns:
- code that indicates the type of the error the cursor is pointing to
- Throws:
IllegalStateException- when the current event type is not SEGMENT_ERROR or ELEMENT_ERROR
-
getText
String getText()Returns the current value of the parse event as a string. This returns- the string value of an element for an
ELEMENT_DATAevent - the string value of a segment tag for a
START_SEGMENTevent - the string value of the current segment tag for an
END_SEGMENTevent - the invalid element text from an
ELEMENT_DATA_ERROR(when available) - the invalid element text from an
ELEMENT_OCCURRENCE_ERROR(when available) - the string value of a segment tag for a
SEGMENT_ERRORevent
- Returns:
- the current text or an empty
String - Throws:
IllegalStateException- if this state is not a valid text state
- the string value of an element for an
-
getTextCharacters
char[] getTextCharacters()Returns an array which contains the characters from this event (as specified bygetText()). This array should be treated as read-only and transient. I.e. the array will contain the text characters until the EDIStreamReader moves on to the next event. Attempts to hold onto the character array beyond that time or modify the contents of the array are breaches of the contract for this interface.- Returns:
- the current text or an empty array
- Throws:
IllegalStateException- if this state is not a valid text state
-
getTextCharacters
int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) Returns the the text associated with an event (as specified bygetText()). Text starting at "sourceStart" is copied into "target" starting at "targetStart". Up to "length" characters are copied. The number of characters actually copied is returned. The "sourceStart" argument must be greater or equal to 0 and less than or equal to the number of characters associated with the event. Usually, one requests text starting at a "sourceStart" of 0. If the number of characters actually copied is less than the "length", then there is no more text. Otherwise, subsequent calls need to be made until all text has been retrieved. For example:int length = 1024; char[] myBuffer = new char[length]; for (int sourceStart = 0;; sourceStart += length) { int nCopied = stream.getTextCharacters(sourceStart, myBuffer, 0, length); if (nCopied < length) break; }EDIStreamException may be thrown if there are any parsing errors in the underlying source. The "targetStart" argument must be greater than or equal to 0 and less than the length of "target", Length must be greater than 0 and "targetStart + length" must be less than or equal to length of "target".- Parameters:
sourceStart- - the index of the first character in the source array to copytarget- - the destination arraytargetStart- - the start offset in the target arraylength- - the number of characters to copy- Returns:
- the number of characters actually copied
- Throws:
IndexOutOfBoundsException- if targetStart < 0 or > than the length of targetIndexOutOfBoundsException- if length < 0 or targetStart + length > length of targetNullPointerException- if target is null
-
getTextStart
int getTextStart()Returns the offset into the text character array where the first character (of this text event) is stored.- Returns:
- offset into the text character array where the first character is stored
- Throws:
IllegalStateException- if this state is not a valid text state
-
getTextLength
int getTextLength()Returns the length of the sequence of characters for this Text event within the text character array.- Returns:
- length of the sequence of characters for this Text event
- Throws:
IllegalStateException- if this state is not a valid text state
-
getLocation
Location getLocation()Return the current location of the processor. If the Location is unknown the processor should return an implementation of Location that returns -1 for the location values. The location information is only valid until next() is called.- Returns:
- current location of the processor
-
setBinaryDataLength
Sets the number of bytes that should be read as binary data and not interpreted as EDI data. This EDIStreamReader will return to normal EDI parsing after reading this number of bytes. The byte immediately following length bytes must be a delimiter valid in the scope of the current interchange or an EDIStreamException will occur. This method must only be called immediately preceding a binary data element. Attempts to call it while the reader is in any other state will result in an IllegalStateException.Note: Applications parsing transactions which contain binary data elements must call this method to avoid the binary data being parsed as EDI content. The length of the binary data is typically found in a companion data element preceding the binary element in the stream.
- Parameters:
length- - the number of bytes to read as binary data and not as EDI-formatted- Throws:
IllegalStateException- if this state is not a state which may precede a data element.EDIStreamException- if there are IO errors allocating resources for binary data processing
-
getBinaryData
InputStream getBinaryData()Returns an InputStream for reading the binary element data for the current element. The length of the input stream is determined by the value previously passed tosetBinaryDataLength(long).- Returns:
- stream containing binary data
- Throws:
IllegalStateException- if the stream reader did not complete the scanning of a binary data element immediately preceding this call.
-
getSchemaTypeReference
EDIReference getSchemaTypeReference()Returns anEDIReferencefor the schema type at the current point in the reader's input stream. Information such as minimum and maximum occurrences, as well as theEDITypemay be obtained from the reference. If the reader is utilizing an implementation schema and the current schema type is an implemented type, the returned reference will be anEDITypeImplementation.- Returns:
- an
EDIReferencefor the schema type at the current point in the reader's input stream - Since:
- 1.9
-
hasText
boolean hasText()Return true if the current event has text, false otherwise. The following events have text:- START_SEGMENT
- END_SEGMENT
- ELEMENT_DATA
- ELEMENT_DATA_ERROR
- ELEMENT_OCCURRENCE_ERROR
- SEGMENT_ERROR
- Returns:
- true if the current event has text, false otherwise
- Since:
- 1.20
-