Solved

ascii to ebcdic file conversion trouble

Posted on 2002-03-05
6
1,141 Views
Last Modified: 2012-05-04
i am trying to convert a file from ascii to ebcdic.  the conversion process works fine, but the resulting file is all on one line.

Any help would be most appreciated:

import java.io.*;

class eToATranslator
{
     public static void main (String args[])
     {
          try
          {
               //create and input stream reader                    
               FileInputStream inputStream = new FileInputStream ("XFERCED.TXT");
               //convert from ascii to unicode
               InputStreamReader inputReader = new InputStreamReader(inputStream,"Cp500");
               //attach a buffer to it
               BufferedReader buffReader = new BufferedReader (inputReader);

               //output file in ebcdic from unicode
               OutputStreamWriter outWriter = new OutputStreamWriter(new FileOutputStream("OutputXFER2.txt"),"Cp1252");
         
               String str = null;
               while ((str = buffReader.readLine()) !=null)
               {
                    outWriter.write(str+"\n");
               }
                         
               inputReader.close();
               inputStream.close();
               outWriter.close();
          }
          catch (Exception e)
          {
               System.out.println("Exception: " + e);
          }
     }
}

0
Comment
Question by:mark_cawood
  • 4
6 Comments
 
LVL 9

Expert Comment

by:Venci75
Comment Utility
2 suggestions:
1. use outWriter.write(str+"\r\n") instead of outWriter.write(str+"\n")
2. Use PrintWriter:
//output file in ebcdic from unicode
OutputStreamWriter outWriter = new OutputStreamWriter(new FileOutputStream("OutputXFER2.txt"),"Cp1252");
PrintWriter printWriter = new PrintWriter(outWriter);
...
printWriter.println(str+"\n");
...                        
0
 

Author Comment

by:mark_cawood
Comment Utility
Thanks for the help.

The outWriter.write(str+"\r\n") almost works. Each line of the EBCDIC code now appears on a new line.

The problem is that each line now starts with a  character and the hex values of the end of line / new line are always the sequence 0D 0A 15

to the best of my knowledge:

0D is the EBCDIC and ASCII carriage return
0A is the ASCII line feed
15 is the EBCDIC new line

So, is the 0A in that sequence anything to worry about when this file is being processed by an ebcdic reading system? (so far i've only looked at it using UltraEdit 9)

0
 

Author Comment

by:mark_cawood
Comment Utility
Thanks for the help.

The outWriter.write(str+"\r\n") almost works. Each line of the EBCDIC code now appears on a new line.

The problem is that each line now starts with a  character and the hex values of the end of line / new line are always the sequence 0D 0A 15

to the best of my knowledge:

0D is the EBCDIC and ASCII carriage return
0A is the ASCII line feed
15 is the EBCDIC new line

So, is the 0A in that sequence anything to worry about when this file is being processed by an ebcdic reading system? (so far i've only looked at it using UltraEdit 9)

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mark_cawood
Comment Utility
see above
0
 
LVL 4

Accepted Solution

by:
m_onkey_boy earned 50 total points
Comment Utility

Have you tried this?

outWriter.write(str);
outWriter.write(0x0D);
outWriter.write(0x15);

Even if it looks wrong in notepad, it may be valid anyway.

----------------------------------------------------
BTW - No big deal, but you are closing the same stream twice:

inputReader.close();
inputStream.close();
0
 

Author Comment

by:mark_cawood
Comment Utility
Thanks, seems to work ok
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now