Package org.apache.synapse.format.syslog
Class InputStreamConsumer
java.lang.Object
org.apache.synapse.format.syslog.InputStreamConsumer
Input stream consumer.
This is a helper class used by
SyslogMessageBuilder to parse data
from an input stream. In particular it supports look ahead and allows to
buffer and reread data from the stream.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconsume()Consume the last byte read from the stream and advance to the next byte.voidconsume(int expected) Check the value of the next byte in the stream and consume it.voidexpect(int expected) Check the value of the next byte in the stream.intgetInteger(int maxDigits) Read a decimal representation of an integer from the stream.intGet the current position in the stream.intnext()Get the next byte from the stream without consuming it.voidsetPosition(int position) Reset the stream position to a previous value.
-
Constructor Details
-
InputStreamConsumer
Constructor.- Parameters:
in- the input stream to consume data from
-
-
Method Details
-
next
Get the next byte from the stream without consuming it. If the byte is not consumed between invocations, two successive calls to this method will return the same result.- Returns:
- the next byte as an integer value in the range 0..255 or -1 if the end of the stream has been reached
- Throws:
IOException- if an I/O error occurred while reading from the stream
-
consume
public void consume()Consume the last byte read from the stream and advance to the next byte. -
getPosition
public int getPosition()Get the current position in the stream.- Returns:
- the position in the stream
-
setPosition
public void setPosition(int position) Reset the stream position to a previous value.- Parameters:
position- the new position
-
expect
Check the value of the next byte in the stream.- Parameters:
expected- the expected value- Throws:
IOException- if an I/O error occurred while reading from the streamProtocolException- if the next byte doesn't have the expected value
-
consume
Check the value of the next byte in the stream and consume it. This is a convenience method that combines a call toexpect(int)with a call toconsume().- Parameters:
expected- the expected value- Throws:
IOException- if an I/O error occurred while reading from the streamProtocolException- if the next byte doesn't have the expected value
-
getInteger
Read a decimal representation of an integer from the stream.- Parameters:
maxDigits- the maximum number of expected digits- Returns:
- the integer value
- Throws:
IOException- if an I/O error occurred while reading from the streamProtocolException- if no integer value was found or if it was too long
-