Class ISO646BCDStringCodec<T>
- java.lang.Object
-
- com.opencloud.slee.resources.in.datatypes.ISO646BCDStringCodec<T>
-
- All Implemented Interfaces:
StringCodec<T>,Serializable
public final class ISO646BCDStringCodec<T> extends Object implements StringCodec<T>
Implements a StringCodec for the case of printable ASCII/ISO646-US characters encoded by subtracting 32 and encoding the result as BCD in semi-octets.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringdecodeString(byte[] encoded)Decodes a String of characters from a byte array, taking digits from all semi-octets left-to-right in pairs, expecting only values [0,95], adding 32, and converting to the printable ASCII/ISO646-US character of that code.StringdecodeString(byte[] encoded, StringIndicators indicators)Decodes a String of characters from a byte array, taking digits from all semi-octets left-to-right in pairs, expecting only values [0,95], adding 32, and converting to the printable ASCII/ISO646-US character of that code.byte[]encodeString(String string)Encodes a String of characters to a byte array, accepting only printable ASCII/ISO646-US characters, and encoding each character in an octet by taking its ASCII code, subtracting 32, and encoding each of the resulting two decimal digits in a semi-octet, with the semi-octets written left-to-right.byte[]encodeString(String string, StringIndicators indicators)Encodes a String of characters to a byte array, accepting only printable ASCII/ISO646-US characters, and encoding each character in an octet by taking its ASCII code, subtracting 32, and encoding each of the resulting two decimal digits in a semi-octet, with the semi-octets written left-to-right.ISO646BCDStringCodec<T>getLaxDecoder()Gets an ISO646BCDStringCodec like the standard one except that decoding invalid characters produces ? characters instead of throwing an exception.static <T> ISO646BCDStringCodec<T>getStandardCodec()Gets the standard ISO646BCDStringCodec.
-
-
-
Method Detail
-
getStandardCodec
public static <T> ISO646BCDStringCodec<T> getStandardCodec()
Gets the standard ISO646BCDStringCodec.- Returns:
- ISO646BCDStringCodec
-
getLaxDecoder
public ISO646BCDStringCodec<T> getLaxDecoder()
Gets an ISO646BCDStringCodec like the standard one except that decoding invalid characters produces ? characters instead of throwing an exception. The lax decoder of a lax decoder is itself (idempotent).- Specified by:
getLaxDecoderin interfaceStringCodec<T>- Returns:
- StringCodec
-
encodeString
public byte[] encodeString(String string, StringIndicators indicators)
Encodes a String of characters to a byte array, accepting only printable ASCII/ISO646-US characters, and encoding each character in an octet by taking its ASCII code, subtracting 32, and encoding each of the resulting two decimal digits in a semi-octet, with the semi-octets written left-to-right. Sets indicators to assist decoding by other StringCodecs.- Specified by:
encodeStringin interfaceStringCodec<T>- Parameters:
string- the String to be encoded to a byte arrayindicators- the StringIndicators object in which to set the indicators- Returns:
- the encoded byte array
- Throws:
UnsupportedDigitException- if a non-printable-ASCII character is found
-
encodeString
public byte[] encodeString(String string)
Encodes a String of characters to a byte array, accepting only printable ASCII/ISO646-US characters, and encoding each character in an octet by taking its ASCII code, subtracting 32, and encoding each of the resulting two decimal digits in a semi-octet, with the semi-octets written left-to-right.- Specified by:
encodeStringin interfaceStringCodec<T>- Parameters:
string- the String to be encoded to a byte array- Returns:
- the encoded byte array
- Throws:
UnsupportedDigitException- if a non-printable-ASCII character is found
-
decodeString
public String decodeString(byte[] encoded, StringIndicators indicators)
Decodes a String of characters from a byte array, taking digits from all semi-octets left-to-right in pairs, expecting only values [0,95], adding 32, and converting to the printable ASCII/ISO646-US character of that code. If a value outside the range [0,95] is found, the standard decoder throws UnsupportedDigitException, while the lax decoder decodes a ? character.- Specified by:
decodeStringin interfaceStringCodec<T>- Parameters:
encoded- the byte array to be decoded to a Stringindicators- indicators indicator values needed for decoding (ignored)- Returns:
- the decoded String
- Throws:
UnsupportedDigitException- if any encoded content is not in range [0,127]
-
decodeString
public String decodeString(byte[] encoded)
Decodes a String of characters from a byte array, taking digits from all semi-octets left-to-right in pairs, expecting only values [0,95], adding 32, and converting to the printable ASCII/ISO646-US character of that code. If a value outside the range [0,95] is found, the standard decoder throws UnsupportedDigitException, while the lax decoder decodes a ? character.- Specified by:
decodeStringin interfaceStringCodec<T>- Parameters:
encoded- the byte array to be decoded to a String- Returns:
- the decoded String
- Throws:
UnsupportedDigitException- if any encoded content is not in range [0,127]
-
-