All Packages Class Hierarchy This Package Previous Next Index
Class cryptix.mime.LegacyString
java.lang.Object
|
+----cryptix.mime.LegacyString
- public class LegacyString
- extends Object
This class contains static functions useful in converting between
Strings and byte arrays. The name of this class is to remind you that
there are better ways of performing such conversions these days -
Java 1.1 supplies its own byte-to-char converters, and the Reader and
Writer classes take care of most of the more finicky details in a much
better way than is done here. Nonetheless, this class exists in order
to maintain backwards compatibility with entities which were written
before the advent of Java and Unicode.
Note that class contains only static functions, and has no public
constructor.
Copyright © 1995-1997
Systemics Ltd on behalf of the
Cryptix Development Team.
All rights reserved.
$Revision: 1.2 $
- Author:
- Jill Baker, David Hopwood
-
toByteArray(String)
- Equivalent to
toByteArray(s, 0, s.length())
.
-
toByteArray(String, int, int)
- Converts a String to an ISO-Latin-1 encoded byte array.
-
toByteArrayLossless(String)
- This method is similar to
toByteArray(s)
,
but throws an IllegalArgumentException if any of the
characters in s are outside the range \u0000 to \u00FF.
-
toByteArrayLossless(String, int, int)
- This method is similar to
toByteArray(s, offset, length)
,
but throws an IllegalArgumentException if any of the
characters in s are outside the range \u0000 to \u00FF.
-
toString(byte[])
- Equivalent to
toString(b, 0, b.length)
.
-
toString(byte[], int, int)
- Converts an ISO-Latin-1 encoded byte array to a String.
toByteArray
public static byte[] toByteArray(String s,
int offset,
int length)
- Converts a String to an ISO-Latin-1 encoded byte array.
This conversion function is neccessary because Java 1.1+ uses
machine dependent char-to-byte and byte-to-char conversions. This
is normally a useful feature, allowing machine independence.
In order to maintain backwards compatibility with pre-Java
conventions, we implement our own machine-independent
deterministic converter.
- Parameters:
- s - the string to be converted to bytes.
- offset - the character offset within the string to start at.
- length - the number of characters to be converted.
- Returns:
- an array of bytes containing the lower 8 bits of each char.
toByteArray
public static byte[] toByteArray(String s)
- Equivalent to
toByteArray(s, 0, s.length())
.
toByteArrayLossless
public static byte[] toByteArrayLossless(String s,
int offset,
int length)
- This method is similar to
toByteArray(s, offset, length)
,
but throws an IllegalArgumentException if any of the
characters in s are outside the range \u0000 to \u00FF.
- Parameters:
- s - the string to be converted to bytes.
- offset - the character offset within the string to start at.
- length - the number of characters to be converted.
- Returns:
- an array of bytes containing the lower 8 bits of each char.
- Throws: IllegalArgumentException
- if any of the characters in s are out of range.
toByteArrayLossless
public static byte[] toByteArrayLossless(String s)
- This method is similar to
toByteArray(s)
,
but throws an IllegalArgumentException if any of the
characters in s are outside the range \u0000 to \u00FF.
- Parameters:
- s - the string to be converted to bytes.
- Returns:
- an array of bytes containing the lower 8 bits of each char.
- Throws: IllegalArgumentException
- if any of the characters in s are out of range.
toString
public static String toString(byte b[],
int offset,
int length)
- Converts an ISO-Latin-1 encoded byte array to a String.
This conversion function is neccessary because Java 1.1+ uses
machine dependent char-to-byte and byte-to-char conversions. This
is normally a useful feature, allowing machine independence.
In order to maintain backwards compatibility with pre-Java
conventions, we implement our own machine-independent
deterministic converter.
- Parameters:
- b - an array of bytes to be converted to a String.
- offset - the character offset within the string to start at.
- length - the number of characters to be converted.
- Returns:
- a String containing the bytes. Each char in the string
will be in the range \u0000 to \u00FF.
toString
public static String toString(byte b[])
- Equivalent to
toString(b, 0, b.length)
.
All Packages Class Hierarchy This Package Previous Next Index