Reputation: 1
I have written the code to convert the data from EBCDIC to ASCII which is working fine for digits and Uppercase letters such as 1, 2, A, B, C. However, it not converting lowercase letters l and when are printing them in the logs it prints non readable characters. Below is the code snipped that we are using for conversion.
public String ebcdicToAscii(String ebcdicValue) {
String asciiBuffer = null;
logger.debug("converting field value frm ebcdic to Ascii. ");
try {
byte[] ebcdicByteArr = ebcdicValue.toString().getBytes(StandardCharsets.ISO_8859_1);
int textLen = ebcdicByteArr.length;
AS400Text textConverter = new AS400Text(textLen);
asciiBuffer = ((String) textConverter.toObject(ebcdicByteArr)).substring(0, textLen);
System.out.println("value: "+asciiBuffer);
} catch (Exception e) {
logger.error("error while converting field value from ebcdic To Ascii: " + e);
}
return asciiBuffer;
}
How to fix this issue?
Upvotes: 0
Views: 342
Reputation: 38
If the problem is only with lower letters then convert lowercase letters to uppercase:
String a = "{0xf1,0xf2,0xf3}";
a = a.substring(1, a.length()-1); //delete first and last character {}
String[] array = a.split(","); //separate with comma
ArrayList<String> scripts = new ArrayList<String>();
for (int i=0; i<array.length; i++)
{
String b = array[i].substring(0,1).toUpperCase() + array[i].substring(1,2).toLowerCase() + array[i].substring(2).toUpperCase();
scripts.add(b);
}
System.out.println(scripts.toString());
Output is:
0xF1,0xF2,0xF3
Upvotes: 1