Top Description Fields Constructors Methods
org.apache.commons.compress.utils

public Class ArchiveUtils

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.US_ASCII

Generic Archive utilities

Field Summary

Modifier and TypeField and Description
private static final int

Constructor Summary

AccessConstructor and Description
private
ArchiveUtils()

Private constructor to prevent instantiation of this utility class.

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if the first N bytes are zero
isArrayZero
(final byte[]
The array to check
a
,
final int
The number of characters to check (not the size of the array)
size
)

Returns true if the first N bytes of an array are all zero

public static boolean

Returns:

true if buffer1 and buffer2 have same contents
isEqual
(final byte[]
the first buffer
buffer1
,
final byte[]
the second buffer
buffer2
)

Compare byte buffers
public static boolean

Returns:

true if buffer1 and buffer2 have same contents
isEqual
(final byte[]
the first buffer
buffer1
,
final byte[]
the second buffer
buffer2
,
final boolean
whether to ignore trailing nulls
ignoreTrailingNulls
)

Compare byte buffers, optionally ignoring trailing nulls

public static boolean

Returns:

true if buffer1 and buffer2 have same contents
isEqual
(final byte[]
the first buffer
buffer1
,
final int
the first offset
offset1
,
final int
the first length
length1
,
final byte[]
the second buffer
buffer2
,
final int
the second offset
offset2
,
final int
the second length
length2
)

Compare byte buffers

public static boolean

Returns:

true if buffer1 and buffer2 have same contents, having regard to trailing nulls
isEqual
(final byte[]
first buffer
buffer1
,
final int
first offset
offset1
,
final int
first length
length1
,
final byte[]
second buffer
buffer2
,
final int
second offset
offset2
,
final int
second length
length2
,
final boolean
whether to ignore trailing nulls
ignoreTrailingNulls
)

Compare byte buffers, optionally ignoring trailing nulls

public static boolean

Returns:

true if buffer1 and buffer2 have same contents, having regard to trailing nulls
isEqualWithNull
(final byte[]
the first buffer
buffer1
,
final int
the first offset
offset1
,
final int
the first length
length1
,
final byte[]
the second buffer
buffer2
,
final int
the second offset
offset2
,
final int
the second length
length2
)

Compare byte buffers, ignoring trailing nulls

public static boolean

Returns:

true if buffer is the same as the expected string
matchAsciiBuffer
(final String
the expected string
expected
,
final byte[]
the buffer
buffer
)

Check if buffer contents matches ASCII String.

public static boolean

Returns:

true if buffer is the same as the expected string
matchAsciiBuffer
(final String
expected string
expected
,
final byte[]
the buffer
buffer
,
final int
offset to read from
offset
,
final int
length of the buffer
length
)

Check if buffer contents matches ASCII String.

public static String

Returns:

a sanitized version of the argument
sanitize
(final String
the string to sanitize
s
)

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.

public static byte[]

Returns:

the bytes
toAsciiBytes
(final String
string to convert
inputString
)

Convert a string to ASCII bytes.

public static String

Returns:

the bytes, interpreted as an ASCII string
toAsciiString
(final byte[]
bytes to convert
inputBytes
)

Convert an input byte array to a String using the ASCII character set.

public static String

Returns:

the bytes, interpreted as an ASCII string
toAsciiString
(final byte[]
input byte array
inputBytes
,
final int
offset within array
offset
,
final int
length of array
length
)

Convert an input byte array to a String using the ASCII character set.

public static String

Returns:

the representation of the entry
toString
(final ArchiveEntry
the entry
entry
)

Generates a string containing the name, isDirectory setting and size of an entry.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_SANITIZED_NAME_LENGTHback to summary
private static final int MAX_SANITIZED_NAME_LENGTH

Constructor Detail

ArchiveUtilsback to summary
private ArchiveUtils()

Private constructor to prevent instantiation of this utility class.

Method Detail

isArrayZeroback to summary
public static boolean isArrayZero(final byte[] a, final int size)

Returns true if the first N bytes of an array are all zero

Parameters
a:byte[]

The array to check

size:int

The number of characters to check (not the size of the array)

Returns:boolean

true if the first N bytes are zero

isEqualback to summary
public static boolean isEqual(final byte[] buffer1, final byte[] buffer2)

Compare byte buffers

Parameters
buffer1:byte[]

the first buffer

buffer2:byte[]

the second buffer

Returns:boolean

true if buffer1 and buffer2 have same contents

Annotations
@Deprecated
isEqualback to summary
public static boolean isEqual(final byte[] buffer1, final byte[] buffer2, final boolean ignoreTrailingNulls)

Compare byte buffers, optionally ignoring trailing nulls

Parameters
buffer1:byte[]

the first buffer

buffer2:byte[]

the second buffer

ignoreTrailingNulls:boolean

whether to ignore trailing nulls

Returns:boolean

true if buffer1 and buffer2 have same contents

isEqualback to summary
public static boolean isEqual(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2, final int offset2, final int length2)

Compare byte buffers

Parameters
buffer1:byte[]

the first buffer

offset1:int

the first offset

length1:int

the first length

buffer2:byte[]

the second buffer

offset2:int

the second offset

length2:int

the second length

Returns:boolean

true if buffer1 and buffer2 have same contents

isEqualback to summary
public static boolean isEqual(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2, final int offset2, final int length2, final boolean ignoreTrailingNulls)

Compare byte buffers, optionally ignoring trailing nulls

Parameters
buffer1:byte[]

first buffer

offset1:int

first offset

length1:int

first length

buffer2:byte[]

second buffer

offset2:int

second offset

length2:int

second length

ignoreTrailingNulls:boolean

whether to ignore trailing nulls

Returns:boolean

true if buffer1 and buffer2 have same contents, having regard to trailing nulls

isEqualWithNullback to summary
public static boolean isEqualWithNull(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2, final int offset2, final int length2)

Compare byte buffers, ignoring trailing nulls

Parameters
buffer1:byte[]

the first buffer

offset1:int

the first offset

length1:int

the first length

buffer2:byte[]

the second buffer

offset2:int

the second offset

length2:int

the second length

Returns:boolean

true if buffer1 and buffer2 have same contents, having regard to trailing nulls

matchAsciiBufferback to summary
public static boolean matchAsciiBuffer(final String expected, final byte[] buffer)

Check if buffer contents matches ASCII String.

Parameters
expected:String

the expected string

buffer:byte[]

the buffer

Returns:boolean

true if buffer is the same as the expected string

matchAsciiBufferback to summary
public static boolean matchAsciiBuffer(final String expected, final byte[] buffer, final int offset, final int length)

Check if buffer contents matches ASCII String.

Parameters
expected:String

expected string

buffer:byte[]

the buffer

offset:int

offset to read from

length:int

length of the buffer

Returns:boolean

true if buffer is the same as the expected string

sanitizeback to summary
public static String sanitize(final String s)

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:String

the string to sanitize

Returns:String

a sanitized version of the argument

Since
1.12
toAsciiBytesback to summary
public static byte[] toAsciiBytes(final String inputString)

Convert a string to ASCII bytes. Used for comparing "magic" strings which need to be independent of the default Locale.

Parameters
inputString:String

string to convert

Returns:byte[]

the bytes

toAsciiStringback to summary
public static String toAsciiString(final byte[] inputBytes)

Convert an input byte array to a String using the ASCII character set.

Parameters
inputBytes:byte[]

bytes to convert

Returns:String

the bytes, interpreted as an ASCII string

toAsciiStringback to summary
public static String toAsciiString(final byte[] inputBytes, final int offset, final int length)

Convert an input byte array to a String using the ASCII character set.

Parameters
inputBytes:byte[]

input byte array

offset:int

offset within array

length:int

length of array

Returns:String

the bytes, interpreted as an ASCII string

toStringback to summary
public static String toString(final ArchiveEntry entry)

Generates a string containing the name, isDirectory setting and size of an entry.

For example:

-    2000 main.c
d     100 testfiles
Parameters
entry:ArchiveEntry

the entry

Returns:String

the representation of the entry