Browse Source

PushCertificateParser: Move reader parsing to instance method

Change-Id: I8ab5fb97303e25b28187375b6f9ff28f918bdd43
stable-4.1
Dave Borowitz 9 years ago
parent
commit
19b45dab71
  1. 52
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java

52
org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java

@ -153,23 +153,7 @@ public class PushCertificateParser {
*/ */
public static PushCertificate fromReader(Reader r) public static PushCertificate fromReader(Reader r)
throws PackProtocolException, IOException { throws PackProtocolException, IOException {
PushCertificateParser parser = new PushCertificateParser(); return new PushCertificateParser().parse(r);
StreamReader reader = new StreamReader(r);
parser.receiveHeader(reader, true);
String line;
try {
while (!(line = reader.read()).isEmpty()) {
if (line.equals(BEGIN_SIGNATURE)) {
parser.receiveSignature(reader);
break;
}
parser.addCommand(line);
}
} catch (EOFException e) {
// EOF reached, but might have been at a valid state. Let build call below
// sort it out.
}
return parser.build();
} }
private boolean received; private boolean received;
@ -229,6 +213,40 @@ public class PushCertificateParser {
enabled = true; enabled = true;
} }
/**
* Parse a push certificate from a reader.
*
* @see #fromReader(Reader)
* @param r
* input reader; consumed only up until the end of the next
* signature in the input.
* @return the parsed certificate, or null if the reader was at EOF.
* @throws PackProtocolException
* if the certificate is malformed.
* @throws IOException
* if there was an error reading from the input.
* @since 4.1
*/
public PushCertificate parse(Reader r)
throws PackProtocolException, IOException {
StreamReader reader = new StreamReader(r);
receiveHeader(reader, true);
String line;
try {
while (!(line = reader.read()).isEmpty()) {
if (line.equals(BEGIN_SIGNATURE)) {
receiveSignature(reader);
break;
}
addCommand(line);
}
} catch (EOFException e) {
// EOF reached, but might have been at a valid state. Let build call below
// sort it out.
}
return build();
}
/** /**
* @return the parsed certificate, or null if push certificates are disabled. * @return the parsed certificate, or null if push certificates are disabled.
* @throws IOException * @throws IOException

Loading…
Cancel
Save