- java.lang.Object
-
- io.xlate.edi.internal.stream.StaEDIStreamReader
-
- All Implemented Interfaces:
EDIStreamConstants,EDIStreamReader,Closeable,AutoCloseable
public class StaEDIStreamReader extends Object implements EDIStreamReader
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.xlate.edi.stream.EDIStreamConstants
EDIStreamConstants.Delimiters, EDIStreamConstants.Standards
-
-
Constructor Summary
Constructors Constructor Description StaEDIStreamReader(InputStream stream, String encoding, Schema schema, Map<String,Object> properties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Frees any resources associated with this Reader.InputStreamgetBinaryData()Returns a ByteBuffer object containing the binary element data read in the previous data element.Map<String,Character>getDelimiters()Retrieve a read-only map of delimiters in use for the stream being read.EDIStreamValidationErrorgetErrorType()Returns an integer code that indicates the type of error the cursor is pointing to.EDIStreamEventgetEventType()Returns an integer code that indicates the type of the event the cursor is pointing to.LocationgetLocation()Return the current location of the processor.ObjectgetProperty(String name)Get the value of a feature/property from the underlying implementationStringgetReferenceCode()Return the reference code for the current element if a schema has been set and the current processing state is within an interchange.StringgetStandard()Get the EDI standard name.StringgetText()Returns the current value of the parse event as a string.char[]getTextCharacters()Returns an array which contains the characters from this event.intgetTextCharacters(int sourceStart, char[] target, int targetStart, int length)Gets the the text associated with a ELEMENT_DATA, ELEMENT_ERROR, START_SEGMENT, or END_SEGMENT event.intgetTextLength()Returns the length of the sequence of characters for this Text event within the text character array.intgetTextStart()Returns the offset into the text character array where the first character (of this text event) is stored.String[]getVersion()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.EDIStreamEventnext()Get next parsing eventEDIStreamEventnextTag()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 Detail
-
getProperty
public Object getProperty(String name)
Description copied from interface:EDIStreamReaderGet the value of a feature/property from the underlying implementation- Specified by:
getPropertyin interfaceEDIStreamReader- Parameters:
name- - The name of the property, may not be null- Returns:
- The value of the property
-
getDelimiters
public Map<String,Character> getDelimiters()
Description copied from interface:EDIStreamReaderRetrieve a read-only map of delimiters in use for the stream being read.- Specified by:
getDelimitersin interfaceEDIStreamReader- Returns:
- The value of the property
-
next
public EDIStreamEvent next() throws EDIStreamException
Description copied from interface:EDIStreamReaderGet next parsing event- Specified by:
nextin interfaceEDIStreamReader- Returns:
- the integer code corresponding to the current parse event
- Throws:
EDIStreamException- if there is an error processing the underlying XML source
-
nextTag
public EDIStreamEvent nextTag() throws EDIStreamException
Description copied from interface:EDIStreamReaderSkips any ELEMENT_DATA, START_COMPOSITE, and END_COMPOSITE until a START_SEGMENT is reached.- Specified by:
nextTagin interfaceEDIStreamReader- Returns:
- the event type of the element read - START_SEGMENT
- Throws:
EDIStreamException- if the current event is not following START_INTERCHANGE and preceding END_INTERCHANGE
-
hasNext
public boolean hasNext() throws EDIStreamExceptionDescription copied from interface:EDIStreamReaderReturns 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- Specified by:
hasNextin interfaceEDIStreamReader- Returns:
- true if there are more events, false otherwise
- Throws:
EDIStreamException- if there is a fatal error detecting the next state
-
close
public void close() throws IOExceptionDescription copied from interface:EDIStreamReaderFrees any resources associated with this Reader. This method does not close the underlying input stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceEDIStreamReader- Throws:
IOException- if there are errors freeing associated resources
-
getEventType
public EDIStreamEvent getEventType()
Description copied from interface:EDIStreamReaderReturns an integer code that indicates the type of the event the cursor is pointing to.- Specified by:
getEventTypein interfaceEDIStreamReader- Returns:
- code that indicates the type of the event the cursor is pointing to
-
getStandard
public String getStandard()
Description copied from interface:EDIStreamReaderGet the EDI standard name. Calls to this method are only valid when the interchange type has been determined, after START_INTERCHANGE.- Specified by:
getStandardin interfaceEDIStreamReader- Returns:
- the name of the EDI standard
-
getVersion
public String[] getVersion()
Description copied from interface:EDIStreamReaderGet 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.- Specified by:
getVersionin interfaceEDIStreamReader- Returns:
- the version
-
setControlSchema
public void setControlSchema(Schema schema)
Description copied from interface:EDIStreamReaderSets 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.
- Specified by:
setControlSchemain interfaceEDIStreamReader- Parameters:
schema- the schema instance to use for validation of control structures
-
setTransactionSchema
public void setTransactionSchema(Schema schema)
Description copied from interface:EDIStreamReaderSets 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 before the end of the segment representing the beginning of the transaction.
- Specified by:
setTransactionSchemain interfaceEDIStreamReader- Parameters:
schema- the schema instance to use for validation of business transaction structures
-
getReferenceCode
public String getReferenceCode()
Description copied from interface:EDIStreamReaderReturn 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.- Specified by:
getReferenceCodein interfaceEDIStreamReader- Returns:
- the reference code from the schema for the current EDIType
-
getErrorType
public EDIStreamValidationError getErrorType()
Description copied from interface:EDIStreamReaderReturns 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.- Specified by:
getErrorTypein interfaceEDIStreamReader- Returns:
- code that indicates the type of the error the cursor is pointing to
-
getText
public String getText()
Description copied from interface:EDIStreamReaderReturns the current value of the parse event as a string. This returns the string value of an ELEMENT_DATA event, and the string value of a segment tag in a START_SEGMENT event. During an ELEMENT_ERROR event, this contains the invalid element.- Specified by:
getTextin interfaceEDIStreamReader- Returns:
- the current text or null
-
getTextCharacters
public char[] getTextCharacters()
Description copied from interface:EDIStreamReaderReturns an array which contains the characters from this event. 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.- Specified by:
getTextCharactersin interfaceEDIStreamReader- Returns:
- the current text or an empty array
-
getTextCharacters
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)Description copied from interface:EDIStreamReaderGets the the text associated with a ELEMENT_DATA, ELEMENT_ERROR, START_SEGMENT, or END_SEGMENT event. 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".- Specified by:
getTextCharactersin interfaceEDIStreamReader- 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
-
getTextStart
public int getTextStart()
Description copied from interface:EDIStreamReaderReturns the offset into the text character array where the first character (of this text event) is stored.- Specified by:
getTextStartin interfaceEDIStreamReader- Returns:
- offset into the text character array where the first character is stored
-
getTextLength
public int getTextLength()
Description copied from interface:EDIStreamReaderReturns the length of the sequence of characters for this Text event within the text character array.- Specified by:
getTextLengthin interfaceEDIStreamReader- Returns:
- length of the sequence of characters for this Text event
-
getLocation
public Location getLocation()
Description copied from interface:EDIStreamReaderReturn 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.- Specified by:
getLocationin interfaceEDIStreamReader- Returns:
- current location of the processor
-
setBinaryDataLength
public void setBinaryDataLength(long length) throws EDIStreamExceptionDescription copied from interface:EDIStreamReaderSets 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.
- Specified by:
setBinaryDataLengthin interfaceEDIStreamReader- Parameters:
length- - the number of bytes to read as binary data and not as EDI-formatted- Throws:
EDIStreamException- if there are IO errors allocating resources for binary data processing
-
getBinaryData
public InputStream getBinaryData()
Description copied from interface:EDIStreamReaderReturns a ByteBuffer object containing the binary element data read in the previous data element. The limit of the buffer will be set to the length of the data.- Specified by:
getBinaryDatain interfaceEDIStreamReader- Returns:
- buffer containing binary data
-
-