public class PacketLineIn
extends java.lang.Object
This class is not thread safe and may issue multiple reads to the underlying stream for each method call made.
This class performs no buffering on its own. This makes it suitable to interleave reads performed by this class with reads performed directly against the underlying InputStream.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
PacketLineIn.AckNackResult |
static class |
PacketLineIn.InputOverLimitIOException
IOException thrown by read when the configured input limit is exceeded.
|
static class |
PacketLineIn.PacketLineInIterator
Iterator over packet lines.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DELIM
Deprecated.
Callers should use
isDelimiter(String) to check if a
string is the delimiter. |
static java.lang.String |
END
Deprecated.
Callers should use
isEnd(String) to check if a
string is the end marker, or
readStrings() to iterate over all
strings in the input stream until the marker is reached. |
private java.io.InputStream |
in |
private long |
limit |
private byte[] |
lineBuffer |
private static org.slf4j.Logger |
log |
Constructor and Description |
---|
PacketLineIn(java.io.InputStream in)
Create a new packet line reader.
|
PacketLineIn(java.io.InputStream in,
long limit)
Create a new packet line reader.
|
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.String |
delimiter()
Get the delimiter marker.
|
(package private) void |
discardUntilEnd() |
(package private) static java.lang.String |
end()
Get the end marker.
|
private java.io.IOException |
invalidHeader() |
private java.io.IOException |
invalidHeader(java.lang.Throwable cause) |
static boolean |
isDelimiter(java.lang.String s)
Check if a string is the delimiter marker.
|
static boolean |
isEnd(java.lang.String s)
Check if a string is the packet end marker.
|
(package private) PacketLineIn.AckNackResult |
readACK(MutableObjectId returnedId) |
(package private) int |
readLength() |
java.lang.String |
readString()
Read a single UTF-8 encoded string packet from the input stream.
|
java.lang.String |
readStringRaw()
Read a single UTF-8 encoded string packet from the input stream.
|
PacketLineIn.PacketLineInIterator |
readStrings()
Get an iterator to read strings from the input stream.
|
private static final org.slf4j.Logger log
@Deprecated public static final java.lang.String END
isEnd(String)
to check if a
string is the end marker, or
readStrings()
to iterate over all
strings in the input stream until the marker is reached.readString()
when a flush packet is found.@Deprecated public static final java.lang.String DELIM
isDelimiter(String)
to check if a
string is the delimiter.readString()
when a delim packet is found.private final byte[] lineBuffer
private final java.io.InputStream in
private long limit
public PacketLineIn(java.io.InputStream in)
in
- the input stream to consume.public PacketLineIn(java.io.InputStream in, long limit)
in
- the input stream to consume.limit
- bytes to read from the input; unlimited if set to 0.PacketLineIn.AckNackResult readACK(MutableObjectId returnedId) throws java.io.IOException
java.io.IOException
public java.lang.String readString() throws java.io.IOException
If the string ends with an LF, it will be removed before returning the
value to the caller. If this automatic trimming behavior is not desired,
use readStringRaw()
instead.
public PacketLineIn.PacketLineInIterator readStrings() throws java.io.IOException
readString()
until END
is encountered.java.io.IOException
- on failure to read the initial packet line.public java.lang.String readStringRaw() throws java.io.IOException
Unlike readString()
a trailing LF will be retained.
END
if the string was the magic flush
packet.java.io.IOException
- the stream cannot be read.public static boolean isDelimiter(java.lang.String s)
s
- the string to checkDELIM
, otherwise false.static java.lang.String delimiter()
Intended for use only in tests.
static java.lang.String end()
Intended for use only in tests.
public static boolean isEnd(java.lang.String s)
s
- the string to checkEND
, otherwise false.void discardUntilEnd() throws java.io.IOException
java.io.IOException
int readLength() throws java.io.IOException
java.io.IOException
private java.io.IOException invalidHeader()
private java.io.IOException invalidHeader(java.lang.Throwable cause)