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 bySyslogMessageBuilder
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 Constructor Description InputStreamConsumer(InputStream in)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
consume()
Consume the last byte read from the stream and advance to the next byte.void
consume(int expected)
Check the value of the next byte in the stream and consume it.void
expect(int expected)
Check the value of the next byte in the stream.int
getInteger(int maxDigits)
Read a decimal representation of an integer from the stream.int
getPosition()
Get the current position in the stream.int
next()
Get the next byte from the stream without consuming it.void
setPosition(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 IOException
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
public void expect(int expected) throws IOException, ProtocolException
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
public void consume(int expected) throws IOException, ProtocolException
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
public int getInteger(int maxDigits) throws IOException, ProtocolException
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
-
-