Class ZipUtil
- java.lang.Object
-
- org.apache.commons.compress.archivers.zip.ZipUtil
-
public abstract class ZipUtil extends java.lang.ObjectUtility class for handling DOS and Java time conversions.
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]DOS_TIME_MINSmallest date/time ZIP can handle.
-
Constructor Summary
Constructors Constructor Description ZipUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longadjustToLong(int i)Assumes a negative integer really is a positive integer that has wrapped around and re-creates the original value.(package private) static longbigToLong(java.math.BigInteger big)Converts a BigInteger into a long, and blows up (NumberFormatException) if the BigInteger is too big.(package private) static booleancanHandleEntryData(ZipArchiveEntry entry)Whether this library is able to read or write the given entry.(package private) static voidcheckRequestedFeatures(ZipArchiveEntry ze)Checks whether the entry requires features not (yet) supported by the library and throws an exception if it does.(package private) static byte[]copy(byte[] from)Create a copy of the given array - or return null if the argument is null.(package private) static voidcopy(byte[] from, byte[] to, int offset)static longdosToJavaTime(long dosTime)Converts DOS time to Java time (number of milliseconds since epoch).static java.util.DatefromDosTime(ZipLong zipDosTime)Convert a DOS date/time field to a Date object.private static java.lang.StringgetUnicodeStringIfOriginalMatches(AbstractUnicodeExtraField f, byte[] orig)If the stored CRC matches the one of the given name, return the Unicode name of the given field.(package private) static java.math.BigIntegerlongToBig(long l)Converts a long into a BigInteger.static byte[]reverse(byte[] array)Reverses a byte[] array.(package private) static voidsetNameAndCommentFromExtraFields(ZipArchiveEntry ze, byte[] originalNameBytes, byte[] commentBytes)If the entry has Unicode*ExtraFields and the CRCs of the names/comments match those of the extra fields, transfer the known Unicode values from the extra field.static intsignedByteToUnsignedInt(byte b)Converts a signed byte into an unsigned integer representation (e.g., -1 becomes 255).private static booleansupportsEncryptionOf(ZipArchiveEntry entry)Whether this library supports the encryption used by the given entry.private static booleansupportsMethodOf(ZipArchiveEntry entry)Whether this library supports the compression method used by the given entry.static byte[]toDosTime(long t)Convert a Date object to a DOS date/time field.static voidtoDosTime(long t, byte[] buf, int offset)Convert a Date object to a DOS date/time field.(package private) static voidtoDosTime(java.util.Calendar c, long t, byte[] buf, int offset)static ZipLongtoDosTime(java.util.Date time)Convert a Date object to a DOS date/time field.static byteunsignedIntToSignedByte(int i)Converts an unsigned integer to a signed byte (e.g., 255 becomes -1).
-
-
-
Method Detail
-
toDosTime
public static ZipLong toDosTime(java.util.Date time)
Convert a Date object to a DOS date/time field.- Parameters:
time- theDateto convert- Returns:
- the date as a
ZipLong
-
toDosTime
public static byte[] toDosTime(long t)
Convert a Date object to a DOS date/time field.Stolen from InfoZip's
fileio.c- Parameters:
t- number of milliseconds since the epoch- Returns:
- the date as a byte array
-
toDosTime
public static void toDosTime(long t, byte[] buf, int offset)Convert a Date object to a DOS date/time field.Stolen from InfoZip's
fileio.c- Parameters:
t- number of milliseconds since the epochbuf- the output bufferoffset- The offset within the output buffer of the first byte to be written. must be non-negative and no larger thanbuf.length-4
-
toDosTime
static void toDosTime(java.util.Calendar c, long t, byte[] buf, int offset)
-
adjustToLong
public static long adjustToLong(int i)
Assumes a negative integer really is a positive integer that has wrapped around and re-creates the original value.- Parameters:
i- the value to treat as unsigned int.- Returns:
- the unsigned int as a long.
-
reverse
public static byte[] reverse(byte[] array)
Reverses a byte[] array. Reverses in-place (thus provided array is mutated), but also returns same for convenience.- Parameters:
array- to reverse (mutated in-place, but also returned for convenience).- Returns:
- the reversed array (mutated in-place, but also returned for convenience).
- Since:
- 1.5
-
bigToLong
static long bigToLong(java.math.BigInteger big)
Converts a BigInteger into a long, and blows up (NumberFormatException) if the BigInteger is too big.- Parameters:
big- BigInteger to convert.- Returns:
- long representation of the BigInteger.
-
longToBig
static java.math.BigInteger longToBig(long l)
Converts a long into a BigInteger. Negative numbers between -1 and -2^31 are treated as unsigned 32 bit (e.g., positive) integers. Negative numbers below -2^31 cause an IllegalArgumentException to be thrown.
- Parameters:
l- long to convert to BigInteger.- Returns:
- BigInteger representation of the provided long.
-
signedByteToUnsignedInt
public static int signedByteToUnsignedInt(byte b)
Converts a signed byte into an unsigned integer representation (e.g., -1 becomes 255).- Parameters:
b- byte to convert to int- Returns:
- int representation of the provided byte
- Since:
- 1.5
-
unsignedIntToSignedByte
public static byte unsignedIntToSignedByte(int i)
Converts an unsigned integer to a signed byte (e.g., 255 becomes -1).- Parameters:
i- integer to convert to byte- Returns:
- byte representation of the provided int
- Throws:
java.lang.IllegalArgumentException- if the provided integer is not inside the range [0,255].- Since:
- 1.5
-
fromDosTime
public static java.util.Date fromDosTime(ZipLong zipDosTime)
Convert a DOS date/time field to a Date object.- Parameters:
zipDosTime- contains the stored DOS time.- Returns:
- a Date instance corresponding to the given time.
-
dosToJavaTime
public static long dosToJavaTime(long dosTime)
Converts DOS time to Java time (number of milliseconds since epoch).- Parameters:
dosTime- time to convert- Returns:
- converted time
-
setNameAndCommentFromExtraFields
static void setNameAndCommentFromExtraFields(ZipArchiveEntry ze, byte[] originalNameBytes, byte[] commentBytes)
If the entry has Unicode*ExtraFields and the CRCs of the names/comments match those of the extra fields, transfer the known Unicode values from the extra field.
-
getUnicodeStringIfOriginalMatches
private static java.lang.String getUnicodeStringIfOriginalMatches(AbstractUnicodeExtraField f, byte[] orig)
If the stored CRC matches the one of the given name, return the Unicode name of the given field.If the field is null or the CRCs don't match, return null instead.
-
copy
static byte[] copy(byte[] from)
Create a copy of the given array - or return null if the argument is null.
-
copy
static void copy(byte[] from, byte[] to, int offset)
-
canHandleEntryData
static boolean canHandleEntryData(ZipArchiveEntry entry)
Whether this library is able to read or write the given entry.
-
supportsEncryptionOf
private static boolean supportsEncryptionOf(ZipArchiveEntry entry)
Whether this library supports the encryption used by the given entry.- Returns:
- true if the entry isn't encrypted at all
-
supportsMethodOf
private static boolean supportsMethodOf(ZipArchiveEntry entry)
Whether this library supports the compression method used by the given entry.- Returns:
- true if the compression method is supported
-
checkRequestedFeatures
static void checkRequestedFeatures(ZipArchiveEntry ze) throws UnsupportedZipFeatureException
Checks whether the entry requires features not (yet) supported by the library and throws an exception if it does.- Throws:
UnsupportedZipFeatureException
-
-