org.apache.commons.compress.archivers.zip
Class ZipUtil

java.lang.Object
  extended by org.apache.commons.compress.archivers.zip.ZipUtil

public abstract class ZipUtil
extends java.lang.Object

Utility class for handling DOS and Java time conversions.


Field Summary
private static byte[] DOS_TIME_MIN
          Smallest date/time ZIP can handle.
 
Constructor Summary
ZipUtil()
           
 
Method Summary
static long adjustToLong(int i)
          Assumes a negative integer really is a positive integer that has wrapped around and re-creates the original value.
(package private) static boolean canHandleEntryData(ZipArchiveEntry entry)
          Whether this library is able to read or write the given entry.
(package private) static void checkRequestedFeatures(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.
static long dosToJavaTime(long dosTime)
          Converts DOS time to Java time (number of milliseconds since epoch).
static java.util.Date fromDosTime(ZipLong zipDosTime)
          Convert a DOS date/time field to a Date object.
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.
(package private) 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.
private static boolean supportsEncryptionOf(ZipArchiveEntry entry)
          Whether this library supports the encryption used by the given entry.
private static boolean supportsMethodOf(ZipArchiveEntry entry)
          Whether this library supports the compression method used by the given entry.
static ZipLong toDosTime(java.util.Date time)
          Convert a Date object to a DOS date/time field.
static byte[] toDosTime(long t)
          Convert a Date object to a DOS date/time field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOS_TIME_MIN

private static final byte[] DOS_TIME_MIN
Smallest date/time ZIP can handle.

Constructor Detail

ZipUtil

public ZipUtil()
Method Detail

toDosTime

public static ZipLong toDosTime(java.util.Date time)
Convert a Date object to a DOS date/time field.

Parameters:
time - the Date to 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

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.

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).


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.


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 STORED or DEFLATED

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