parseOctalOrBinary

Compute the value contained in a byte buffer. If the most
significant bit of the first byte in the buffer is set, this
bit is ignored and the rest of the buffer is interpreted as a
binary number. Otherwise, the buffer is interpreted as an
octal number as per the parseOctal function above.

Parameters:

buffer - The buffer from which to parse.

offset - The offset into the buffer from which to parse.

length - The maximum number of bytes to parse.

Returns:

The long value of the octal or binary string.

Throws:

IllegalArgumentException - if the trailing space/NUL is
missing or an invalid byte is detected in an octal number, or
if a binary number would exceed the size of a signed long
64-bit integer.

formatNameBytes

Copy a name into a buffer.
Copies characters from the name into the buffer
starting at the specified offset.
If the buffer is longer than the name, the buffer
is filled with trailing NULs.
If the name is longer than the buffer,
the output is truncated.

Parameters:

name - The header name from which to copy the characters.

buf - The buffer where the name is to be stored.

offset - The starting offset into the buffer

length - The maximum number of header bytes to copy.

Returns:

The updated offset, i.e. offset + length

formatNameBytes

Copy a name into a buffer.
Copies characters from the name into the buffer
starting at the specified offset.
If the buffer is longer than the name, the buffer
is filled with trailing NULs.
If the name is longer than the buffer,
the output is truncated.

formatLongOctalOrBinaryBytes

Write an long integer into a buffer as an octal string if this
will fit, or as a binary number otherwise.
Uses formatUnsignedOctalString(long, byte[], int, int) to format
the value as an octal string with leading zeros.
The converted number is followed by a space.

verifyCheckSum

The checksum is calculated by taking the sum of the unsigned byte values
of the header block with the eight checksum bytes taken to be ascii
spaces (decimal value 32). It is stored as a six digit octal number with
leading zeroes followed by a NUL and then a space. Various
implementations do not adhere to this format. For better compatibility,
ignore leading and trailing whitespace, and get the first six digits. In
addition, some historic tar implementations treated bytes as signed.
Implementations typically calculate the checksum both ways, and treat it
as good if either the signed or unsigned sum matches the included
checksum.

The return value of this method should be treated as a best-effort
heuristic rather than an absolute and final truth. The checksum
verification logic may well evolve over time as more special cases
are encountered.