Class ArchiveUtils
java.lang.Object
org.apache.commons.compress.utils.ArchiveUtils
Generic Archive utilities
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isArrayZero
(byte[] a, int size) Returns true if the first N bytes of an array are all zerostatic boolean
isEqual
(byte[] buffer1, byte[] buffer2) Deprecated.static boolean
isEqual
(byte[] buffer1, byte[] buffer2, boolean ignoreTrailingNulls) Compare byte buffers, optionally ignoring trailing nullsstatic boolean
isEqual
(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) Compare byte buffersstatic boolean
isEqual
(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2, boolean ignoreTrailingNulls) Compare byte buffers, optionally ignoring trailing nullsstatic boolean
isEqualWithNull
(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) Compare byte buffers, ignoring trailing nullsstatic boolean
matchAsciiBuffer
(String expected, byte[] buffer) Check if buffer contents matches ASCII String.static boolean
matchAsciiBuffer
(String expected, byte[] buffer, int offset, int length) Check if buffer contents matches ASCII String.static String
Returns a "sanitized" version of the string given as arguments, where sanitized means non-printable characters have been replaced with a question mark and the outcome is not longer than 255 chars.static byte[]
toAsciiBytes
(String inputString) Convert a string to ASCII bytes.static String
toAsciiString
(byte[] inputBytes) Convert an input byte array to a String using the ASCII character set.static String
toAsciiString
(byte[] inputBytes, int offset, int length) Convert an input byte array to a String using the ASCII character set.static String
toString
(ArchiveEntry entry) Generates a string containing the name, isDirectory setting and size of an entry.
-
Method Details
-
isArrayZero
Returns true if the first N bytes of an array are all zero- Parameters:
a
- The array to checksize
- The number of characters to check (not the size of the array)- Returns:
- true if the first N bytes are zero
-
isEqual
Deprecated.Compare byte buffers- Parameters:
buffer1
- the first bufferbuffer2
- the second buffer- Returns:
true
if buffer1 and buffer2 have same contents
-
isEqual
Compare byte buffers, optionally ignoring trailing nulls- Parameters:
buffer1
- the first bufferbuffer2
- the second bufferignoreTrailingNulls
- whether to ignore trailing nulls- Returns:
true
if buffer1 and buffer2 have same contents
-
isEqual
public static boolean isEqual(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) Compare byte buffers- Parameters:
buffer1
- the first bufferoffset1
- the first offsetlength1
- the first lengthbuffer2
- the second bufferoffset2
- the second offsetlength2
- the second length- Returns:
true
if buffer1 and buffer2 have same contents
-
isEqual
public static boolean isEqual(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2, boolean ignoreTrailingNulls) Compare byte buffers, optionally ignoring trailing nulls- Parameters:
buffer1
- first bufferoffset1
- first offsetlength1
- first lengthbuffer2
- second bufferoffset2
- second offsetlength2
- second lengthignoreTrailingNulls
- whether to ignore trailing nulls- Returns:
true
if buffer1 and buffer2 have same contents, having regard to trailing nulls
-
isEqualWithNull
public static boolean isEqualWithNull(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) Compare byte buffers, ignoring trailing nulls- Parameters:
buffer1
- the first bufferoffset1
- the first offsetlength1
- the first lengthbuffer2
- the second bufferoffset2
- the second offsetlength2
- the second length- Returns:
true
if buffer1 and buffer2 have same contents, having regard to trailing nulls
-
matchAsciiBuffer
Check if buffer contents matches ASCII String.- Parameters:
expected
- the expected stringbuffer
- the buffer- Returns:
true
if buffer is the same as the expected string
-
matchAsciiBuffer
Check if buffer contents matches ASCII String.- Parameters:
expected
- expected stringbuffer
- the bufferoffset
- offset to read fromlength
- length of the buffer- Returns:
true
if buffer is the same as the expected string
-
sanitize
Returns a "sanitized" version of the string given as arguments, where sanitized means non-printable characters have been replaced with a question mark and the outcome is not longer than 255 chars.This method is used to clean up file names when they are used in exception messages as they may end up in log files or as console output and may have been read from a corrupted input.
- Parameters:
s
- the string to sanitize- Returns:
- a sanitized version of the argument
- Since:
- 1.12
-
toAsciiBytes
Convert a string to ASCII bytes. Used for comparing "magic" strings which need to be independent of the default Locale.- Parameters:
inputString
- string to convert- Returns:
- the bytes
-
toAsciiString
Convert an input byte array to a String using the ASCII character set.- Parameters:
inputBytes
- bytes to convert- Returns:
- the bytes, interpreted as an ASCII string
-
toAsciiString
Convert an input byte array to a String using the ASCII character set.- Parameters:
inputBytes
- input byte arrayoffset
- offset within arraylength
- length of array- Returns:
- the bytes, interpreted as an ASCII string
-
toString
Generates a string containing the name, isDirectory setting and size of an entry.For example:
- 2000 main.c d 100 testfiles
- Parameters:
entry
- the entry- Returns:
- the representation of the entry
-
Arrays.equals(byte[], byte[])
.