CSCOwnCodeConverter interface is as follows:
Create the implementation class of following interface, when developing the character code conversion UOC.
Figure I-1 Figurecharacter code conversion UOC class
public class OwnCodeConverter implements CSCOwnCodeConverter
{
public void setProperties(final Properties properties)
throws CSCOwnCodeConverterException;
public char[] ownCodeToUnicode(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
public byte[] unicodeToOwnCode(final char[] inBuffer)
throws CSCOwnCodeConverterException;
public int available(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
}
Method name | Description |
---|---|
setProperties method | This is a method for passing definition contents of self-defined file to the character code conversion UOC. |
ownCodeToUnicode method | This is method for converting the character string of self-defined character code to Unicode. |
unicodeToOwnCode method | This is the method for converting the character string of Unicode(UTF-16) to self-defined character code. |
Available method | This is the method of returning bytes count of character string that can be converted at the time of character code conversion. |
Figure I-2 FigureOrder of invoking each method from character code conversion UOC
public void setProperties(final Properties properties)
throws CSCOwnCodeConverterException;
public char[] ownCodeToUnicode(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
public byte[] unicodeToOwnCode(final char[] inBuffer)
throws CSCOwnCodeConverterException;
public int available(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
Exception class that occurs at the time of developing character code conversion UOC is as follows:
Implementation example of CSCOwnCodeConverter interface is as follows:
public class OwnConvertUoc implements CSCOwnCodeConverter {
// Code conversion option
HJCOption option = null;
// Code conversion result
HJCResult result = null;
// Encode
String encode = null;
// Constructor
public void OwnConvertUoc() {
result = new HJCResult();
option = new HJCOption();
}
// Receive self-defined file in property format of Java
public void setProperties(final Properties properties)
throws CSCOwnCodeConverterException {
if ( properties == null ) {
// self-defined file has not been registered
// self-defined file is executed from the non-defined reception/service adapter
// Since there is a possibility of occurrence, it is not considered as error
encode = "";
return;
}
encode = properties.getProperty("encode");
if ( encode == null ) {
// When key does not exist
String message = "Character code is not specified.";
throw new CSCOwnCodeConverterException(message);
}
}
// Convert the self-defined code to Unicode
public char[] ownCodeToUnicode(final byte[] inBuffer)
throws CSCOwnCodeConverterException {
if ( encode.equals("SJIS") ) {
// Convert from SJIS(MS932) to Unicode
// Use code conversion
HJCString inStr = new HJCString( inBuffer );
try {
HJCConverters.cs_ms932tounicode(inStr, result, option);
} catch ( Exception e ){
throw new CSCOwnCodeConverterException(e);
}
return result.getStrResult().toString().toCharArray();
}
else if ( encode.equals("KEIS") ) {
// Convert from KEIS to Unicode
// Use code conversion
HJCString inStr = new HJCString( inBuffer );
try {
HJCConverters.cs_keistounicode(inStr, result, option);
} catch ( Exception e ){
throw new CSCOwnCodeConverterException(e);
}
return result.getStrResult().toString().toCharArray();
}
else {
// Character code not considered as target
String message = "This is a character code not considered as target.";
throw new CSCOwnCodeConverterException(message);
}
}
// Convert Unicode to self-defined code
public byte[] unicodeToOwnCode(final char[] inBuffer)
throws CSCOwnCodeConverterException {
// (omitted)
}
// Returns the byte count, that can be successfully converted
public int available(final byte[] inBuffer)
throws CSCOwnCodeConverterException {
// (omitted)
}
}