public class Patch
extends java.lang.Object
FileHeaders from a
unified diff patch file| Modifier and Type | Field and Description |
|---|---|
private static byte[][] |
BIN_HEADERS |
private static byte[] |
BIN_TRAILER |
private static byte[] |
DIFF_CC |
private static byte[] |
DIFF_COMBINED |
(package private) static byte[] |
DIFF_GIT |
private java.util.List<FormatError> |
errors
Formatting errors, if any were identified.
|
private java.util.List<FileHeader> |
files
The files, in the order they were parsed out of the input.
|
private static byte[] |
GIT_BINARY |
(package private) static byte[] |
SIG_FOOTER |
| Constructor and Description |
|---|
Patch()
Create an empty patch.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addError(FormatError err)
Add a formatting error to this patch script.
|
void |
addFile(FileHeader fh)
Add a single file to this patch.
|
(package private) void |
error(byte[] buf,
int ptr,
java.lang.String msg) |
java.util.List<FormatError> |
getErrors()
Get collection of formatting errors.
|
java.util.List<? extends FileHeader> |
getFiles()
Get list of files described in the patch, in occurrence order.
|
private static boolean |
matchAny(byte[] buf,
int c,
byte[][] srcs) |
void |
parse(byte[] buf,
int ptr,
int end)
Parse a patch stored in a byte[].
|
void |
parse(java.io.InputStream is)
Parse a patch received from an InputStream.
|
private int |
parseDiffCombined(byte[] hdr,
byte[] buf,
int start,
int end) |
private int |
parseDiffGit(byte[] buf,
int start,
int end) |
private int |
parseFile(byte[] buf,
int c,
int end) |
private int |
parseGitBinary(FileHeader fh,
int c,
int end) |
private int |
parseHunks(FileHeader fh,
int c,
int end) |
private int |
parseTraditionalPatch(byte[] buf,
int start,
int end) |
private static byte[] |
readFully(java.io.InputStream is) |
private static int |
skipFile(byte[] buf,
int ptr) |
(package private) void |
warn(byte[] buf,
int ptr,
java.lang.String msg) |
static final byte[] DIFF_GIT
private static final byte[] DIFF_CC
private static final byte[] DIFF_COMBINED
private static final byte[][] BIN_HEADERS
private static final byte[] BIN_TRAILER
private static final byte[] GIT_BINARY
static final byte[] SIG_FOOTER
private final java.util.List<FileHeader> files
private final java.util.List<FormatError> errors
public void addFile(FileHeader fh)
Typically files should be added by parsing the text through one of this class's parse methods.
fh - the header of the file.public java.util.List<? extends FileHeader> getFiles()
public void addError(FormatError err)
err - the error description.public java.util.List<FormatError> getErrors()
public void parse(java.io.InputStream is)
throws java.io.IOException
Multiple parse calls on the same instance will concatenate the patch data, but each parse input must start with a valid file header (don't split a single file across parse calls).
is - the stream to read the patch data from. The stream is read
until EOF is reached.java.io.IOException - there was an error reading from the input stream.private static byte[] readFully(java.io.InputStream is)
throws java.io.IOException
java.io.IOExceptionpublic void parse(byte[] buf,
int ptr,
int end)
Multiple parse calls on the same instance will concatenate the patch data, but each parse input must start with a valid file header (don't split a single file across parse calls).
buf - the buffer to parse.ptr - starting position to parse from.end - 1 past the last position to end parsing. The total length to
be parsed is end - ptr.private int parseFile(byte[] buf,
int c,
int end)
private int parseDiffGit(byte[] buf,
int start,
int end)
private int parseDiffCombined(byte[] hdr,
byte[] buf,
int start,
int end)
private int parseTraditionalPatch(byte[] buf,
int start,
int end)
private static int skipFile(byte[] buf,
int ptr)
private int parseHunks(FileHeader fh, int c, int end)
private int parseGitBinary(FileHeader fh, int c, int end)
void warn(byte[] buf,
int ptr,
java.lang.String msg)
void error(byte[] buf,
int ptr,
java.lang.String msg)
private static boolean matchAny(byte[] buf,
int c,
byte[][] srcs)