Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ASCII to EBCIDIC conversion error

 
Amar Naik
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are have some historical data in ASCII format. We want to insert this data into our system in EBCIDIC format. I am trying to write a code to convert ASCII data to EBCIDIC data
Below is my logic
import java.io.*;

public class DcollType {



static String readInput() {

StringBuffer buffer = new StringBuffer();
try {

FileInputStream fis = new FileInputStream("ASCII.txt");
InputStreamReader isr = new InputStreamReader(fis, "ASCII") ;
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
buffer.append((char)ch);
}
in.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

static void writeOutput(String str) {

try {
FileOutputStream fos = new FileOutputStream("ASCII_EBCIDIC.bin");;
Writer out = new OutputStreamWriter(fos, "Cp1047" );
out.write(str);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}


public static void main(String[] args){
String inputstr=readInput();
writeOutput(inputstr);
}



}


This data gets produced from mainframe. the mainframe transmitted a sample file one in ASCII and another in EBCIDIC.
I used my program and converted the ASCII file to EBCIDIC. When i compared with the mainframe EBCIDIC file, there is a mismatch.

Can anybody please advise
 
Paul Clapham
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This mismatch... is it that everything is totally wrong? Or is it that only a few characters are wrong (which might indicate that CP1047 was the wrong flavour of EBCDIC for your system)?

And you are trying to target only alpha fields on the mainframe, right? If there were packed decimal fields then perhaps the mainframe might have converted them into ASCII differently.

I guess I'm saying we need more information about the mismatch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic