Top Description Fields Constructors Methods
org.eclipse.jgit.util

public final Class RawParseUtils

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.ISO_8859_1, .StandardCharsets.UTF_8, java.time.Instant.EPOCH, .ZoneOffset.UTC, org.eclipse.jgit.lib.ObjectChecker.author, .ObjectChecker.committer, .ObjectChecker.encoding, .ObjectChecker.object, .ObjectChecker.parent, .ObjectChecker.tag, .ObjectChecker.tagger, .ObjectChecker.tree, .ObjectChecker.type

Handy utility functions to parse raw object contents.

Field Summary

Modifier and TypeField and Description
private static final byte[]
private static final byte[]
private static final byte[]
private static final Map<String, Charset>
private static final byte[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static final int

Returns:

position just after the space in "author ", so the first character of the author's name. If no author header can be located -1 is returned.
author
(byte[]
buffer to scan.
b
,
int
position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the commit buffer and does not accidentally look at message body.
ptr
)

Locate the "author " header line data.

private static Charset
public static final int

Returns:

position of the user's message buffer.
commitMessage
(byte[]
buffer to scan.
b
,
int
position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the commit buffer.
ptr
)

Locate the position of the commit message body.

public static final int

Returns:

position just after the space in "committer ", so the first character of the committer's name. If no committer header can be located -1 is returned.
committer
(byte[]
buffer to scan.
b
,
int
position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the commit buffer and does not accidentally look at message body.
ptr
)

Locate the "committer " header line data.

public static String

Returns:

a string representation of the range [start,end), after decoding the region through the specified character set.
decode
(byte[]
buffer to pull raw bytes from.
buffer
)

Decode a buffer under UTF-8, if possible.

public static String

Returns:

a string representation of the range [start,end), after decoding the region through the specified character set.
decode
(final byte[]
buffer to pull raw bytes from.
buffer
,
final int
start position in buffer
start
,
final int
one position past the last location within the buffer to take data from.
end
)

Decode a buffer under UTF-8, if possible.

public static String

Returns:

a string representation of the range [start,end), after decoding the region through the specified character set.
decode
(Charset
character set to use when decoding the buffer.
cs
,
byte[]
buffer to pull raw bytes from.
buffer
)

Decode a buffer under the specified character set if possible.

public static String

Returns:

a string representation of the range [start,end), after decoding the region through the specified character set.
decode
(final Charset
character set to use when decoding the buffer.
cs
,
final byte[]
buffer to pull raw bytes from.
buffer
,
final int
first position within the buffer to take data from.
start
,
final int
one position past the last location within the buffer to take data from.
end
)

Decode a region of the buffer under the specified character set if possible.

private static String
public static String

Returns:

a string representation of the range [start,end), after decoding the region through the specified character set.
decodeNoFallback
(final Charset
character set to use when decoding the buffer.
cs
,
final byte[]
buffer to pull raw bytes from.
buffer
,
final int
first position within the buffer to take data from.
start
,
final int
one position past the last location within the buffer to take data from.
end
)

Decode a region of the buffer under the specified character set if possible.

public static final int

Returns:

position just after the space in "encoding ", so the first character of the encoding's name. If no encoding header can be located -1 is returned (and UTF-8 should be assumed).
encoding
(byte[]
buffer to scan.
b
,
int
position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the buffer and does not accidentally look at the message body.
ptr
)

Locate the "encoding " header line.

public static int

Returns:

position of the ':' which terminates the footer line key if this is otherwise a valid footer line key; otherwise -1.
endOfFooterLineKey
(byte[]
buffer to scan.
raw
,
int
first position within raw to consider as a footer line key.
ptr
)

Locate the end of a footer line key string.

public static final int

Returns:

position of the LF at the end of the paragraph; b.length if no paragraph end could be located.
endOfParagraph
(byte[]
buffer to scan.
b
,
int
position in buffer to start the scan at. Most callers will want to pass the first position of the commit message (as found by commitMessage(byte[], int).
start
)

Locate the end of a paragraph.

public static String

Returns:

a string representation of the range [start,end).
extractBinaryString
(final byte[]
buffer to pull raw bytes from.
buffer
,
final int
first position within the buffer to take data from.
start
,
final int
one position past the last location within the buffer to take data from.
end
)

Decode a region of the buffer under the ISO-8859-1 encoding.

public static int

Returns:

the new offset value o. This is the position of the last byte written. Additional writing should start at one position earlier.
formatBase10
(final byte[]
buffer to write into.
b
,
int
one offset past the location where writing will begin; writing proceeds towards lower index values.
o
,
int
the value to store.
value
)

Format a base 10 numeric into a temporary buffer.

public static Charset

Returns:

the Java character set representation. Never null. Default to UTF-8.
guessEncoding
(byte[]
buffer to scan.
buffer
)

Parse the "encoding " header into a character set reference.

public static final boolean

Returns:

whether the message starts with any known headers
hasAnyKnownHeaders
(byte[]
buffer to scan.
b
)

Returns whether the message starts with any known headers.

public static final int

Returns:

new position just after the line end. This is either b.length, or the index of the header's terminating newline.
headerEnd
(final byte[]
buffer to scan.
b
,
int
position within buffer to start looking for the header (normally a new-line).
ptr
)
Deprecated use {nextLfSkippingSplitLines} directly instead

Locate the first end of header after the given position.

public static final int

Returns:

new position at the start of the header's contents, -1 for not found
headerStart
(byte[]
header to search for
headerName
,
byte[]
buffer to scan.
b
,
int
position within buffer to start looking for header at.
ptr
)

Find the start of the contents of a given header.

public static final byte[]

Returns:

the header value, with blanks indicating continuation lines stripped
headerValue
(final byte[]
buffer to extract the header from
b
,
int
of the header value, see headerStart(byte[], byte[], int)
start
,
int end)

Extract a part of a buffer as a header value, removing the single blanks at the front of continuation lines.

public static int

Returns:

last index of ch in raw, trimming spaces.
lastIndexOfTrim
(byte[]
buffer to scan.
raw
,
char
character to find.
ch
,
int
starting position.
pos
)

Get last index of ch in raw, trimming spaces.

public static final IntList

Returns:

a line map indicating the starting position of each line.
lineMap
(byte[]
buffer to scan.
buf
,
int
position within the buffer corresponding to the first byte of line 1.
ptr
,
int
1 past the end of the content within buf.
end
)

Index the region between [ptr, end) to find line starts.

public static final IntList

Returns:

a line map indicating the starting position of each line.
lineMapOrBinary
(byte[]
buffer to scan.
buf
,
int
position within the buffer corresponding to the first byte of line 1.
ptr
,
int
1 past the end of the content within buf.
end
)

Like lineMap(byte[], int, int) but throw BinaryBlobException if a NUL byte is encountered.

public static final int

Returns:

ptr + src.length if b[ptr..src.length] == src; else -1.
match
(byte[]
the buffer to scan.
b
,
int
first position within b, this should match src[0].
ptr
,
byte[]
the buffer to test for equality with b.
src
)

Determine if b[ptr] matches src.

public static final int

Returns:

new position just after chrA.
next
(byte[]
buffer to scan.
b
,
int
position within buffer to start looking for chrA at.
ptr
,
char
character to find.
chrA
)

Locate the first position after a given character.

public static final int

Returns:

new position just after the first LF found.
nextLF
(byte[]
buffer to scan.
b
,
int
position within buffer to start looking for LF at.
ptr
)

Locate the first position after the next LF.

public static final int

Returns:

new position just after the first chrA or LF to be found.
nextLF
(byte[]
buffer to scan.
b
,
int
position within buffer to start looking for chrA or LF at.
ptr
,
char
character to find.
chrA
)

Locate the first position after either the given character or LF.

public static final int

Returns:

new position just after the line end of the last line-split. This is either b.length, or the index of the current split-line's terminating newline.
nextLfSkippingSplitLines
(final byte[]
buffer to scan.
b
,
int
position within buffer to start looking for the next line.
ptr
)

Locate the first end of line after the given position, while treating following lines which are starting with spaces as part of the current line.

public static final int

Returns:

the value at this location; 0 if the location is not a valid numeric.
parseBase10
(final byte[]
buffer to scan.
b
,
int
position within buffer to start parsing digits at.
ptr
,
final MutableInteger
optional location to return the new ptr value through. If null the ptr value will be discarded.
ptrResult
)

Parse a base 10 numeric from a sequence of ASCII digits into an int.

public static Charset

Returns:

the Java character set representation. Never null.
parseEncoding
(byte[]
buffer to scan.
b
)

Parse the "encoding " header into a character set reference.

public static String

Returns:

the encoding header as specified in the commit; null if the header was not present and should be assumed.
parseEncodingName
(byte[]
buffer to scan.
b
)

Parse the "encoding " header as a string.

public static final int

Returns:

the integer value.
parseHexInt16
(final byte[]
buffer to parse digits from; positions [p, p+4) will be parsed.
bs
,
final int
first position within the buffer to parse.
p
)

Parse 4 character base 16 (hex) formatted string to unsigned integer.

public static final int

Returns:

the integer value.
parseHexInt32
(final byte[]
buffer to parse digits from; positions [p, p+8) will be parsed.
bs
,
final int
first position within the buffer to parse.
p
)

Parse 8 character base 16 (hex) formatted string to unsigned integer.

public static final int

Returns:

numeric value, in the range 0-15.
parseHexInt4
(final byte
hex character to parse.
digit
)

Parse a single hex digit to its numeric value (0-15).

public static final long

Returns:

the integer value.
parseHexInt64
(final byte[]
buffer to parse digits from; positions [p, p+16) will be parsed.
bs
,
final int
first position within the buffer to parse.
p
)

Parse 16 character base 16 (hex) formatted string to unsigned long.

public static final long

Returns:

the value at this location; 0 if the location is not a valid numeric.
parseLongBase10
(final byte[]
buffer to scan.
b
,
int
position within buffer to start parsing digits at.
ptr
,
final MutableInteger
optional location to return the new ptr value through. If null the ptr value will be discarded.
ptrResult
)

Parse a base 10 numeric from a sequence of ASCII digits into a long.

public static PersonIdent

Returns:

the parsed identity or null in case the identity could not be parsed.
parsePersonIdent
(String
the string to parse a name from.
in
)

Parse a name string (e.g. author, committer, tagger) into a PersonIdent.

public static PersonIdent

Returns:

the parsed identity or null in case the identity could not be parsed.
parsePersonIdent
(byte[]
the buffer to parse character data from.
raw
,
int
first position of the identity information. This should be the first position after the space which delimits the header field name (e.g. "author" or "committer") from the rest of the identity line.
nameB
)

Parse a name line (e.g. author, committer, tagger) into a PersonIdent.

public static PersonIdent

Returns:

the parsed identity. Never null.
parsePersonIdentOnly
(final byte[]
the buffer to parse character data from.
raw
,
final int
first position of the identity information. This should be the first position after the space which delimits the header field name (e.g. "author" or "committer") from the rest of the identity line.
nameB
)

Parse a name data (e.g. as within a reflog) into a PersonIdent.

public static final int

Returns:

the timezone at this location, expressed in minutes.
parseTimeZoneOffset
(byte[]
buffer to scan.
b
,
int
position within buffer to start parsing digits at.
ptr
)

Parse a Git style timezone string.

public static final int

Returns:

the timezone at this location, expressed in minutes.
parseTimeZoneOffset
(final byte[]
buffer to scan.
b
,
int
position within buffer to start parsing digits at.
ptr
,
MutableInteger
optional location to return the new ptr value through. If null the ptr value will be discarded.
ptrResult
)

Parse a Git style timezone string.

private static ZoneId

Returns:

the ZoneOffset represention of the timezone offset string. Invalid offsets default to UTC.
parseZoneOffset
(final byte[]
buffer to scan.
b
,
int
position within buffer to start parsing digits at.
ptr
,
MutableInteger
optional location to return the new ptr value through. If null the ptr value will be discarded.
ptrResult
)

Parse a Git style timezone string in [+-]hhmm format

public static final int

Returns:

new position just before chrA, -1 for not found
prev
(byte[]
buffer to scan.
b
,
int
position within buffer to start looking for chrA at.
ptr
,
char
character to find.
chrA
)

Locate the first position before a given character.

public static final int

Returns:

new position just before the first LF found, -1 for not found
prevLF
(byte[]
buffer to scan.
b
,
int
position within buffer to start looking for LF at.
ptr
)

Locate the first position before the previous LF.

public static final int

Returns:

new position just before the first chrA or LF to be found, -1 for not found
prevLF
(byte[]
buffer to scan.
b
,
int
position within buffer to start looking for chrA or LF at.
ptr
,
char
character to find.
chrA
)

Locate the previous position before either the given character or LF.

public static final int

Returns:

position just after the space in "tagger ", so the first character of the tagger's name. If no tagger header can be located -1 is returned.
tagger
(byte[]
buffer to scan.
b
,
int
position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the tag buffer and does not accidentally look at message body.
ptr
)

Locate the "tagger " header line data.

public static final int

Returns:

position of the user's message buffer.
tagMessage
(byte[]
buffer to scan.
b
,
int
position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the tag buffer.
ptr
)

Locate the position of the tag message body.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

base10byteback to summary
private static final byte[] base10byte
digits10back to summary
private static final byte[] digits10
digits16back to summary
private static final byte[] digits16
encodingAliasesback to summary
private static final Map<String, Charset> encodingAliases
footerLineKeyCharsback to summary
private static final byte[] footerLineKeyChars

Constructor Detail

RawParseUtilsback to summary
private RawParseUtils()

Method Detail

authorback to summary
public static final int author(byte[] b, int ptr)

Locate the "author " header line data.

Parameters
b:byte[]

buffer to scan.

ptr:int

position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the commit buffer and does not accidentally look at message body.

Returns:int

position just after the space in "author ", so the first character of the author's name. If no author header can be located -1 is returned.

charsetForAliasback to summary
private static Charset charsetForAlias(String name)
commitMessageback to summary
public static final int commitMessage(byte[] b, int ptr)

Locate the position of the commit message body.

Parameters
b:byte[]

buffer to scan.

ptr:int

position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the commit buffer.

Returns:int

position of the user's message buffer.

committerback to summary
public static final int committer(byte[] b, int ptr)

Locate the "committer " header line data.

Parameters
b:byte[]

buffer to scan.

ptr:int

position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the commit buffer and does not accidentally look at message body.

Returns:int

position just after the space in "committer ", so the first character of the committer's name. If no committer header can be located -1 is returned.

decodeback to summary
public static String decode(byte[] buffer)

Decode a buffer under UTF-8, if possible. If the byte stream cannot be decoded that way, the platform default is tried and if that too fails, the fail-safe ISO-8859-1 encoding is tried.

Parameters
buffer:byte[]

buffer to pull raw bytes from.

Returns:String

a string representation of the range [start,end), after decoding the region through the specified character set.

decodeback to summary
public static String decode(final byte[] buffer, final int start, final int end)

Decode a buffer under UTF-8, if possible. If the byte stream cannot be decoded that way, the platform default is tried and if that too fails, the fail-safe ISO-8859-1 encoding is tried.

Parameters
buffer:byte[]

buffer to pull raw bytes from.

start:int

start position in buffer

end:int

one position past the last location within the buffer to take data from.

Returns:String

a string representation of the range [start,end), after decoding the region through the specified character set.

decodeback to summary
public static String decode(Charset cs, byte[] buffer)

Decode a buffer under the specified character set if possible. If the byte stream cannot be decoded that way, the platform default is tried and if that too fails, the fail-safe ISO-8859-1 encoding is tried.

Parameters
cs:Charset

character set to use when decoding the buffer.

buffer:byte[]

buffer to pull raw bytes from.

Returns:String

a string representation of the range [start,end), after decoding the region through the specified character set.

decodeback to summary
public static String decode(final Charset cs, final byte[] buffer, final int start, final int end)

Decode a region of the buffer under the specified character set if possible. If the byte stream cannot be decoded that way, the platform default is tried and if that too fails, the fail-safe ISO-8859-1 encoding is tried.

Parameters
cs:Charset

character set to use when decoding the buffer.

buffer:byte[]

buffer to pull raw bytes from.

start:int

first position within the buffer to take data from.

end:int

one position past the last location within the buffer to take data from.

Returns:String

a string representation of the range [start,end), after decoding the region through the specified character set.

decodeback to summary
private static String decode(ByteBuffer b, Charset charset) throws CharacterCodingException
decodeNoFallbackback to summary
public static String decodeNoFallback(final Charset cs, final byte[] buffer, final int start, final int end) throws CharacterCodingException

Decode a region of the buffer under the specified character set if possible. If the byte stream cannot be decoded that way, the platform default is tried and if that too fails, an exception is thrown.

Parameters
cs:Charset

character set to use when decoding the buffer.

buffer:byte[]

buffer to pull raw bytes from.

start:int

first position within the buffer to take data from.

end:int

one position past the last location within the buffer to take data from.

Returns:String

a string representation of the range [start,end), after decoding the region through the specified character set.

Exceptions
CharacterCodingException:
the input is not in any of the tested character sets.
encodingback to summary
public static final int encoding(byte[] b, int ptr)

Locate the "encoding " header line.

Parameters
b:byte[]

buffer to scan.

ptr:int

position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the buffer and does not accidentally look at the message body.

Returns:int

position just after the space in "encoding ", so the first character of the encoding's name. If no encoding header can be located -1 is returned (and UTF-8 should be assumed).

endOfFooterLineKeyback to summary
public static int endOfFooterLineKey(byte[] raw, int ptr)

Locate the end of a footer line key string.

If the region at raw[ptr] matches ^[A-Za-z0-9-]+: (e.g. "Signed-off-by: A. U. Thor\n") then this method returns the position of the first ':'.

If the region at raw[ptr] does not match ^[A-Za-z0-9-]+: then this method returns -1.

Parameters
raw:byte[]

buffer to scan.

ptr:int

first position within raw to consider as a footer line key.

Returns:int

position of the ':' which terminates the footer line key if this is otherwise a valid footer line key; otherwise -1.

endOfParagraphback to summary
public static final int endOfParagraph(byte[] b, int start)

Locate the end of a paragraph.

A paragraph is ended by two consecutive LF bytes or CRLF pairs

Parameters
b:byte[]

buffer to scan.

start:int

position in buffer to start the scan at. Most callers will want to pass the first position of the commit message (as found by commitMessage(byte[], int).

Returns:int

position of the LF at the end of the paragraph; b.length if no paragraph end could be located.

extractBinaryStringback to summary
public static String extractBinaryString(final byte[] buffer, final int start, final int end)

Decode a region of the buffer under the ISO-8859-1 encoding. Each byte is treated as a single character in the 8859-1 character encoding, performing a raw binary->char conversion.

Parameters
buffer:byte[]

buffer to pull raw bytes from.

start:int

first position within the buffer to take data from.

end:int

one position past the last location within the buffer to take data from.

Returns:String

a string representation of the range [start,end).

formatBase10back to summary
public static int formatBase10(final byte[] b, int o, int value)

Format a base 10 numeric into a temporary buffer.

Formatting is performed backwards. The method starts at offset o-1 and ends at o-1-digits, where digits is the number of positions necessary to store the base 10 value.

The argument and return values from this method make it easy to chain writing, for example:

final byte[] tmp = new byte[64];
int ptr = tmp.length;
tmp[--ptr] = '\n';
ptr = RawParseUtils.formatBase10(tmp, ptr, 32);
tmp[--ptr] = ' ';
ptr = RawParseUtils.formatBase10(tmp, ptr, 18);
tmp[--ptr] = 0;
final String str = new String(tmp, ptr, tmp.length - ptr);
Parameters
b:byte[]

buffer to write into.

o:int

one offset past the location where writing will begin; writing proceeds towards lower index values.

value:int

the value to store.

Returns:int

the new offset value o. This is the position of the last byte written. Additional writing should start at one position earlier.

guessEncodingback to summary
public static Charset guessEncoding(byte[] buffer)

Parse the "encoding " header into a character set reference.

If unsuccessful, return UTF-8.

Parameters
buffer:byte[]

buffer to scan.

Returns:Charset

the Java character set representation. Never null. Default to UTF-8.

Since
6.7
See Also
parseEncoding(byte[])
hasAnyKnownHeadersback to summary
public static final boolean hasAnyKnownHeaders(byte[] b)

Returns whether the message starts with any known headers.

Parameters
b:byte[]

buffer to scan.

Returns:boolean

whether the message starts with any known headers

Since
6.9
headerEndback to summary
public static final int headerEnd(final byte[] b, int ptr)

Deprecated

use {nextLfSkippingSplitLines} directly instead

Locate the first end of header after the given position. Note that headers may be more than one line long.

Also note that there might be multiple headers. If you wish to find the last header's end - call this in a loop.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for the header (normally a new-line).

Returns:int

new position just after the line end. This is either b.length, or the index of the header's terminating newline.

Annotations
@Deprecated
Since
5.1
headerStartback to summary
public static final int headerStart(byte[] headerName, byte[] b, int ptr)

Find the start of the contents of a given header.

Parameters
headerName:byte[]

header to search for

b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for header at.

Returns:int

new position at the start of the header's contents, -1 for not found

Since
5.1
headerValueback to summary
public static final byte[] headerValue(final byte[] b, int start, int end)

Extract a part of a buffer as a header value, removing the single blanks at the front of continuation lines.

Parameters
b:byte[]

buffer to extract the header from

start:int

of the header value, see headerStart(byte[], byte[], int)

end:int

of the header; see nextLfSkippingSplitLines(byte[], int)

Returns:byte[]

the header value, with blanks indicating continuation lines stripped

Since
6.9
lastIndexOfTrimback to summary
public static int lastIndexOfTrim(byte[] raw, char ch, int pos)

Get last index of ch in raw, trimming spaces.

Parameters
raw:byte[]

buffer to scan.

ch:char

character to find.

pos:int

starting position.

Returns:int

last index of ch in raw, trimming spaces.

Since
4.1
lineMapback to summary
public static final IntList lineMap(byte[] buf, int ptr, int end)

Index the region between [ptr, end) to find line starts.

The returned list is 1 indexed. Index 0 contains java.lang.Integer#MIN_VALUE to pad the list out.

Using a 1 indexed list means that line numbers can be directly accessed from the list, so list.get(1) (aka get line 1) returns ptr.

The last element (index map.size()-1) always contains end.

Parameters
buf:byte[]

buffer to scan.

ptr:int

position within the buffer corresponding to the first byte of line 1.

end:int

1 past the end of the content within buf.

Returns:IntList

a line map indicating the starting position of each line.

lineMapOrBinaryback to summary
public static final IntList lineMapOrBinary(byte[] buf, int ptr, int end) throws BinaryBlobException

Like lineMap(byte[], int, int) but throw BinaryBlobException if a NUL byte is encountered.

Parameters
buf:byte[]

buffer to scan.

ptr:int

position within the buffer corresponding to the first byte of line 1.

end:int

1 past the end of the content within buf.

Returns:IntList

a line map indicating the starting position of each line.

Exceptions
BinaryBlobException:
if a NUL byte or a lone CR is found.
Since
5.0
matchback to summary
public static final int match(byte[] b, int ptr, byte[] src)

Determine if b[ptr] matches src.

Parameters
b:byte[]

the buffer to scan.

ptr:int

first position within b, this should match src[0].

src:byte[]

the buffer to test for equality with b.

Returns:int

ptr + src.length if b[ptr..src.length] == src; else -1.

nextback to summary
public static final int next(byte[] b, int ptr, char chrA)

Locate the first position after a given character.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for chrA at.

chrA:char

character to find.

Returns:int

new position just after chrA.

nextLFback to summary
public static final int nextLF(byte[] b, int ptr)

Locate the first position after the next LF.

This method stops on the first '\n' it finds.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for LF at.

Returns:int

new position just after the first LF found.

nextLFback to summary
public static final int nextLF(byte[] b, int ptr, char chrA)

Locate the first position after either the given character or LF.

This method stops on the first match it finds from either chrA or '\n'.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for chrA or LF at.

chrA:char

character to find.

Returns:int

new position just after the first chrA or LF to be found.

nextLfSkippingSplitLinesback to summary
public static final int nextLfSkippingSplitLines(final byte[] b, int ptr)

Locate the first end of line after the given position, while treating following lines which are starting with spaces as part of the current line.

For example, nextLfSkippingSplitLines( "row \n with space at beginning of a following line\nThe actual next line", 0) will return the position of "\nThe actual next line".

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for the next line.

Returns:int

new position just after the line end of the last line-split. This is either b.length, or the index of the current split-line's terminating newline.

Since
6.9
parseBase10back to summary
public static final int parseBase10(final byte[] b, int ptr, final MutableInteger ptrResult)

Parse a base 10 numeric from a sequence of ASCII digits into an int.

Digit sequences can begin with an optional run of spaces before the sequence, and may start with a '+' or a '-' to indicate sign position. Any other characters will cause the method to stop and return the current result to the caller.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start parsing digits at.

ptrResult:MutableInteger

optional location to return the new ptr value through. If null the ptr value will be discarded.

Returns:int

the value at this location; 0 if the location is not a valid numeric.

parseEncodingback to summary
public static Charset parseEncoding(byte[] b)

Parse the "encoding " header into a character set reference.

Locates the "encoding " header (if present) by first calling encoding(byte[], int) and then returns the proper character set to apply to this buffer to evaluate its contents as character data.

If no encoding header is present UTF-8 is assumed.

Parameters
b:byte[]

buffer to scan.

Returns:Charset

the Java character set representation. Never null.

Exceptions
IllegalCharsetNameException:
if the character set requested by the encoding header is malformed and unsupportable.
UnsupportedCharsetException:
if the JRE does not support the character set requested by the encoding header.
parseEncodingNameback to summary
public static String parseEncodingName(byte[] b)

Parse the "encoding " header as a string.

Locates the "encoding " header (if present) and returns its value.

Parameters
b:byte[]

buffer to scan.

Returns:String

the encoding header as specified in the commit; null if the header was not present and should be assumed.

Annotations
@Nullable
Since
4.2
parseHexInt16back to summary
public static final int parseHexInt16(final byte[] bs, final int p)

Parse 4 character base 16 (hex) formatted string to unsigned integer.

The number is read in network byte order, that is, most significant nybble first.

Parameters
bs:byte[]

buffer to parse digits from; positions [p, p+4) will be parsed.

p:int

first position within the buffer to parse.

Returns:int

the integer value.

Exceptions
ArrayIndexOutOfBoundsException:
if the string is not hex formatted.
parseHexInt32back to summary
public static final int parseHexInt32(final byte[] bs, final int p)

Parse 8 character base 16 (hex) formatted string to unsigned integer.

The number is read in network byte order, that is, most significant nybble first.

Parameters
bs:byte[]

buffer to parse digits from; positions [p, p+8) will be parsed.

p:int

first position within the buffer to parse.

Returns:int

the integer value.

Exceptions
ArrayIndexOutOfBoundsException:
if the string is not hex formatted.
parseHexInt4back to summary
public static final int parseHexInt4(final byte digit)

Parse a single hex digit to its numeric value (0-15).

Parameters
digit:byte

hex character to parse.

Returns:int

numeric value, in the range 0-15.

Exceptions
ArrayIndexOutOfBoundsException:
if the input digit is not a valid hex digit.
parseHexInt64back to summary
public static final long parseHexInt64(final byte[] bs, final int p)

Parse 16 character base 16 (hex) formatted string to unsigned long.

The number is read in network byte order, that is, most significant nibble first.

Parameters
bs:byte[]

buffer to parse digits from; positions [p, p+16) will be parsed.

p:int

first position within the buffer to parse.

Returns:long

the integer value.

Annotations
@SuppressWarnings:IntLongMath
Exceptions
ArrayIndexOutOfBoundsException:
if the string is not hex formatted.
Since
4.3
parseLongBase10back to summary
public static final long parseLongBase10(final byte[] b, int ptr, final MutableInteger ptrResult)

Parse a base 10 numeric from a sequence of ASCII digits into a long.

Digit sequences can begin with an optional run of spaces before the sequence, and may start with a '+' or a '-' to indicate sign position. Any other characters will cause the method to stop and return the current result to the caller.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start parsing digits at.

ptrResult:MutableInteger

optional location to return the new ptr value through. If null the ptr value will be discarded.

Returns:long

the value at this location; 0 if the location is not a valid numeric.

parsePersonIdentback to summary
public static PersonIdent parsePersonIdent(String in)

Parse a name string (e.g. author, committer, tagger) into a PersonIdent.

Leading spaces won't be trimmed from the string, i.e. will show up in the parsed name afterwards.

Parameters
in:String

the string to parse a name from.

Returns:PersonIdent

the parsed identity or null in case the identity could not be parsed.

parsePersonIdentback to summary
public static PersonIdent parsePersonIdent(byte[] raw, int nameB)

Parse a name line (e.g. author, committer, tagger) into a PersonIdent.

When passing in a value for nameB callers should use the return value of author(byte[], int) or committer(byte[], int), as these methods provide the proper position within the buffer.

Parameters
raw:byte[]

the buffer to parse character data from.

nameB:int

first position of the identity information. This should be the first position after the space which delimits the header field name (e.g. "author" or "committer") from the rest of the identity line.

Returns:PersonIdent

the parsed identity or null in case the identity could not be parsed.

parsePersonIdentOnlyback to summary
public static PersonIdent parsePersonIdentOnly(final byte[] raw, final int nameB)

Parse a name data (e.g. as within a reflog) into a PersonIdent.

When passing in a value for nameB callers should use the return value of author(byte[], int) or committer(byte[], int), as these methods provide the proper position within the buffer.

Parameters
raw:byte[]

the buffer to parse character data from.

nameB:int

first position of the identity information. This should be the first position after the space which delimits the header field name (e.g. "author" or "committer") from the rest of the identity line.

Returns:PersonIdent

the parsed identity. Never null.

parseTimeZoneOffsetback to summary
public static final int parseTimeZoneOffset(byte[] b, int ptr)

Parse a Git style timezone string.

The sequence "-0315" will be parsed as the numeric value -195, as the lower two positions count minutes, not 100ths of an hour.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start parsing digits at.

Returns:int

the timezone at this location, expressed in minutes.

parseTimeZoneOffsetback to summary
public static final int parseTimeZoneOffset(final byte[] b, int ptr, MutableInteger ptrResult)

Parse a Git style timezone string.

The sequence "-0315" will be parsed as the numeric value -195, as the lower two positions count minutes, not 100ths of an hour.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start parsing digits at.

ptrResult:MutableInteger

optional location to return the new ptr value through. If null the ptr value will be discarded.

Returns:int

the timezone at this location, expressed in minutes.

Since
4.1
parseZoneOffsetback to summary
private static ZoneId parseZoneOffset(final byte[] b, int ptr, MutableInteger ptrResult)

Parse a Git style timezone string in [+-]hhmm format

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start parsing digits at.

ptrResult:MutableInteger

optional location to return the new ptr value through. If null the ptr value will be discarded.

Returns:ZoneId

the ZoneOffset represention of the timezone offset string. Invalid offsets default to UTC.

prevback to summary
public static final int prev(byte[] b, int ptr, char chrA)

Locate the first position before a given character.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for chrA at.

chrA:char

character to find.

Returns:int

new position just before chrA, -1 for not found

prevLFback to summary
public static final int prevLF(byte[] b, int ptr)

Locate the first position before the previous LF.

This method stops on the first '\n' it finds.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for LF at.

Returns:int

new position just before the first LF found, -1 for not found

prevLFback to summary
public static final int prevLF(byte[] b, int ptr, char chrA)

Locate the previous position before either the given character or LF.

This method stops on the first match it finds from either chrA or '\n'.

Parameters
b:byte[]

buffer to scan.

ptr:int

position within buffer to start looking for chrA or LF at.

chrA:char

character to find.

Returns:int

new position just before the first chrA or LF to be found, -1 for not found

taggerback to summary
public static final int tagger(byte[] b, int ptr)

Locate the "tagger " header line data.

Parameters
b:byte[]

buffer to scan.

ptr:int

position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the tag buffer and does not accidentally look at message body.

Returns:int

position just after the space in "tagger ", so the first character of the tagger's name. If no tagger header can be located -1 is returned.

tagMessageback to summary
public static final int tagMessage(byte[] b, int ptr)

Locate the position of the tag message body.

Parameters
b:byte[]

buffer to scan.

ptr:int

position in buffer to start the scan at. Most callers should pass 0 to ensure the scan starts from the beginning of the tag buffer.

Returns:int

position of the user's message buffer.