edu.vt.middleware.crypt.util
Class Convert

java.lang.Object
  extended by edu.vt.middleware.crypt.util.Convert

public final class Convert
extends Object

Utility class provides static methods to perform common conversions.

Version:
$Revision: 3 $
Author:
Middleware Services

Field Summary
static Charset ASCII_CHARSET
          ASCII character set used for all encoding methods.
static String CHARSET_PROPERTY
          System property used to specify character set.
static Charset DEFAULT_CHARSET
          Default character set.
 
Method Summary
static byte[] fromBase64(String base64)
          Converts base64-encoded string of bytes into the original byte array.
static byte[] fromHex(String hex)
          Converts hexadecimal string of bytes into the original byte array.
static Charset getDefaultCharset()
          Gets the default charset used for character/byte conversions.
static byte[] toAsciiBytes(String input)
          Converts a string to bytes in the ASCII character set.
static String toBase64(byte[] input)
          Converts a byte array into a base-64 encoded string without any line breaks.
static byte[] toBytes(char[] input)
          Converts a character array to a byte array in the default character set.
static byte[] toBytes(String input)
          Converts a string to bytes in the default character set.
static byte[] toBytes(String[] input)
          Convers an array of strings into a byte array produced by concatenating the byte representation of each string in the default character set.
static String toHex(byte[] input)
          Converts a byte array into a hexadecimal string representation of the bytes.
static String toString(byte[] input)
          Converts a byte array to a string in the default encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARSET_PROPERTY

public static final String CHARSET_PROPERTY
System property used to specify character set.

See Also:
Constant Field Values

ASCII_CHARSET

public static final Charset ASCII_CHARSET
ASCII character set used for all encoding methods.


DEFAULT_CHARSET

public static final Charset DEFAULT_CHARSET
Default character set.

Method Detail

getDefaultCharset

public static Charset getDefaultCharset()
Gets the default charset used for character/byte conversions. If the edu.vt.middleware.crypt.charset system property is specified, attempts to get the named character set, otherwise returns DEFAULT_CHARSET.

Returns:
Default character set.

toBytes

public static byte[] toBytes(String[] input)
Convers an array of strings into a byte array produced by concatenating the byte representation of each string in the default character set.

Parameters:
input - String to convert
Returns:
String characters as bytes.

toBytes

public static byte[] toBytes(String input)
Converts a string to bytes in the default character set.

Parameters:
input - String to convert.
Returns:
String characters as bytes.

toBytes

public static byte[] toBytes(char[] input)
Converts a character array to a byte array in the default character set.

Parameters:
input - Character array to convert.
Returns:
Characters as bytes in the default charset.

toAsciiBytes

public static byte[] toAsciiBytes(String input)
Converts a string to bytes in the ASCII character set.

Parameters:
input - String to convert.
Returns:
Byte array of ASCII characters.

toString

public static String toString(byte[] input)
Converts a byte array to a string in the default encoding.

Parameters:
input - Byte array to convert.
Returns:
String representation of bytes.

fromHex

public static byte[] fromHex(String hex)
Converts hexadecimal string of bytes into the original byte array.

Parameters:
hex - Hexadecimal string of bytes.
Returns:
Original byte array.

toHex

public static String toHex(byte[] input)
Converts a byte array into a hexadecimal string representation of the bytes.

Parameters:
input - Byte array to convert
Returns:
String of hexadecimal characters, two for each byte in input array.

fromBase64

public static byte[] fromBase64(String base64)
Converts base64-encoded string of bytes into the original byte array.

Parameters:
base64 - Base64-encoded string of bytes.
Returns:
Original byte array.

toBase64

public static String toBase64(byte[] input)
Converts a byte array into a base-64 encoded string without any line breaks.

Parameters:
input - Byte array to convert.
Returns:
Base-64 encoded string of input bytes.


Copyright © 2003-2011 Virginia Tech. All Rights Reserved.