Browse Source

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>
tags/v0.12.1
Shawn O. Pearce 13 years ago
parent
commit
00eae14a7f
1 changed files with 44 additions and 6 deletions
  1. 44
    6
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java

+ 44
- 6
org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java View File

@@ -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;

Loading…
Cancel
Save