cryptix.util.mime
Class ISOLatin1

java.lang.Object
  |
  +--cryptix.util.mime.ISOLatin1

public class ISOLatin1
extends java.lang.Object

This class contains static functions useful in converting between Strings and byte arrays. There are better ways of performing such conversions in Java 1.1, which 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 Java 1.0.2.

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.1.1.1 $

Since:
Cryptix 2.2
Author:
Jill Baker, David Hopwood

Method Summary
static byte[] toByteArray(java.lang.String s)
          Equivalent to toByteArray(s, 0, s.length()).
static byte[] toByteArray(java.lang.String s, int offset, int length)
          Converts a String to an ISO-Latin-1 encoded byte array.
static byte[] toByteArrayLossless(java.lang.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.
static byte[] toByteArrayLossless(java.lang.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.
static java.lang.String toString(byte[] b)
          Equivalent to toString(b, 0, b.length).
static java.lang.String toString(byte[] b, int offset, int length)
          Converts an ISO-Latin-1 encoded byte array to a String.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toByteArray

public static byte[] toByteArray(java.lang.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.
Since:
Cryptix 2.2.2

toByteArray

public static byte[] toByteArray(java.lang.String s)
Equivalent to toByteArray(s, 0, s.length()).

toByteArrayLossless

public static byte[] toByteArrayLossless(java.lang.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:
java.lang.IllegalArgumentException - if any of the characters in s are out of range.
Since:
Cryptix 2.2.2

toByteArrayLossless

public static byte[] toByteArrayLossless(java.lang.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:
java.lang.IllegalArgumentException - if any of the characters in s are out of range.
Since:
Cryptix 2.2.2

toString

public static java.lang.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.
Since:
Cryptix 2.2.2

toString

public static java.lang.String toString(byte[] b)
Equivalent to toString(b, 0, b.length).