Modifier and Type | Method and Description |
---|---|
static long |
computeCheckSum(byte[] buf)
Compute the checksum of a tar entry header.
|
static int |
formatCheckSumOctalBytes(long value,
byte[] buf,
int offset,
int length)
Writes an octal value into a buffer.
|
static int |
formatLongOctalBytes(long value,
byte[] buf,
int offset,
int length)
Write an octal long integer into a buffer.
|
static int |
formatLongOctalOrBinaryBytes(long value,
byte[] buf,
int offset,
int length)
Write an long integer into a buffer as an octal string if this
will fit, or as a binary number otherwise.
|
static int |
formatNameBytes(String name,
byte[] buf,
int offset,
int length)
Copy a name into a buffer.
|
static int |
formatNameBytes(String name,
byte[] buf,
int offset,
int length,
ZipEncoding encoding)
Copy a name into a buffer.
|
static int |
formatOctalBytes(long value,
byte[] buf,
int offset,
int length)
Write an octal integer into a buffer.
|
static void |
formatUnsignedOctalString(long value,
byte[] buffer,
int offset,
int length)
Fill buffer with unsigned octal number, padded with leading zeroes.
|
static boolean |
parseBoolean(byte[] buffer,
int offset)
Parse a boolean byte from a buffer.
|
protected static List<TarArchiveStructSparse> |
parseFromPAX01SparseHeaders(String sparseMap)
For PAX Format 0.1, the sparse headers are stored in a single variable : GNU.sparse.map
GNU.sparse.map
Map of non-null data chunks.
|
static String |
parseName(byte[] buffer,
int offset,
int length)
Parse an entry name from a buffer.
|
static String |
parseName(byte[] buffer,
int offset,
int length,
ZipEncoding encoding)
Parse an entry name from a buffer.
|
static long |
parseOctal(byte[] buffer,
int offset,
int length)
Parse an octal string from a buffer.
|
static long |
parseOctalOrBinary(byte[] buffer,
int offset,
int length)
Compute the value contained in a byte buffer.
|
protected static List<TarArchiveStructSparse> |
parsePAX01SparseHeaders(String sparseMap)
Deprecated.
use #parseFromPAX01SparseHeaders instead
|
protected static List<TarArchiveStructSparse> |
parsePAX1XSparseHeaders(InputStream inputStream,
int recordSize)
For PAX Format 1.X:
The sparse map itself is stored in the file data block, preceding the actual file data.
|
protected static Map<String,String> |
parsePaxHeaders(InputStream inputStream,
List<TarArchiveStructSparse> sparseHeaders,
Map<String,String> globalPaxHeaders)
Deprecated.
use the four-arg version instead
|
protected static Map<String,String> |
parsePaxHeaders(InputStream inputStream,
List<TarArchiveStructSparse> sparseHeaders,
Map<String,String> globalPaxHeaders,
long headerSize)
For PAX Format 0.0, the sparse headers(GNU.sparse.offset and GNU.sparse.numbytes)
may appear multi times, and they look like:
GNU.sparse.size=size
GNU.sparse.numblocks=numblocks
repeat numblocks times
GNU.sparse.offset=offset
GNU.sparse.numbytes=numbytes
end repeat
For PAX Format 0.1, the sparse headers are stored in a single variable : GNU.sparse.map
GNU.sparse.map
Map of non-null data chunks.
|
static TarArchiveStructSparse |
parseSparse(byte[] buffer,
int offset)
Parses the content of a PAX 1.0 sparse block.
|
static boolean |
verifyCheckSum(byte[] header)
Wikipedia says:
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).
|
public static long parseOctal(byte[] buffer, int offset, int length)
Leading spaces are ignored. The buffer must contain a trailing space or NUL, and may contain an additional trailing space or NUL.
The input buffer is allowed to contain all NULs, in which case the method returns 0L (this allows for missing fields).
To work-around some tar implementations that insert a leading NUL this method returns 0 if it detects a leading NUL since Commons Compress 1.4.
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 - must be at least 2 bytes.IllegalArgumentException
- if the trailing space/NUL is missing or if a invalid byte is detected.public static long parseOctalOrBinary(byte[] buffer, int offset, int length)
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.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.public static boolean parseBoolean(byte[] buffer, int offset)
buffer
- The buffer from which to parse.offset
- The offset into the buffer from which to parse.IllegalArgumentException
- if an invalid byte is detected.public static String parseName(byte[] buffer, int offset, int length)
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.public static String parseName(byte[] buffer, int offset, int length, ZipEncoding encoding) throws IOException
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.encoding
- name of the encoding to use for file namesIOException
- on errorpublic static TarArchiveStructSparse parseSparse(byte[] buffer, int offset)
buffer
- The buffer from which to parse.offset
- The offset into the buffer from which to parse.public static int formatNameBytes(String name, byte[] buf, int offset, int length)
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 bufferlength
- The maximum number of header bytes to copy.public static int formatNameBytes(String name, byte[] buf, int offset, int length, ZipEncoding encoding) throws IOException
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 bufferlength
- The maximum number of header bytes to copy.encoding
- name of the encoding to use for file namesIOException
- on errorpublic static void formatUnsignedOctalString(long value, byte[] buffer, int offset, int length)
value
- number to convert to octal - treated as unsignedbuffer
- destination bufferoffset
- starting offset in bufferlength
- length of buffer to fillIllegalArgumentException
- if the value will not fit in the bufferpublic static int formatOctalBytes(long value, byte[] buf, int offset, int length)
formatUnsignedOctalString(long, byte[], int, int)
to format
the value as an octal string with leading zeros.
The converted number is followed by space and NULvalue
- The value to writebuf
- The buffer to receive the outputoffset
- The starting offset into the bufferlength
- The size of the output bufferIllegalArgumentException
- if the value (and trailer) will not fit in the bufferpublic static int formatLongOctalBytes(long value, byte[] buf, int offset, int length)
formatUnsignedOctalString(long, byte[], int, int)
to format
the value as an octal string with leading zeros.
The converted number is followed by a space.value
- The value to write as octalbuf
- The destinationbuffer.offset
- The starting offset into the buffer.length
- The length of the bufferIllegalArgumentException
- if the value (and trailer) will not fit in the bufferpublic static int formatLongOctalOrBinaryBytes(long value, byte[] buf, int offset, int length)
formatUnsignedOctalString(long, byte[], int, int)
to format
the value as an octal string with leading zeros.
The converted number is followed by a space.value
- The value to write into the buffer.buf
- The destination buffer.offset
- The starting offset into the buffer.length
- The length of the buffer.IllegalArgumentException
- if the value (and trailer)
will not fit in the buffer.public static int formatCheckSumOctalBytes(long value, byte[] buf, int offset, int length)
formatUnsignedOctalString(long, byte[], int, int)
to format
the value as an octal string with leading zeros.
The converted number is followed by NUL and then space.value
- The value to convertbuf
- The destination bufferoffset
- The starting offset into the buffer.length
- The size of the buffer.IllegalArgumentException
- if the value (and trailer) will not fit in the bufferpublic static long computeCheckSum(byte[] buf)
buf
- The tar entry's header buffer.public static boolean verifyCheckSum(byte[] header)
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.
header
- tar header@Deprecated protected static Map<String,String> parsePaxHeaders(InputStream inputStream, List<TarArchiveStructSparse> sparseHeaders, Map<String,String> globalPaxHeaders) throws IOException
inputStream
- input stream to read keys and valuessparseHeaders
- used in PAX Format 0.0 & 0.1, as it may appear multiple times,
the sparse headers need to be stored in an array, not a mapglobalPaxHeaders
- global PAX headers of the tar archiveIOException
- if an I/O error occurs.protected static Map<String,String> parsePaxHeaders(InputStream inputStream, List<TarArchiveStructSparse> sparseHeaders, Map<String,String> globalPaxHeaders, long headerSize) throws IOException
inputStream
- input stream to read keys and valuessparseHeaders
- used in PAX Format 0.0 & 0.1, as it may appear multiple times,
the sparse headers need to be stored in an array, not a mapglobalPaxHeaders
- global PAX headers of the tar archiveheaderSize
- total size of the PAX header, will be ignored if negativeIOException
- if an I/O error occurs.@Deprecated protected static List<TarArchiveStructSparse> parsePAX01SparseHeaders(String sparseMap)
Will internally invoke parseFromPAX01SparseHeaders(java.lang.String)
and map IOExceptions to a RzuntimeException, You
should use parseFromPAX01SparseHeaders(java.lang.String)
directly instead.
sparseMap
- the sparse map string consisting of comma-separated values "offset,size[,offset-1,size-1...]"protected static List<TarArchiveStructSparse> parseFromPAX01SparseHeaders(String sparseMap) throws IOException
sparseMap
- the sparse map string consisting of comma-separated values "offset,size[,offset-1,size-1...]"IOException
- Corrupted TAR archive.protected static List<TarArchiveStructSparse> parsePAX1XSparseHeaders(InputStream inputStream, int recordSize) throws IOException
inputStream
- parsing source.recordSize
- The size the TAR headerIOException
- if an I/O error occurs.Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.