Package org.eclipse.jgit.transport
Class PacketLineIn
java.lang.Object
org.eclipse.jgit.transport.PacketLineIn
Read Git style pkt-line formatting from an input stream.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum
static class
IOException thrown by read when the configured input limit is exceeded.static class
Iterator over packet lines. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Deprecated.static final String
Deprecated.Callers should useisEnd(String)
to check if a string is the end marker, orreadStrings()
to iterate over all strings in the input stream until the marker is reached.private final InputStream
private long
private final byte[]
private static final org.slf4j.Logger
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new packet line reader.PacketLineIn
(InputStream in, long limit) Create a new packet line reader. -
Method Summary
Modifier and TypeMethodDescription(package private) static String
Get the delimiter marker.(package private) void
(package private) static String
end()
Get the end marker.private IOException
private IOException
invalidHeader
(Throwable cause) static boolean
Check if a string is the delimiter marker.static boolean
Check if a string is the packet end marker.(package private) static PacketLineIn.AckNackResult
parseACKv2
(String line, MutableObjectId returnedId) Parses a ACK/NAK line in protocol V2.(package private) PacketLineIn.AckNackResult
readACK
(MutableObjectId returnedId) (package private) int
Read a single UTF-8 encoded string packet from the input stream.Read a single UTF-8 encoded string packet from the input stream.Get an iterator to read strings from the input stream.
-
Field Details
-
log
private static final org.slf4j.Logger log -
END
Deprecated.Callers should useisEnd(String)
to check if a string is the end marker, orreadStrings()
to iterate over all strings in the input stream until the marker is reached.Magic return fromreadString()
when a flush packet is found. -
DELIM
Deprecated.Callers should useisDelimiter(String)
to check if a string is the delimiter.Magic return fromreadString()
when a delim packet is found.- Since:
- 5.0
-
lineBuffer
private final byte[] lineBuffer -
in
-
limit
private long limit
-
-
Constructor Details
-
PacketLineIn
Create a new packet line reader.- Parameters:
in
- the input stream to consume.
-
PacketLineIn
Create a new packet line reader.- Parameters:
in
- the input stream to consume.limit
- bytes to read from the input; unlimited if set to 0.- Since:
- 4.7
-
-
Method Details
-
parseACKv2
static PacketLineIn.AckNackResult parseACKv2(String line, MutableObjectId returnedId) throws IOException Parses a ACK/NAK line in protocol V2.- Parameters:
line
- to parsereturnedId
- in case ofACK_COMMON
- Returns:
- one of
NAK
,ACK_COMMON
, orACK_READY
- Throws:
IOException
- on protocol or transport errors
-
readACK
- Throws:
IOException
-
readString
Read a single UTF-8 encoded string packet from the input stream.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.- Returns:
- the string.
END
if the string was the magic flush packet,DELIM
if the string was the magic DELIM packet. - Throws:
IOException
- the stream cannot be read.
-
readStrings
Get an iterator to read strings from the input stream.- Returns:
- an iterator that calls
readString()
untilEND
is encountered. - Throws:
IOException
- on failure to read the initial packet line.- Since:
- 5.4
-
readStringRaw
Read a single UTF-8 encoded string packet from the input stream.Unlike
readString()
a trailing LF will be retained.- Returns:
- the string.
END
if the string was the magic flush packet. - Throws:
IOException
- the stream cannot be read.
-
isDelimiter
Check if a string is the delimiter marker.- Parameters:
s
- the string to check- Returns:
- true if the given string is
DELIM
, otherwise false. - Since:
- 5.4
-
delimiter
Get the delimiter marker.Intended for use only in tests.
- Returns:
- The delimiter marker.
-
end
Get the end marker.Intended for use only in tests.
- Returns:
- The end marker.
-
isEnd
Check if a string is the packet end marker.- Parameters:
s
- the string to check- Returns:
- true if the given string is
END
, otherwise false. - Since:
- 5.4
-
discardUntilEnd
- Throws:
IOException
-
readLength
- Throws:
IOException
-
invalidHeader
-
invalidHeader
-
isDelimiter(String)
to check if a string is the delimiter.