| java.lang.Object org.archive.util.ArchiveUtils
ArchiveUtils | public class ArchiveUtils (Code) | | Miscellaneous useful methods.
author: gojomo & others |
Method Summary | |
public static String | addImpliedHttpIfNecessary(String u) Given a string that may be a plain host or host/path (without
URI scheme), add an implied http:// if necessary. | public static boolean | byteArrayEquals(byte[] lhs, byte[] rhs) check that two byte arrays are equal. | public static long | byteArrayIntoLong(byte[] bytearray) | public static long | byteArrayIntoLong(byte[] bytearray, int offset) Byte array into long.
Parameters: bytearray - Array to convert to a long. Parameters: offset - Offset into array at which we start decoding the long. | public static long | classnameBasedUID(Class class1, int version) Generate a long UID based on the given class and version number. | public static String | doubleToString(double val, int maxFractionDigits) Converts a double to a string. | public static String | formatBytesForDisplay(long amount) Takes a byte size and formats it for display with 'friendly' units. | public static String | formatMillisecondsToConventional(long time) | public static String | formatMillisecondsToConventional(long time, boolean toMs) | public static String | get12DigitDate() Utility function for creating arc-style date stamps
in the format yyyMMddHHmm. | public static String | get12DigitDate(long date) Utility function for creating arc-style date stamps
in the format yyyyMMddHHmm. | public static String | get12DigitDate(Date d) | public static String | get14DigitDate() Utility function for creating arc-style date stamps
in the format yyyMMddHHmmss. | public static String | get14DigitDate(long date) Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmss. | public static String | get14DigitDate(Date d) | public static String | get17DigitDate() Utility function for creating arc-style date stamps
in the format yyyMMddHHmmssSSS. | public static String | get17DigitDate(long date) Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmssSSS. | public static String | get17DigitDate(Date date) | public static Date | getDate(String d) Parses an ARC-style date. | public static String | getLog14Date() Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC. | public static String | getLog14Date(long date) Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC. | public static String | getLog14Date(Date date) Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC. | public static String | getLog17Date() Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC. | public static String | getLog17Date(long date) Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC. | public static Date | getSecondsSinceEpoch(String timestamp) Parameters: timestamp - A 14-digit timestamp or the suffix for a 14-digittimestamp: E.g. | public static void | longIntoByteArray(long l, byte[] array, int offset) Copy the raw bytes of a long into a byte array, starting at
the specified offset. | public static String | padTo(int i, int pad) Convert an int to a String , and pad it to
pad spaces.
Parameters: i - the int Parameters: pad - the width to pad to. | public static String | padTo(String s, int pad) Pad the given String to pad characters wide
by pre-pending spaces. | public static String | padTo(String s, int pad, char padChar) Pad the given String to pad characters wide
by pre-pending padChar .
s should not be null . | public static Date | parse12DigitDate(String date) Utility function for parsing arc-style date stamps
in the format yyyMMddHHmm.
Date stamps are in the UTC time zone. | public static Date | parse14DigitDate(String date) Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmss.
Date stamps are in the UTC time zone. | public static Date | parse17DigitDate(String date) Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmssSSS.
Date stamps are in the UTC time zone. | public static String | secondsSinceEpoch(String timestamp) Parameters: timestamp - A 14-digit timestamp or the suffix for a 14-digittimestamp: E.g. | public static String | singleLineReport(Reporter rep) | public static boolean | startsWith(byte[] array, byte[] prefix) Verify that the array begins with the prefix. | public static Calendar | timestamp17ToCalendar(String timestamp17String) Convert 17-digit date format timestamps (as found in crawl.log, for
example) into a GregorianCalendar object. | public static String | writeReportToString(Reporter rep, String name) Compose the requested report into a String. | public static String | zeroPadInteger(int i) Parameters: i - Integer to add prefix of zeros too. |
MAX_INT_CHAR_WIDTH | public static int MAX_INT_CHAR_WIDTH(Code) | | |
addImpliedHttpIfNecessary | public static String addImpliedHttpIfNecessary(String u)(Code) | | Given a string that may be a plain host or host/path (without
URI scheme), add an implied http:// if necessary.
Parameters: u - string to evaluate string with http:// added if no scheme already present |
byteArrayEquals | public static boolean byteArrayEquals(byte[] lhs, byte[] rhs)(Code) | | check that two byte arrays are equal. They may be null .
Parameters: lhs - a byte array Parameters: rhs - another byte array. true if they are both equal (or bothnull ) |
byteArrayIntoLong | public static long byteArrayIntoLong(byte[] bytearray)(Code) | | |
byteArrayIntoLong | public static long byteArrayIntoLong(byte[] bytearray, int offset)(Code) | | Byte array into long.
Parameters: bytearray - Array to convert to a long. Parameters: offset - Offset into array at which we start decoding the long. Long made of the bytes of array beginning atoffset offset . See Also: ArchiveUtils.longIntoByteArray(long,byte[],int) |
classnameBasedUID | public static long classnameBasedUID(Class class1, int version)(Code) | | Generate a long UID based on the given class and version number.
Using this instead of the default will assume serialization
compatibility across class changes unless version number is
intentionally bumped.
Parameters: class1 - Parameters: version - UID based off class and version number. |
doubleToString | public static String doubleToString(double val, int maxFractionDigits)(Code) | | Converts a double to a string.
Parameters: val - The double to convert Parameters: precision - How many characters to include after '.' the double as a string. |
formatBytesForDisplay | public static String formatBytesForDisplay(long amount)(Code) | | Takes a byte size and formats it for display with 'friendly' units.
This involves converting it to the largest unit
(of B, KB, MB, GB, TB) for which the amount will be > 1.
Additionally, at least 2 significant digits are always displayed.
Displays as bytes (B): 0-1023
Displays as kilobytes (KB): 1024 - 2097151 (~2Mb)
Displays as megabytes (MB): 2097152 - 4294967295 (~4Gb)
Displays as gigabytes (GB): 4294967296 - infinity
Negative numbers will be returned as '0 B'.
Parameters: amount - the amount of bytes A string containing the amount, properly formated. |
formatMillisecondsToConventional | public static String formatMillisecondsToConventional(long time)(Code) | | Convert milliseconds value to a human-readable duration
Parameters: time - Human readable string version of passed time |
formatMillisecondsToConventional | public static String formatMillisecondsToConventional(long time, boolean toMs)(Code) | | Convert milliseconds value to a human-readable duration
Parameters: time - Parameters: toMs - whether to print to the ms Human readable string version of passed time |
get12DigitDate | public static String get12DigitDate()(Code) | | Utility function for creating arc-style date stamps
in the format yyyMMddHHmm.
Date stamps are in the UTC time zone
the date stamp |
get12DigitDate | public static String get12DigitDate(long date)(Code) | | Utility function for creating arc-style date stamps
in the format yyyyMMddHHmm.
Date stamps are in the UTC time zone
Parameters: date - milliseconds since epoc the date stamp |
get14DigitDate | public static String get14DigitDate()(Code) | | Utility function for creating arc-style date stamps
in the format yyyMMddHHmmss.
Date stamps are in the UTC time zone
the date stamp |
get14DigitDate | public static String get14DigitDate(long date)(Code) | | Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmss.
Date stamps are in the UTC time zone
Parameters: date - milliseconds since epoc the date stamp |
get17DigitDate | public static String get17DigitDate()(Code) | | Utility function for creating arc-style date stamps
in the format yyyMMddHHmmssSSS.
Date stamps are in the UTC time zone
the date stamp |
get17DigitDate | public static String get17DigitDate(long date)(Code) | | Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmssSSS.
Date stamps are in the UTC time zone
Parameters: date - milliseconds since epoc the date stamp |
getDate | public static Date getDate(String d) throws ParseException(Code) | | Parses an ARC-style date. If passed String is < 12 characters in length,
we pad. At a minimum, String should contain a year (>=4 characters).
Parse will also fail if day or month are incompletely specified. Depends
on the above getXXDigitDate methods.
Parameters: A - 4-17 digit date in ARC style (yyyy toyyyyMMddHHmmssSSS ) formatting. A Date object representing the passed String. throws: ParseException - |
getLog14Date | public static String getLog14Date()(Code) | | Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC. Use current time.
Format is yyyy-MM-dd'T'HH:mm:ss'Z'
the date stamp |
getLog14Date | public static String getLog14Date(long date)(Code) | | Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
Format is yyyy-MM-dd'T'HH:mm:ss'Z'
Parameters: date - long timestamp to format. the date stamp |
getLog14Date | public static String getLog14Date(Date date)(Code) | | Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
Format is yyyy-MM-dd'T'HH:mm:ss'Z'
Parameters: date - Date to format. the date stamp |
getLog17Date | public static String getLog17Date()(Code) | | Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC. Use current time.
Format is yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
the date stamp |
getLog17Date | public static String getLog17Date(long date)(Code) | | Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
Format is yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
Parameters: date - Date to format. the date stamp |
longIntoByteArray | public static void longIntoByteArray(long l, byte[] array, int offset)(Code) | | Copy the raw bytes of a long into a byte array, starting at
the specified offset.
Parameters: l - Parameters: array - Parameters: offset - |
padTo | public static String padTo(int i, int pad)(Code) | | Convert an int to a String , and pad it to
pad spaces.
Parameters: i - the int Parameters: pad - the width to pad to. String w/ padding. |
padTo | public static String padTo(String s, int pad)(Code) | | Pad the given String to pad characters wide
by pre-pending spaces. s should not be null .
If s is already wider than pad no change is
done.
Parameters: s - the String to pad Parameters: pad - the width to pad to. String w/ padding. |
padTo | public static String padTo(String s, int pad, char padChar)(Code) | | Pad the given String to pad characters wide
by pre-pending padChar .
s should not be null . If s is
already wider than pad no change is done.
Parameters: s - the String to pad Parameters: pad - the width to pad to. Parameters: padChar - The pad character to use. String w/ padding. |
parse12DigitDate | public static Date parse12DigitDate(String date) throws ParseException(Code) | | Utility function for parsing arc-style date stamps
in the format yyyMMddHHmm.
Date stamps are in the UTC time zone. The whole string will not be
parsed, only the first 12 digits.
Parameters: date - an arc-style formatted date stamp the Date corresponding to the date stamp string throws: ParseException - if the inputstring was malformed |
parse14DigitDate | public static Date parse14DigitDate(String date) throws ParseException(Code) | | Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmss.
Date stamps are in the UTC time zone. The whole string will not be
parsed, only the first 14 digits.
Parameters: date - an arc-style formatted date stamp the Date corresponding to the date stamp string throws: ParseException - if the inputstring was malformed |
parse17DigitDate | public static Date parse17DigitDate(String date) throws ParseException(Code) | | Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmssSSS.
Date stamps are in the UTC time zone. The whole string will not be
parsed, only the first 17 digits.
Parameters: date - an arc-style formatted date stamp the Date corresponding to the date stamp string throws: ParseException - if the inputstring was malformed |
secondsSinceEpoch | public static String secondsSinceEpoch(String timestamp) throws ParseException(Code) | | Parameters: timestamp - A 14-digit timestamp or the suffix for a 14-digittimestamp: E.g. '20010909014640' or '20010101' or '1970'. Seconds since the epoch as a string zero-pre-padded so alwaysInteger.MAX_VALUE wide (Makes it so sorting of resultant string worksproperly). throws: ParseException - |
singleLineReport | public static String singleLineReport(Reporter rep)(Code) | | Utility method to get a String singleLineReport from Reporter
Parameters: rep - Reporter to get singleLineReport from String of report |
startsWith | public static boolean startsWith(byte[] array, byte[] prefix)(Code) | | Verify that the array begins with the prefix.
Parameters: array - Parameters: prefix - true if array is identical to prefix for the first prefix.lengthpositions |
timestamp17ToCalendar | public static Calendar timestamp17ToCalendar(String timestamp17String)(Code) | | Convert 17-digit date format timestamps (as found in crawl.log, for
example) into a GregorianCalendar object. + * Useful so you can convert
into milliseconds-since-epoch. Note: it is possible to compute
milliseconds-since-epoch + * using
ArchiveUtils.parse17DigitDate .UTC(), but
that method is deprecated in favor of using Calendar.getTimeInMillis(). + *
I probably should have dug into all the utility methods in
DateFormat.java to parse the timestamp, but this was + * easier. If
someone wants to fix this to use those methods, please have at it!
Mike Schwartz, schwartz at CodeOnTheRoad dot com.
Parameters: timestamp17String - Calendar set to timestamp17String . |
writeReportToString | public static String writeReportToString(Reporter rep, String name)(Code) | | Compose the requested report into a String. DANGEROUS IF REPORT
CAN BE LARGE.
Parameters: rep - Reported Parameters: name - String name of report to compose String of report |
zeroPadInteger | public static String zeroPadInteger(int i)(Code) | | Parameters: i - Integer to add prefix of zeros too. If passed2005, will return the String 0000002005 . Stringwidth is the width of Integer.MAX_VALUE as a string (10digits). Padded String version of i . |
|
|