瀏覽代碼

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 年之前
父節點
當前提交
00eae14a7f
共有 1 個文件被更改,包括 44 次插入6 次删除
  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 查看文件

import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils; 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 { static enum AckNackResult {
/** NAK */ /** NAK */


private final byte[] lineBuffer; 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; in = i;
lineBuffer = new byte[SideBandOutputStream.SMALL_BUF]; lineBuffer = new byte[SideBandOutputStream.SMALL_BUF];
} }
throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedACKNAKGot, line)); 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(); int len = readLength();
if (len == 0) if (len == 0)
return END; return END;
return RawParseUtils.decode(Constants.CHARSET, raw, 0, len); 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(); int len = readLength();
if (len == 0) if (len == 0)
return END; return END;

Loading…
取消
儲存