From: Shawn O. Pearce Date: Mon, 28 Mar 2011 17:26:30 +0000 (-0700) Subject: Make PacketLineIn public X-Git-Tag: v0.12.1~32 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F55%2F2955%2F2;p=jgit.git Make PacketLineIn public PacketLineOut is already public. Make PacketLineIn partially public in case an application needs to use some of the pkt-line protocol. Change-Id: I5b383eca980bd9e16a7dbdb5aed040c6586d4f46 Signed-off-by: Shawn O. Pearce --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index e5b2494c88..5b06c43895 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -56,9 +56,19 @@ import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.RawParseUtils; -class PacketLineIn { - /* must not string pool */ - static final String END = new StringBuilder(0).toString(); +/** + * 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. + */ +public class PacketLineIn { + /** Magic return from {@link #readString()} when a flush packet is found. */ + public static final String END = new StringBuilder(0).toString(); /* must not string pool */ static enum AckNackResult { /** NAK */ @@ -77,7 +87,13 @@ class PacketLineIn { private final byte[] lineBuffer; - PacketLineIn(final InputStream i) { + /** + * Create a new packet line reader. + * + * @param i + * the input stream to consume. + */ + public PacketLineIn(final InputStream i) { in = i; lineBuffer = new byte[SideBandOutputStream.SMALL_BUF]; } @@ -106,7 +122,19 @@ class PacketLineIn { throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedACKNAKGot, line)); } - 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 {@link #readStringRaw()} instead. + * + * @return the string. {@link #END} if the string was the magic flush + * packet. + * @throws IOException + * the stream cannot be read. + */ + public String readString() throws IOException { int len = readLength(); if (len == 0) return END; @@ -127,7 +155,17 @@ class PacketLineIn { return RawParseUtils.decode(Constants.CHARSET, raw, 0, len); } - String readStringRaw() throws IOException { + /** + * Read a single UTF-8 encoded string packet from the input stream. + *

+ * Unlike {@link #readString()} a trailing LF will be retained. + * + * @return the string. {@link #END} if the string was the magic flush + * packet. + * @throws IOException + * the stream cannot be read. + */ + public String readStringRaw() throws IOException { int len = readLength(); if (len == 0) return END;