public class CharConverter
extends java.lang.Object
implements java.io.Serializable
Note: Some methods of this class accept an array-valued argument in addition to arguments that specify an array offset and possibly also a length.
All such methods will throw an ArrayIndexOutOfBoundsException
if the offset and/or length are not valid for the array.
AS400Text
,
Serialized FormConstructor and Description |
---|
CharConverter()
Constructs a CharConverter object using a "best guess" based on the default Locale.
|
CharConverter(int ccsid)
Constructs a CharConverter object using the specified CCSID.
|
CharConverter(int ccsid,
AS400 system)
Constructs a CharConverter object using the specified CCSID and system.
|
CharConverter(java.lang.String encoding)
Constructs a CharConverter object using the specified character encoding.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
byteArrayToString(AS400 system,
byte[] source)
Converts the specified bytes into a String.
|
java.lang.String |
byteArrayToString(byte[] source)
Converts the specified bytes into a String.
|
java.lang.String |
byteArrayToString(byte[] source,
int offset)
Converts the specified bytes into a String.
|
java.lang.String |
byteArrayToString(byte[] source,
int offset,
int length)
Converts the specified bytes into a String.
|
java.lang.String |
byteArrayToString(byte[] source,
int offset,
int length,
BidiConversionProperties properties)
Converts the specified bytes into a String.
|
java.lang.String |
byteArrayToString(byte[] source,
int offset,
int length,
int type)
Converts the specified bytes into a String.
|
static java.lang.String |
byteArrayToString(int ccsid,
AS400 system,
byte[] source)
Converts the specified bytes into a String.
|
static java.lang.String |
byteArrayToString(int ccsid,
byte[] source)
Converts the specified bytes into a String.
|
static java.lang.String |
convertIFSQSYSPathnameToJobPathname(java.lang.String qsysData,
int jobCCSID)
Converts a QSYS pathname String obtained from the IFS classes into a String suitable for use with other Toolbox services such as CommandCall and DataQueues.
|
static java.lang.String |
convertJobPathnameToIFSQSYSPathname(java.lang.String jobData,
int jobCCSID)
Converts a pathname String obtained from a Toolbox host server (such as CommandCall or DataQueue) to a QSYS pathname suitable for use with the IFS classes.
|
int |
getCcsid()
Returns the CCSID of this conversion object.
|
java.lang.String |
getEncoding()
Returns the encoding of this conversion object.
|
static boolean |
isFaultTolerantConversion()
Indicates if conversion is fault tolerant.
|
static void |
setFaultTolerantConversion(boolean faultTolerantConversion)
Enables fault tolerant conversion.
|
static byte[] |
stringToByteArray(AS400 system,
java.lang.String source)
Converts the specified String into bytes.
|
static byte[] |
stringToByteArray(int ccsid,
AS400 system,
java.lang.String source)
Converts the specified String into bytes.
|
static byte[] |
stringToByteArray(int ccsid,
java.lang.String source)
Converts the specified String into bytes.
|
byte[] |
stringToByteArray(java.lang.String source)
Converts the specified String into bytes.
|
byte[] |
stringToByteArray(java.lang.String source,
BidiConversionProperties properties)
Converts the specified String into bytes.
|
void |
stringToByteArray(java.lang.String source,
byte[] destination)
Converts the specified String into bytes.
|
void |
stringToByteArray(java.lang.String source,
byte[] destination,
int offset)
Converts the specified String into bytes.
|
void |
stringToByteArray(java.lang.String source,
byte[] destination,
int offset,
int length)
Converts the specified String into bytes.
|
void |
stringToByteArray(java.lang.String source,
byte[] destination,
int offset,
int length,
BidiConversionProperties properties)
Converts the specified String into bytes.
|
void |
stringToByteArray(java.lang.String source,
byte[] destination,
int offset,
int length,
int type)
Converts the specified String into bytes.
|
byte[] |
stringToByteArray(java.lang.String source,
int type)
Converts the specified String into bytes.
|
public CharConverter()
public CharConverter(java.lang.String encoding) throws java.io.UnsupportedEncodingException
encoding
- The name of a character encoding.java.io.UnsupportedEncodingException
- If the encoding is not supported.public CharConverter(int ccsid) throws java.io.UnsupportedEncodingException
ccsid
- The CCSID of the IBM i text.java.io.UnsupportedEncodingException
- If the ccsid is not supported.public CharConverter(int ccsid, AS400 system) throws java.io.UnsupportedEncodingException
ccsid
- The CCSID of the IBM i text.system
- The system object representing the system with which to connect.
If null, then this constructor behaves identically to CharConverter(ccsid).java.io.UnsupportedEncodingException
- If the ccsid is not supported.public java.lang.String byteArrayToString(byte[] source)
source
- The bytes to convert.public java.lang.String byteArrayToString(byte[] source, int offset)
source
- The bytes to convert.offset
- The offset into the source array for the start of the data.public java.lang.String byteArrayToString(byte[] source, int offset, int length)
source
- The bytes to convert.offset
- The offset into the source array for the start of the data.length
- The number of bytes of data to read from the array.public java.lang.String byteArrayToString(byte[] source, int offset, int length, int type)
source
- The bytes to convert.offset
- The offset into the source array for the start of the data.length
- The number of bytes of data to read from the array.type
- The bidi string type, as defined by the CDRA (Character Data Representation Architecture). See BidiStringType for more information and valid values.BidiStringType
public java.lang.String byteArrayToString(byte[] source, int offset, int length, BidiConversionProperties properties)
source
- The bytes to convert.offset
- The offset into the source array for the start of the data.length
- The number of bytes of data to read from the array.properties
- The bidi conversion properties.public static java.lang.String byteArrayToString(AS400 system, byte[] source)
system
- The system object representing the system with which to connect.source
- The bytes to convert.public static java.lang.String byteArrayToString(int ccsid, AS400 system, byte[] source) throws java.io.UnsupportedEncodingException
ccsid
- The CCSID of the IBM i text.system
- The system object representing the system with which to connect.source
- The bytes to convert.java.io.UnsupportedEncodingException
- If the ccsid is not supported.public static java.lang.String byteArrayToString(int ccsid, byte[] source) throws java.io.UnsupportedEncodingException
ccsid
- The CCSID of the IBM i text.source
- The bytes to convert.java.io.UnsupportedEncodingException
- If the ccsid is not supported.public static java.lang.String convertIFSQSYSPathnameToJobPathname(java.lang.String qsysData, int jobCCSID) throws java.io.UnsupportedEncodingException
This method is meant to handle QSYS pathnames and other string data that was retrieved using the IFS classes. Object names in QSYS are stored in EBCDIC. The file server always returns names to the Toolbox IFS classes in Unicode, so the system must convert the name from EBCDIC to Unicode before returning it to the client. The system does this conversion using CCSID 37, not the file server job CCSID; however, the name may contain variant (but legal) codepoints. Specifically, the three legal variant EBCDIC codepoints for QSYS object names are 0x5B, 0x7B, and 0x7C. If the name retrieved using the Toolbox IFS classes is given to another Toolbox component such as CommandCall, the name will be converted to EBCDIC using the job CCSID for that particular component. If variant characters exist in the name, the resulting name used by the host server job may not be the same as the original name.
Here is a typical scenario in which this method will be needed. The user profile name CASH$FLOW exists on the system. In EBCDIC CCSID 37, it is comprised of the codepoints:
0xC3 0xC1 0xE2 0xC8 0x5B 0xC6 0xD3 0xD6 0xE6Note that the dollar sign '$' is codepoint 0x5B so it is one of the legal codepoints for a QSYS object pathname. Now, if this pathname is used in a CommandCall, such as "DLTUSRPRF CASH$FLOW", that command string will get converted to the CCSID of the host server job. If the host server job isn't running under CCSID 37, the resulting command string may not contain the dollar sign. For example, in CCSID 285 (United Kingdom) the codepoint 0x5B is actually an English pound sterling ('£' or Unicode 0x00A3). The dollar sign '$' is found at codepoint 0x4A instead. Hence, the "CASH$FLOW" in the command string will get converted to the following EBCDIC CCSID 285 codepoints:
0xC3 0xC1 0xE2 0xC8 0x4A 0xC6 0xD3 0xD6 0xE6That is not how the user profile name is stored in QSYS. The 0x4A codepoint should really be a 0x5B codepoint. So in this case, the command server will return an error message indicating the user profile was not found.
The solution is to use this method to replace the variant codepoints with codepoints that will correctly convert given the host server job CCSID. When given the string "CASH$FLOW" and the CCSID 285, this method will return the string "CASH£FLOW". If the CommandCall is issued with the string "DLTUSRPRF CASH£FLOW" and the job CCSID of the remote command host server is 285, it will correctly convert the pound sterling '£' into codepoint 0x5B, which is how the user profile name "CASH$FLOW" is actually stored in QSYS.
Note: This method is intended for use only with QSYS object pathnames; that is, pathnames containing "/QSYS.LIB/".
For more information, please see IBM i Information Center: CL and APIs: Control Language (CL): Naming within commands.
qsysData
- The String in which to substitute variant QSYS characters.jobCCSID
- The CCSID of the job in which to convert the variant characters.java.io.UnsupportedEncodingException
- If the specified CCSID is not supported.convertJobPathnameToIFSQSYSPathname(java.lang.String, int)
public static java.lang.String convertJobPathnameToIFSQSYSPathname(java.lang.String jobData, int jobCCSID) throws java.io.UnsupportedEncodingException
See the javadoc for convertIFSQSYSPathnameToJobPathname
for more information. This method essentially does the opposite of what convertIFSQSYSPathnameToJobPathname does. The specified jobData string has its variant characters substituted so that it can be used with the IFS classes. If given the String returned by this method, the file server will correctly convert the codepoints into the real QSYS object pathname using CCSID 37.
Note: This method is intended for use only with QSYS object pathnames; that is, pathnames containing "/QSYS.LIB/".
jobData
- The String in which to substitute variant QSYS characters.jobCCSID
- The CCSID of the job in which to convert the variant characters.java.io.UnsupportedEncodingException
- If the specified CCSID is not supported.convertIFSQSYSPathnameToJobPathname(java.lang.String, int)
public int getCcsid()
public java.lang.String getEncoding()
public static boolean isFaultTolerantConversion()
public static void setFaultTolerantConversion(boolean faultTolerantConversion)
faultTolerantConversion
- true to enable fault tolerant conversion, false otherwise.public byte[] stringToByteArray(java.lang.String source)
source
- The String to convert.public byte[] stringToByteArray(java.lang.String source, int type)
source
- The String to convert.type
- The bidi string type, as defined by the CDRA (Character Data Representation Architecture). See BidiStringType for more information and valid values.BidiStringType
public byte[] stringToByteArray(java.lang.String source, BidiConversionProperties properties)
source
- The String to convert.properties
- The bidi conversion properties.public void stringToByteArray(java.lang.String source, byte[] destination) throws java.io.CharConversionException
source
- The String to convert.destination
- The destination byte array.java.io.CharConversionException
- If destination is not large enough to hold the converted string.public void stringToByteArray(java.lang.String source, byte[] destination, int offset) throws java.io.CharConversionException
source
- The String to convert.destination
- The destination byte array.offset
- The offset into the destination array for the start of the data.java.io.CharConversionException
- If destination is not large enough to hold the converted string.public void stringToByteArray(java.lang.String source, byte[] destination, int offset, int length) throws java.io.CharConversionException
source
- The String to convert.destination
- The destination byte array.offset
- The offset into the destination array for the start of the data.length
- The number of bytes of data to write into the array.java.io.CharConversionException
- If destination is not large enough to hold the converted string.public void stringToByteArray(java.lang.String source, byte[] destination, int offset, int length, int type) throws java.io.CharConversionException
source
- The String to convert.destination
- The destination byte array.offset
- The offset into the destination array for the start of the data.length
- The number of bytes of data to write into the array.type
- The bidi string type, as defined by the CDRA (Character Data Representation Architecture). See BidiStringType for more information and valid values.java.io.CharConversionException
- If destination is not large enough to hold the converted string.BidiStringType
public void stringToByteArray(java.lang.String source, byte[] destination, int offset, int length, BidiConversionProperties properties) throws java.io.CharConversionException
source
- The String to convert.destination
- The destination byte array.offset
- The offset into the destination array for the start of the data.length
- The number of bytes of data to write into the array.properties
- The bidi conversion properties.java.io.CharConversionException
- If destination is not large enough to hold the converted string.BidiStringType
public static byte[] stringToByteArray(AS400 system, java.lang.String source)
system
- The system object representing the system with which to connect.source
- The String to convert.public static byte[] stringToByteArray(int ccsid, AS400 system, java.lang.String source) throws java.io.UnsupportedEncodingException
ccsid
- The CCSID of the IBM i text.system
- The system object representing the system with which to connect.source
- The String to convert.java.io.UnsupportedEncodingException
- If the ccsid is not supported.public static byte[] stringToByteArray(int ccsid, java.lang.String source) throws java.io.UnsupportedEncodingException
ccsid
- The CCSID of the IBM i text.source
- The String to convert.java.io.UnsupportedEncodingException
- If the ccsid is not supported.