public class ArchiveUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
GZIP_SUFFIX
suffix to recognize gzipped files
|
protected static java.lang.String |
LAST_TIMESTAMP14 |
protected static java.lang.String |
LAST_TIMESTAMP17 |
protected static long |
LAST_UNIQUE_NOW14 |
protected static long |
LAST_UNIQUE_NOW17 |
static int |
MAX_INT_CHAR_WIDTH |
static java.util.Set<java.lang.String> |
TLDS |
static java.lang.String |
VERSION |
| Constructor and Description |
|---|
ArchiveUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
addImpliedHttpIfNecessary(java.lang.String u)
Given a string that may be a plain host or host/path (without
URI scheme), add an implied http:// if necessary.
|
static boolean |
byteArrayEquals(byte[] lhs,
byte[] rhs)
check that two byte arrays are equal.
|
static long |
byteArrayIntoLong(byte[] bytearray) |
static long |
byteArrayIntoLong(byte[] bytearray,
int offset)
Byte array into long.
|
static void |
closeQuietly(java.lang.Object input) |
static void |
continueCheck()
Perform checks as to whether normal execution should proceed.
|
static java.lang.String |
dateToTimestamp(java.lang.String input)
Convert a user-entered date into a timestamp
|
static java.lang.String |
doubleToString(double val,
int maxFractionDigits)
Converts a double to a string.
|
static java.lang.String |
doubleToString(double val,
int maxFractionDigits,
int minFractionDigits) |
static java.lang.String |
formatBytesForDisplay(long amount)
Takes a byte size and formats it for display with 'friendly' units.
|
static java.lang.String |
formatMillisecondsToConventional(long time)
Convert milliseconds value to a human-readable duration
|
static java.lang.String |
formatMillisecondsToConventional(long duration,
int unitCount)
Convert milliseconds value to a human-readable duration of
mixed units, using units no larger than days.
|
static java.lang.String |
get12DigitDate()
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmm.
|
static java.lang.String |
get12DigitDate(java.util.Date d) |
static java.lang.String |
get12DigitDate(long date)
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmm.
|
static java.lang.String |
get14DigitDate()
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmss.
|
static java.lang.String |
get14DigitDate(java.util.Date d) |
static java.lang.String |
get14DigitDate(long date)
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmss.
|
static java.lang.String |
get17DigitDate()
Utility function for creating arc-style date stamps
in the format yyyMMddHHmmssSSS.
|
static java.lang.String |
get17DigitDate(java.util.Date date) |
static java.lang.String |
get17DigitDate(long date)
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmssSSS.
|
static java.io.BufferedReader |
getBufferedReader(java.io.File source)
Get a BufferedReader on the crawler journal given
TODO: move to a general utils class
|
static java.io.BufferedReader |
getBufferedReader(java.net.URL source)
Get a BufferedReader on the crawler journal given.
|
static java.util.Date |
getDate(java.lang.String d)
Parses an ARC-style date.
|
static java.util.Date |
getDate(java.lang.String d,
java.util.Date defaultDate)
A version of getDate which returns the default instead of throwing an exception if parsing fails
|
static java.lang.String |
getLog14Date()
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static java.lang.String |
getLog14Date(java.util.Date date)
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static java.lang.String |
getLog14Date(long date)
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static java.lang.String |
getLog17Date()
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static java.lang.String |
getLog17Date(long date)
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static java.util.Date |
getSecondsSinceEpoch(java.lang.String timestamp) |
static java.lang.String |
getUnique14DigitDate()
Utility function for creating UNIQUE-from-this-class
arc-style date stamps in the format yyyMMddHHmmss.
|
static java.lang.String |
getUnique17DigitDate()
Utility function for creating UNIQUE-from-this-class
arc-style date stamps in the format yyyMMddHHmmssSSS.
|
static byte[] |
gzip(byte[] bytes)
Gzip passed bytes.
|
static boolean |
isGzipped(java.io.InputStream is)
Tests passed stream is gzip stream by reading in the HEAD.
|
static boolean |
isTld(java.lang.String dom)
Return whether the given string represents a known
top-level-domain (like "com", "org", etc.) per IANA
as of 20100419
|
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.
|
static java.lang.String |
padTo(int i,
int pad)
Convert an
int to a String, and pad it to
pad spaces. |
static java.lang.String |
padTo(java.lang.String s,
int pad)
Pad the given
String to pad characters wide
by pre-pending spaces. |
static java.lang.String |
padTo(java.lang.String s,
int pad,
char padChar)
Pad the given
String to pad characters wide
by pre-pending padChar. |
static java.util.Date |
parse12DigitDate(java.lang.String date)
Utility function for parsing arc-style date stamps
in the format yyyMMddHHmm.
|
static java.util.Date |
parse14DigitDate(java.lang.String date)
Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmss.
|
static java.util.Date |
parse14DigitISODate(java.lang.String datetime,
java.util.Date defaultVal) |
static java.util.Date |
parse17DigitDate(java.lang.String date)
Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmssSSS.
|
static java.lang.String |
prettyString(java.util.Map<?,?> map)
Provide a improved String of a Map's entries
|
static java.lang.String |
prettyString(java.lang.Object obj)
Enhance given object's default String display for appearing
nested in a pretty Map String.
|
static java.lang.String |
prettyString(java.lang.Object[] array)
Provide a slightly-improved String of Object[]
|
static int |
readFully(java.io.InputStream input,
byte[] buf)
Read stream into buf until EOF or buf full.
|
static java.lang.String |
secondsSinceEpoch(java.lang.String timestamp) |
static boolean |
startsWith(byte[] array,
byte[] prefix)
Verify that the array begins with the prefix.
|
static java.lang.String |
zeroPadInteger(int i) |
public static final java.lang.String VERSION
public static int MAX_INT_CHAR_WIDTH
protected static long LAST_UNIQUE_NOW17
protected static java.lang.String LAST_TIMESTAMP17
protected static long LAST_UNIQUE_NOW14
protected static java.lang.String LAST_TIMESTAMP14
public static java.util.Set<java.lang.String> TLDS
public static final java.lang.String GZIP_SUFFIX
public static java.lang.String get17DigitDate()
public static java.lang.String getUnique17DigitDate()
public static java.lang.String get14DigitDate()
public static java.lang.String getUnique14DigitDate()
public static java.lang.String get12DigitDate()
public static java.lang.String getLog17Date()
public static java.lang.String getLog17Date(long date)
date - Date to format.public static java.lang.String getLog14Date()
public static java.lang.String getLog14Date(long date)
date - long timestamp to format.public static java.lang.String getLog14Date(java.util.Date date)
date - Date to format.public static java.util.Date parse14DigitISODate(java.lang.String datetime,
java.util.Date defaultVal)
public static java.lang.String get17DigitDate(long date)
date - milliseconds since epocpublic static java.lang.String get17DigitDate(java.util.Date date)
public static java.lang.String get14DigitDate(long date)
date - milliseconds since epocpublic static java.lang.String get14DigitDate(java.util.Date d)
public static java.lang.String get12DigitDate(long date)
date - milliseconds since epocpublic static java.lang.String get12DigitDate(java.util.Date d)
public static java.util.Date getDate(java.lang.String d,
java.util.Date defaultDate)
d - defaultDate - java.text.ParseExceptionpublic static java.util.Date getDate(java.lang.String d)
throws java.text.ParseException
A - 4-17 digit date in ARC style (yyyy to
yyyyMMddHHmmssSSS) formatting.java.text.ParseExceptionpublic static java.lang.String dateToTimestamp(java.lang.String input)
input - public static java.util.Date parse17DigitDate(java.lang.String date)
throws java.text.ParseException
date - an arc-style formatted date stampjava.text.ParseException - if the inputstring was malformedpublic static java.util.Date parse14DigitDate(java.lang.String date)
throws java.text.ParseException
date - an arc-style formatted date stampjava.text.ParseException - if the inputstring was malformedpublic static java.util.Date parse12DigitDate(java.lang.String date)
throws java.text.ParseException
date - an arc-style formatted date stampjava.text.ParseException - if the inputstring was malformedpublic static java.lang.String secondsSinceEpoch(java.lang.String timestamp)
throws java.text.ParseException
timestamp - A 14-digit timestamp or the suffix for a 14-digit
timestamp: E.g. '20010909014640' or '20010101' or '1970'.java.text.ParseExceptionpublic static java.util.Date getSecondsSinceEpoch(java.lang.String timestamp)
throws java.text.ParseException
timestamp - A 14-digit timestamp or the suffix for a 14-digit
timestamp: E.g. '20010909014640' or '20010101' or '1970'.java.text.ParseExceptionsecondsSinceEpoch(String)public static java.lang.String zeroPadInteger(int i)
i - Integer to add prefix of zeros too. If passed
2005, will return the String 0000002005. String
width is the width of Integer.MAX_VALUE as a string (10
digits).i.public static java.lang.String padTo(int i,
int pad)
int to a String, and pad it to
pad spaces.i - the intpad - the width to pad to.public static java.lang.String padTo(java.lang.String s,
int pad)
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.s - the String to padpad - the width to pad to.public static java.lang.String padTo(java.lang.String s,
int pad,
char padChar)
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.s - the String to padpad - the width to pad to.padChar - The pad character to use.public static boolean byteArrayEquals(byte[] lhs,
byte[] rhs)
null.lhs - a byte arrayrhs - another byte array.true if they are both equal (or both
null)public static java.lang.String doubleToString(double val,
int maxFractionDigits)
val - The double to convertprecision - How many characters to include after '.'public static java.lang.String doubleToString(double val,
int maxFractionDigits,
int minFractionDigits)
public static java.lang.String formatBytesForDisplay(long amount)
This involves converting it to the largest unit (of B, KiB, MiB, GiB, TiB) for which the amount will be > 1.
Additionally, at least 2 significant digits are always displayed.
Negative numbers will be returned as '0 B'.
amount - the amount of bytespublic static java.lang.String formatMillisecondsToConventional(long time)
time - timepublic static java.lang.String formatMillisecondsToConventional(long duration,
int unitCount)
duration - unitCount - how many significant units to show, at most
for example, a value of 2 would show days+hours or hours+seconds
but not hours+second+millisecondstimepublic static void longIntoByteArray(long l,
byte[] array,
int offset)
l - array - offset - public static long byteArrayIntoLong(byte[] bytearray)
public static long byteArrayIntoLong(byte[] bytearray,
int offset)
bytearray - Array to convert to a long.offset - Offset into array at which we start decoding the long.array beginning at
offset offset.longIntoByteArray(long, byte[], int)public static java.lang.String addImpliedHttpIfNecessary(java.lang.String u)
u - string to evaluatepublic static boolean startsWith(byte[] array,
byte[] prefix)
array - prefix - public static java.lang.String prettyString(java.lang.Object obj)
obj - Object to prettifypublic static java.lang.String prettyString(java.util.Map<?,?> map)
Map - public static java.lang.String prettyString(java.lang.Object[] array)
Object[] - public static boolean isTld(java.lang.String dom)
dom - candidate stringpublic static void closeQuietly(java.lang.Object input)
public static void continueCheck()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic static int readFully(java.io.InputStream input,
byte[] buf)
throws java.io.IOException
input - buf - java.io.IOExceptionpublic static java.io.BufferedReader getBufferedReader(java.io.File source)
throws java.io.IOException
source - File journaljava.io.IOExceptionpublic static java.io.BufferedReader getBufferedReader(java.net.URL source)
throws java.io.IOException
source - URL journaljava.io.IOExceptionpublic static byte[] gzip(byte[] bytes)
throws java.io.IOException
bytes - What to gzip.java.io.IOExceptionpublic static boolean isGzipped(java.io.InputStream is)
throws java.io.IOException
is - An InputStream.java.io.IOExceptionCopyright © 2019 The International Internet Preservation Consortium. All Rights Reserved.