TrueZIP Driver ZIP 7.1

de.schlichtherle.truezip.zip
Enum DateTimeConverter

java.lang.Object
  extended by java.lang.Enum<DateTimeConverter>
      extended by de.schlichtherle.truezip.zip.DateTimeConverter
All Implemented Interfaces:
Serializable, Comparable<DateTimeConverter>

@ThreadSafe
@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public enum DateTimeConverter
extends Enum<DateTimeConverter>

Converts Java time values to DOS date/time values and vice versa. This class has been introduced in order to enhance interoperability between different flavours of the ZIP file format specification when converting date/time from the serialized DOS format in a ZIP file to the local system time, which is represented by a UNIX-like encoding by the Java API.

Author:
Christian Schlichtherle

Nested Class Summary
private  class DateTimeConverter.ThreadLocalGregorianCalendar
           
 
Enum Constant Summary
JAR
          This instance applies the schedule for Daylight Saving Time (DST), i.e. all time conversions will apply DST where appropriate to a particular date.
ZIP
          This instance ignores the schedule for Daylight Saving Time (DST), i.e. all time conversions will use the same raw offset and current DST savings, regardless of whether DST savings should be applied to a particular date or not.
 
Field Summary
private  ThreadLocal<GregorianCalendar> calendar
          A thread local lenient gregorian calendar for date/time conversion which has its timezone set to the return value of newTimeZone().
(package private) static long MAX_DOS_TIME
          Largest supported DOS date/time value in a ZIP file, which is December 31st, 2107 AD 23:59:58 local time.
(package private) static long MIN_DOS_TIME
          Smallest supported DOS date/time value in a ZIP file, which is January 1st, 1980 AD 00:00:00 local time.
 
Method Summary
private  GregorianCalendar getGregorianCalendar()
          Returns a thread local lenient gregorian calendar for date/time conversion which has its timezone set to the return value of newTimeZone().
(package private) abstract  TimeZone newTimeZone()
          Returns a new timezone to use for date/time conversion.
(package private) abstract  boolean roundUp(long jTime)
          Returns whether the given Java time should be rounded up or down to the next two second interval when converting it to a DOS date/time.
(package private)  long toDosTime(long jTime)
          Converts a Java time value to a DOS date/time value.
(package private)  long toJavaTime(long dTime)
          Converts a 32 bit integer encoded DOS date/time value to a Java time value.
static DateTimeConverter valueOf(String name)
          Returns the enum constant of this type with the specified name.
static DateTimeConverter[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

JAR

public static final DateTimeConverter JAR
This instance applies the schedule for Daylight Saving Time (DST), i.e. all time conversions will apply DST where appropriate to a particular date.

This behaviour provides best interoperability with:


ZIP

public static final DateTimeConverter ZIP
This instance ignores the schedule for Daylight Saving Time (DST), i.e. all time conversions will use the same raw offset and current DST savings, regardless of whether DST savings should be applied to a particular date or not.

This behavior provides best interoperability with:

Field Detail

MIN_DOS_TIME

static final long MIN_DOS_TIME
Smallest supported DOS date/time value in a ZIP file, which is January 1st, 1980 AD 00:00:00 local time.

See Also:
Constant Field Values

MAX_DOS_TIME

static final long MAX_DOS_TIME
Largest supported DOS date/time value in a ZIP file, which is December 31st, 2107 AD 23:59:58 local time.

See Also:
Constant Field Values

calendar

private final ThreadLocal<GregorianCalendar> calendar
A thread local lenient gregorian calendar for date/time conversion which has its timezone set to the return value of newTimeZone().

Method Detail

values

public static DateTimeConverter[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (DateTimeConverter c : DateTimeConverter.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static DateTimeConverter valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

newTimeZone

abstract TimeZone newTimeZone()
Returns a new timezone to use for date/time conversion. All returned instances must have the same rules.

Returns:
A new timezone for date/time conversion - never null.

roundUp

abstract boolean roundUp(long jTime)
Returns whether the given Java time should be rounded up or down to the next two second interval when converting it to a DOS date/time.

Parameters:
jTime - The number of milliseconds since midnight, January 1st, 1970 AD UTC (called epoch alias Java time).
Returns:
true for round-up, false for round-down.

getGregorianCalendar

private GregorianCalendar getGregorianCalendar()
Returns a thread local lenient gregorian calendar for date/time conversion which has its timezone set to the return value of newTimeZone().

Returns:
A thread local lenient gregorian calendar.

toDosTime

final long toDosTime(long jTime)
Converts a Java time value to a DOS date/time value. The returned value is rounded up or down to even seconds, depending on roundUp(long). If the Java time value is earlier than January 1st, 1980 AD 00:00:00 local time, then this value is returned instead.

This method uses a lenient DateTimeConverter.ThreadLocalGregorianCalendar for the date/time conversion which has its timezone set to the return value of newTimeZone().

Parameters:
jTime - The number of milliseconds since midnight, January 1st, 1970 AD UTC (called the epoch alias Java time).
Returns:
A DOS date/time value reflecting the local time zone and rounded down to even seconds which is minimum January 1st, 1980 AD 00:00:00.
Throws:
RuntimeException - If jTime is negative or later than 2107 AD.
See Also:
toJavaTime(long), newTimeZone()

toJavaTime

final long toJavaTime(long dTime)
Converts a 32 bit integer encoded DOS date/time value to a Java time value.

Note that not all 32 bit integers are valid DOS date/time values. If an invalid DOS date/time value is provided, it gets adjusted by overflowing the respective field value as if using a lenient calendar. This feature is provided in order to read bogus ZIP archive files created by third party tools. However, the returned Java time may differ from its intended value at the time of the creation of the ZIP archive file and when converting it back again, the resulting DOS date/time value will not be the same as dTime.

This method uses a lenient DateTimeConverter.ThreadLocalGregorianCalendar for the date/time conversion which has its timezone set to the return value of newTimeZone().

Parameters:
dTime - The DOS date/time value.
Returns:
The number of milliseconds since midnight, January 1st, 1970 AD UTC (called epoch alias Java time).
Throws:
IllegalArgumentException - If dTime is earlier than 1980 AD or greater than 0xffffffffL.
See Also:
toDosTime(long), newTimeZone()

TrueZIP Driver ZIP 7.1

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.