Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-07-2013, 12:59 PM   #1
LQ Newbie
Registered: Apr 2013
Location: Plano Texas
Posts: 1

Rep: Reputation: Disabled
Migrating Java application from HP/UX to Linux - String to byte array issues

I have a Java application which is currently running on an HP/UX box and is being migrated to Suse Linux. The application must translate data from ASCII to EBCDIC to send to a mainframe legacy app. If I have the code line below in in HP/UX, it works fine:

String transactionName = new String(transNameByteArray);

However, executing this same code in Linux produces a String which is neither ASCII nor EBCDIC valid data. I understand that I may need to force the code page used as it may be different on HP/UX than on Linux but I am not sure what the code page would be. The line below doesn't correct the issue:

String transactionName = new String(transNameByteArray, "ISO-8859-1");
Old 04-07-2013, 02:30 PM   #2
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,272

Rep: Reputation: 1456Reputation: 1456Reputation: 1456Reputation: 1456Reputation: 1456Reputation: 1456Reputation: 1456Reputation: 1456Reputation: 1456Reputation: 1456
However, executing this same code in Linux produces a String which is neither ASCII nor EBCDIC valid data.
A String is Unicode.

ASCII <-> EBCDIC conversion (I used IBM500 because the EBCDIC Wikipedia page uses it in the example):
import java.math.*;
import java.nio.charset.*;

public class Ascii2Ebcdic {
    public static byte[] conv(Charset from, Charset to, byte[] bytes) {
        return new String(bytes, from).getBytes(to);
    public static void main(String[] args) throws Exception {
        Charset ascii = Charset.forName("US-ASCII");
        Charset ebcdic = Charset.forName("IBM500");

        byte[] abc_ascii = { 0x61, 0x62, 0x63 };
        byte[] xyz_ebcdic = { (byte)0xA7, (byte)0xA8, (byte)0xA9 };
        System.out.write(conv(ascii, ebcdic, abc_ascii));
        System.out.write(conv(ebcdic, ascii, xyz_ebcdic));
Output (which is "abc" in EBCDIC followed by "xyz" in ASCII):
% java Ascii2Ebcdic | od -t x1
0000000 81 82 83 78 79 7a


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues with connecting to Java application from outside lan sajuthomas Linux - Networking 0 09-24-2007 06:56 AM
Converting Image to Byte Array (Java) megabot Programming 2 03-17-2007 10:49 AM
Java byte array problem Mohsen Programming 2 03-11-2004 02:37 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 02:39 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:44 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration