Package org.apache.synapse.format.syslog
Class InputStreamConsumer
- java.lang.Object
-
- org.apache.synapse.format.syslog.InputStreamConsumer
-
public class InputStreamConsumer extends Object
Input stream consumer. This is a helper class used bySyslogMessageBuilderto 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 Constructor Description InputStreamConsumer(InputStream in)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconsume()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.intgetPosition()Get 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 Detail
-
InputStreamConsumer
public InputStreamConsumer(InputStream in)
Constructor.- Parameters:
in- the input stream to consume data from
-
-
Method Detail
-
next
public int next() throws IOExceptionGet 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
public void expect(int expected) throws IOException, ProtocolExceptionCheck 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
public void consume(int expected) throws IOException, ProtocolExceptionCheck 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
public int getInteger(int maxDigits) throws IOException, ProtocolExceptionRead 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
-
-