org.milyn.edisax
Class BufferedSegmentReader

java.lang.Object
  extended by org.milyn.edisax.BufferedSegmentReader

public class BufferedSegmentReader
extends Object

Buffered EDI Stream Segment reader.

Author:
tfennelly

Field Summary
static String IGNORE_CR_LF
           
 
Constructor Summary
BufferedSegmentReader(InputSource ediInputSource, Delimiters rootDelimiters)
          Construct the stream reader.
 
Method Summary
 Charset changeEncoding(Charset encoding)
          Change the encoding used to read the underlying EDI data stream.
 String[] getCurrentSegmentFields()
          Get the current EDI segment fields.
 int getCurrentSegmentNumber()
          Get the current segment "number".
 Delimiters getDelimiters()
          Get the current delimiter set.
 Stack<Delimiters> getDelimitersStack()
          Get the
 StringBuffer getSegmentBuffer()
          Get the segment buffer.
 boolean hasCurrentSegment()
          Does the read have a segment buffered and ready for processing.
 void mark()
          Try mark the stream so we can support changing of the reader encoding.
 boolean moveToNextSegment()
          Move to the next EDI segment.
 boolean moveToNextSegment(boolean clearBuffer)
          Move to the next EDI segment.
 String peek(int numChars)
          Peek a fixed number of characters from the input source.
 String peek(int numChars, boolean ignoreLeadingWhitespace)
          Peek a fixed number of characters from the input source.
 void popDelimiters()
          Restore the parent delimiters set.
 void pushDelimiters(Delimiters delimiters)
          Push in a new Delimiters set into the reader.
 String read(int numChars)
          Read a fixed number of characters from the input source.
 void setIgnoreNewLines(boolean ignoreNewLines)
          Set ignore new lines in the EDI Stream.
 void setSegmentListener(BufferedSegmentListener segmentListener)
          Set the segment listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IGNORE_CR_LF

public static String IGNORE_CR_LF
Constructor Detail

BufferedSegmentReader

public BufferedSegmentReader(InputSource ediInputSource,
                             Delimiters rootDelimiters)
Construct the stream reader.

Parameters:
ediInputSource - EDI Stream input source.
rootDelimiters - Root currentDelimiters. New currentDelimiters can be pushed and popped.
Method Detail

mark

public void mark()
Try mark the stream so we can support changing of the reader encoding.

See Also:
changeEncoding(Charset)

changeEncoding

public Charset changeEncoding(Charset encoding)
                       throws IOException
Change the encoding used to read the underlying EDI data stream.

mark() should have been called first.

Parameters:
encoding - The new encoding.
Returns:
The old/replaced encoding if known, otherwise null.
Throws:
IOException - Failed to skip already read characters.

getDelimiters

public Delimiters getDelimiters()
Get the current delimiter set.

Returns:
the currentDelimiters The current delimiter set.

pushDelimiters

public void pushDelimiters(Delimiters delimiters)
Push in a new Delimiters set into the reader.

Parameters:
delimiters - New delimiters.

popDelimiters

public void popDelimiters()
Restore the parent delimiters set.

Be sure to get the delimiters stack and check that it is not empty before popping.


getDelimitersStack

public Stack<Delimiters> getDelimitersStack()
Get the

Returns:
the delimitersStack

setIgnoreNewLines

public void setIgnoreNewLines(boolean ignoreNewLines)
Set ignore new lines in the EDI Stream.

Some EDI messages are formatted with new lines for readability and so the new line characters should be ignored.

Parameters:
ignoreNewLines - True if new line characters should be ignored, otherwise false.

read

public String read(int numChars)
            throws IOException
Read a fixed number of characters from the input source.

Parameters:
numChars - The number of characters to read.
Returns:
The characters in a String. If the end of the input source was reached, the length of the string will be less than the requested number of characters.
Throws:
IOException - Error reading from input source.

peek

public String peek(int numChars)
            throws IOException
Peek a fixed number of characters from the input source.

Peek differs from read(int) in that it leaves the characters in the segment buffer.

Parameters:
numChars - The number of characters to peeked.
Returns:
The characters in a String. If the end of the input source was reached, the length of the string will be less than the requested number of characters.
Throws:
IOException - Error reading from input source.

peek

public String peek(int numChars,
                   boolean ignoreLeadingWhitespace)
            throws IOException
Peek a fixed number of characters from the input source.

Peek differs from read(int) in that it leaves the characters in the segment buffer.

Parameters:
numChars - The number of characters to peeked.
ignoreLeadingWhitespace - Ignore leading whitespace.
Returns:
The characters in a String. If the end of the input source was reached, the length of the string will be less than the requested number of characters.
Throws:
IOException - Error reading from input source.

setSegmentListener

public void setSegmentListener(BufferedSegmentListener segmentListener)
Set the segment listener.

Parameters:
segmentListener - The segment listener.

moveToNextSegment

public boolean moveToNextSegment()
                          throws IOException
Move to the next EDI segment.

Simply reads and buffers the next EDI segment. Clears the current contents of the buffer before reading.

Returns:
True if a "next" segment exists, otherwise false.
Throws:
IOException - Error reading from EDI stream.

moveToNextSegment

public boolean moveToNextSegment(boolean clearBuffer)
                          throws IOException
Move to the next EDI segment.

Simply reads and buffers the next EDI segment.

Parameters:
clearBuffer - Clear the segment buffer before reading.
Returns:
True if a "next" segment exists, otherwise false.
Throws:
IOException - Error reading from EDI stream.

hasCurrentSegment

public boolean hasCurrentSegment()
Does the read have a segment buffered and ready for processing.

Returns:
True if a current segment exists, otherwise false.

getSegmentBuffer

public StringBuffer getSegmentBuffer()
Get the segment buffer.

Returns:
The segment buffer.

getCurrentSegmentFields

public String[] getCurrentSegmentFields()
                                 throws IllegalStateException
Get the current EDI segment fields.

Returns:
The current EDI segment fields array.
Throws:
IllegalStateException - No current Segment.

getCurrentSegmentNumber

public int getCurrentSegmentNumber()
Get the current segment "number".

The first segment is "segment number 1".

Returns:
The "number" of the current segment.


Copyright © 2018. All rights reserved.