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

public abstract class ZipUtil extends Object
Utility class for handling DOS and Java time conversions.
This class is immutable
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    adjustToLong(int i)
    Assumes a negative integer really is a positive integer that has wrapped around and re-creates the original value.
    static long
    dosToJavaTime(long dosTime)
    Converts DOS time to Java time (number of milliseconds since epoch).
    static Date
    fromDosTime(ZipLong zipDosTime)
    Converts a DOS date/time field to a Date object.
    static boolean
    isDosTime(long time)
    Tests whether a given time (in milliseconds since Epoch) can be safely represented as DOS time
    static byte[]
    reverse(byte[] array)
    Reverses a byte[] array.
    static int
    Converts a signed byte into an unsigned integer representation (e.g., -1 becomes 255).
    static byte[]
    toDosTime(long t)
    Converts a Date object to a DOS date/time field.
    static void
    toDosTime(long t, byte[] buf, int offset)
    Converts a Date object to a DOS date/time field.
    static ZipLong
    Converts a Date object to a DOS date/time field.
    static byte
    Converts an unsigned integer to a signed byte (e.g., 255 becomes -1).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • 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.
    • 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
    • fromDosTime

      public static Date fromDosTime(ZipLong zipDosTime)
      Converts 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.
    • isDosTime

      public static boolean isDosTime(long time)
      Tests whether a given time (in milliseconds since Epoch) can be safely represented as DOS time
      Parameters:
      time - time in milliseconds since epoch
      Returns:
      true if the time can be safely represented as DOS time, false otherwise
      Since:
      1.23
    • 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
    • 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
    • toDosTime

      public static ZipLong toDosTime(Date time)
      Converts 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)
      Converts 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)
      Converts a Date object to a DOS date/time field.

      Stolen from InfoZip's fileio.c

      Parameters:
      t - number of milliseconds since the epoch
      buf - the output buffer
      offset - The offset within the output buffer of the first byte to be written. must be non-negative and no larger than buf.length-4
    • 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:
      IllegalArgumentException - if the provided integer is not inside the range [0,255].
      Since:
      1.5