Package loci.poi.hpsf

Class Util

java.lang.Object
loci.poi.hpsf.Util

public class Util extends Object

Provides various static utility methods.

Since:
2002-02-09
Version:
$Id: Util.java 550886 2007-06-26 17:58:28Z klute $
Author:
Rainer Klute (klute@rainer-klute.de)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The difference between the Windows epoch (1601-01-01 00:00:00) and the Unix epoch (1970-01-01 00:00:00) in milliseconds: 11644473600000L.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    cat(byte[][] byteArrays)
    Concatenates the contents of several byte arrays into a single one.
    static byte[]
    copy(byte[] src, int offset, int length)
    Copies bytes from a source byte array into a new byte array.
    static void
    copy(byte[] src, int srcOffset, int length, byte[] dst, int dstOffset)
    Copies a part of a byte array into another byte array.
    static long
    Converts a Date into a filetime.
    static boolean
    equal(byte[] a, byte[] b)
    Checks whether two byte arrays a and b are equal.
    static boolean
    equals(Object[] c1, Object[] c2)
    Compares to object arrays with regarding the objects' order.
    static boolean
    Checks whether two collections are equal.
    static Date
    filetimeToDate(int high, int low)
    Converts a Windows FILETIME into a Date.
    static Date
    filetimeToDate(long filetime)
    Converts a Windows FILETIME into a Date.
    static byte[]
    pad4(byte[] ba)
    Pads a byte array with 0x00 bytes so that its length is a multiple of 4.
    static char[]
    pad4(char[] ca)
    Pads a character array with 0x0000 characters so that its length is a multiple of 4.
    static char[]
    Pads a string with 0x0000 characters so that its length is a multiple of 4.
    static String
    Returns a textual representation of a Throwable, including a stacktrace.

    Methods inherited from class java.lang.Object

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

    • EPOCH_DIFF

      public static final long EPOCH_DIFF

      The difference between the Windows epoch (1601-01-01 00:00:00) and the Unix epoch (1970-01-01 00:00:00) in milliseconds: 11644473600000L. (Use your favorite spreadsheet program to verify the correctness of this value. By the way, did you notice that you can tell from the epochs which operating system is the modern one? :-))

      See Also:
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • equal

      public static boolean equal(byte[] a, byte[] b)

      Checks whether two byte arrays a and b are equal. They are equal

      • if they have the same length and

      • if for each i with i >= 0 and i < a.length holds a[i] == b[i].

      Parameters:
      a - The first byte array
      b - The first byte array
      Returns:
      true if the byte arrays are equal, else false
    • copy

      public static void copy(byte[] src, int srcOffset, int length, byte[] dst, int dstOffset)

      Copies a part of a byte array into another byte array.

      Parameters:
      src - The source byte array.
      srcOffset - Offset in the source byte array.
      length - The number of bytes to copy.
      dst - The destination byte array.
      dstOffset - Offset in the destination byte array.
    • cat

      public static byte[] cat(byte[][] byteArrays)

      Concatenates the contents of several byte arrays into a single one.

      Parameters:
      byteArrays - The byte arrays to be concatened.
      Returns:
      A new byte array containing the concatenated byte arrays.
    • copy

      public static byte[] copy(byte[] src, int offset, int length)

      Copies bytes from a source byte array into a new byte array.

      Parameters:
      src - Copy from this byte array.
      offset - Start copying here.
      length - Copy this many bytes.
      Returns:
      The new byte array. Its length is number of copied bytes.
    • filetimeToDate

      public static Date filetimeToDate(int high, int low)

      Converts a Windows FILETIME into a Date. The Windows FILETIME structure holds a date and time associated with a file. The structure identifies a 64-bit integer specifying the number of 100-nanosecond intervals which have passed since January 1, 1601. This 64-bit value is split into the two double words stored in the structure.

      Parameters:
      high - The higher double word of the FILETIME structure.
      low - The lower double word of the FILETIME structure.
      Returns:
      The Windows FILETIME as a Date.
    • filetimeToDate

      public static Date filetimeToDate(long filetime)

      Converts a Windows FILETIME into a Date. The Windows FILETIME structure holds a date and time associated with a file. The structure identifies a 64-bit integer specifying the number of 100-nanosecond intervals which have passed since January 1, 1601.

      Parameters:
      filetime - The filetime to convert.
      Returns:
      The Windows FILETIME as a Date.
    • dateToFileTime

      public static long dateToFileTime(Date date)

      Converts a Date into a filetime.

      Parameters:
      date - The date to be converted
      Returns:
      The filetime
      See Also:
    • equals

      public static boolean equals(Collection c1, Collection c2)

      Checks whether two collections are equal. Two collections C1 and C2 are equal, if the following conditions are true:

      • For each c1i (element of C1) there is a c2j (element of C2), and c1i equals c2j.

      • For each c2i (element of C2) there is a c1j (element of C1) and c2i equals c1j.

      Parameters:
      c1 - the first collection
      c2 - the second collection
      Returns:
      true if the collections are equal, else false.
    • equals

      public static boolean equals(Object[] c1, Object[] c2)

      Compares to object arrays with regarding the objects' order. For example, [1, 2, 3] and [2, 1, 3] are equal.

      Parameters:
      c1 - The first object array.
      c2 - The second object array.
      Returns:
      true if the object arrays are equal, false if they are not.
    • pad4

      public static byte[] pad4(byte[] ba)

      Pads a byte array with 0x00 bytes so that its length is a multiple of 4.

      Parameters:
      ba - The byte array to pad.
      Returns:
      The padded byte array.
    • pad4

      public static char[] pad4(char[] ca)

      Pads a character array with 0x0000 characters so that its length is a multiple of 4.

      Parameters:
      ca - The character array to pad.
      Returns:
      The padded character array.
    • pad4

      public static char[] pad4(String s)

      Pads a string with 0x0000 characters so that its length is a multiple of 4.

      Parameters:
      s - The string to pad.
      Returns:
      The padded string as a character array.
    • toString

      public static String toString(Throwable t)

      Returns a textual representation of a Throwable, including a stacktrace.

      Parameters:
      t - The Throwable
      Returns:
      a string containing the output of a call to t.printStacktrace().