Class PacketLineIn

java.lang.Object
org.eclipse.jgit.transport.PacketLineIn

public class PacketLineIn extends Object
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.

  • Field Details

  • Constructor Details

    • PacketLineIn

      public PacketLineIn(InputStream in)
      Create a new packet line reader.
      Parameters:
      in - the input stream to consume.
    • PacketLineIn

      public PacketLineIn(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 Details

    • readString

      public String readString() throws IOException
      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

      public PacketLineIn.PacketLineInIterator readStrings() throws IOException
      Get an iterator to read strings from the input stream.
      Returns:
      an iterator that calls readString() until END is encountered.
      Throws:
      IOException - on failure to read the initial packet line.
      Since:
      5.4
    • readStringRaw

      public String readStringRaw() throws IOException
      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

      public static boolean isDelimiter(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
    • isEnd

      public static boolean isEnd(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