LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 04-07-2013, 11:59 AM   #1
JayMac2013
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, 01:30 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,694

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
Quote:
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):
Code:
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):
Code:
% java Ascii2Ebcdic | od -t x1
0000000 81 82 83 78 79 7a
0000006
 
  


Reply


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 05:56 AM
Converting Image to Byte Array (Java) megabot Programming 2 03-17-2007 09:49 AM
Java byte array problem Mohsen Programming 2 03-11-2004 01:37 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:58 AM.

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