summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-03-28 10:26:30 -0700
committerShawn O. Pearce <spearce@spearce.org>2011-04-01 17:35:43 -0400
commit00eae14a7f736640da0086a9a9eb73ed50963eb8 (patch)
tree504ffde136874d2597728b374d7c1c3c68a727ff
parenta4c142286e99529cd3707473db0ccea362d84545 (diff)
downloadjgit-00eae14a7f736640da0086a9a9eb73ed50963eb8.tar.gz
jgit-00eae14a7f736640da0086a9a9eb73ed50963eb8.zip
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 <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java50
1 files changed, 44 insertions, 6 deletions
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.
+ * <p>
+ * This class is not thread safe and may issue multiple reads to the underlying
+ * stream for each method call made.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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;