Package org.eclipse.jgit.transport
Class PacketLineIn
- java.lang.Object
-
- org.eclipse.jgit.transport.PacketLineIn
-
public class PacketLineIn extends java.lang.ObjectRead 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 Classes Modifier and Type Class Description (package private) static classPacketLineIn.AckNackResultstatic classPacketLineIn.InputOverLimitIOExceptionIOException thrown by read when the configured input limit is exceeded.static classPacketLineIn.PacketLineInIteratorIterator over packet lines.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDELIMDeprecated.Callers should useisDelimiter(String)to check if a string is the delimiter.static java.lang.StringENDDeprecated.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 java.io.InputStreaminprivate longlimitprivate byte[]lineBufferprivate static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.Stringdelimiter()Get the delimiter marker.(package private) voiddiscardUntilEnd()(package private) static java.lang.Stringend()Get the end marker.private java.io.IOExceptioninvalidHeader()private java.io.IOExceptioninvalidHeader(java.lang.Throwable cause)static booleanisDelimiter(java.lang.String s)Check if a string is the delimiter marker.static booleanisEnd(java.lang.String s)Check if a string is the packet end marker.(package private) static PacketLineIn.AckNackResultparseACKv2(java.lang.String line, MutableObjectId returnedId)Parses a ACK/NAK line in protocol V2.(package private) PacketLineIn.AckNackResultreadACK(MutableObjectId returnedId)(package private) intreadLength()java.lang.StringreadString()Read a single UTF-8 encoded string packet from the input stream.java.lang.StringreadStringRaw()Read a single UTF-8 encoded string packet from the input stream.PacketLineIn.PacketLineInIteratorreadStrings()Get an iterator to read strings from the input stream.
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
END
@Deprecated public static final java.lang.String 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 public static final java.lang.String 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
private final java.io.InputStream in
-
limit
private long limit
-
-
Constructor Detail
-
PacketLineIn
public PacketLineIn(java.io.InputStream in)
Create a new packet line reader.- Parameters:
in- the input stream to consume.
-
PacketLineIn
public PacketLineIn(java.io.InputStream in, long limit)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 Detail
-
parseACKv2
static PacketLineIn.AckNackResult parseACKv2(java.lang.String line, MutableObjectId returnedId) throws java.io.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:
java.io.IOException- on protocol or transport errors
-
readACK
PacketLineIn.AckNackResult readACK(MutableObjectId returnedId) throws java.io.IOException
- Throws:
java.io.IOException
-
readString
public java.lang.String readString() throws java.io.IOExceptionRead 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.
-
readStrings
public PacketLineIn.PacketLineInIterator readStrings() throws java.io.IOException
Get an iterator to read strings from the input stream.- Returns:
- an iterator that calls
readString()untilENDis encountered. - Throws:
java.io.IOException- on failure to read the initial packet line.- Since:
- 5.4
-
readStringRaw
public java.lang.String readStringRaw() throws java.io.IOExceptionRead a single UTF-8 encoded string packet from the input stream.Unlike
readString()a trailing LF will be retained.- Returns:
- the string.
ENDif the string was the magic flush packet. - Throws:
java.io.IOException- the stream cannot be read.
-
isDelimiter
public static boolean isDelimiter(java.lang.String s)
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
static java.lang.String delimiter()
Get the delimiter marker.Intended for use only in tests.
- Returns:
- The delimiter marker.
-
end
static java.lang.String end()
Get the end marker.Intended for use only in tests.
- Returns:
- The end marker.
-
isEnd
public static boolean isEnd(java.lang.String s)
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
void discardUntilEnd() throws java.io.IOException- Throws:
java.io.IOException
-
readLength
int readLength() throws java.io.IOException- Throws:
java.io.IOException
-
invalidHeader
private java.io.IOException invalidHeader()
-
invalidHeader
private java.io.IOException invalidHeader(java.lang.Throwable cause)
-
-