org.dspace.core
Class Utils

java.lang.Object
  extended by org.dspace.core.Utils

public class Utils
extends Object

Utility functions for DSpace.

Version:
$Revision: 3762 $
Author:
Peter Breton

Method Summary
static String addEntities(String value)
          Replace characters that could be interpreted as HTML codes with symbolic references (entities).
static void bufferedCopy(InputStream source, OutputStream destination)
          Copy stream-data from source to destination, with buffering.
static void copy(InputStream input, OutputStream output)
          Copy stream-data from source to destination.
static String formatISO8601Date(Date d)
          Convert a Date to String in the ISO 8601 standard format.
static byte[] generateBytesKey()
          Generate a unique key as a byte array.
static String generateHexKey()
          Generate a unique key.
static String generateKey()
          Generate a unique key.
static String getMD5(byte[] data)
          Return an MD5 checksum for data in hex format.
static String getMD5(String data)
          Return an MD5 checksum for data in hex format.
static byte[] getMD5Bytes(byte[] data)
          Return an MD5 checksum for data as a byte array.
static long parseDuration(String duration)
          Utility method to parse durations defined as \d+[smhdwy] (seconds, minutes, hours, days, weeks, years)
static Date parseISO8601Date(String s)
          Translates timestamp from an ISO 8601-standard format, which is commonly used in XML and RDF documents.
static String toHex(byte[] data)
          Return a hex representation of the byte array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMD5

public static String getMD5(String data)
Return an MD5 checksum for data in hex format.

Parameters:
data - The data to checksum.
Returns:
MD5 checksum for the data in hex format.

getMD5

public static String getMD5(byte[] data)
Return an MD5 checksum for data in hex format.

Parameters:
data - The data to checksum.
Returns:
MD5 checksum for the data in hex format.

getMD5Bytes

public static byte[] getMD5Bytes(byte[] data)
Return an MD5 checksum for data as a byte array.

Parameters:
data - The data to checksum.
Returns:
MD5 checksum for the data as a byte array.

toHex

public static String toHex(byte[] data)
Return a hex representation of the byte array

Parameters:
data - The data to transform.
Returns:
A hex representation of the data.

generateKey

public static String generateKey()
Generate a unique key. The key is a long (length 38 to 40) sequence of digits.

Returns:
A unique key as a long sequence of base-10 digits.

generateHexKey

public static String generateHexKey()
Generate a unique key. The key is a 32-character long sequence of hex digits.

Returns:
A unique key as a long sequence of hex digits.

generateBytesKey

public static byte[] generateBytesKey()
Generate a unique key as a byte array.

Returns:
A unique key as a byte array.

copy

public static void copy(InputStream input,
                        OutputStream output)
                 throws IOException
Copy stream-data from source to destination. This method does not buffer, flush or close the streams, as to do so would require making non-portable assumptions about the streams' origin and further use. If you wish to perform a buffered copy, use bufferedCopy(java.io.InputStream, java.io.OutputStream).

Parameters:
input - The InputStream to obtain data from.
output - The OutputStream to copy data to.
Throws:
IOException

bufferedCopy

public static void bufferedCopy(InputStream source,
                                OutputStream destination)
                         throws IOException
Copy stream-data from source to destination, with buffering. This is equivalent to passing copy(java.io.InputStream, java.io.OutputStream)a java.io.BufferedInputStream and java.io.BufferedOuputStream to copy(java.io.InputStream, java.io.OutputStream), and flushing the output stream afterwards. The streams are not closed after the copy.

Parameters:
source - The InputStream to obtain data from.
destination - The OutputStream to copy data to.
Throws:
IOException

addEntities

public static String addEntities(String value)
Replace characters that could be interpreted as HTML codes with symbolic references (entities). This function should be called before displaying any metadata fields that could contain the characters " <", ">", "&", "'", and double quotation marks. This will effectively disable HTML links in metadata.

Parameters:
value - the metadata value to be scrubbed for display
Returns:
the passed-in string, with html special characters replaced with entities.

parseDuration

public static long parseDuration(String duration)
                          throws ParseException
Utility method to parse durations defined as \d+[smhdwy] (seconds, minutes, hours, days, weeks, years)

Parameters:
duration - specified duration
Returns:
number of milliseconds equivalent to duration.
Throws:
ParseException - if the duration is of incorrect format

parseISO8601Date

public static Date parseISO8601Date(String s)
Translates timestamp from an ISO 8601-standard format, which is commonly used in XML and RDF documents. This method is synchronized because it depends on a non-reentrant static DateFormat (more efficient than creating a new one each call).

Parameters:
s - the input string
Returns:
Date object, or null if there is a problem translating.

formatISO8601Date

public static String formatISO8601Date(Date d)
Convert a Date to String in the ISO 8601 standard format. The RFC822 timezone is almost right, still need to insert ":". This method is synchronized because it depends on a non-reentrant static DateFormat (more efficient than creating a new one each call).

Parameters:
d - the input Date
Returns:
String containing formatted date.


Copyright © 2010 DuraSpace. All Rights Reserved.