java - Reading a line with multiple line breaks as separate lines -


i have java program running on mainframe z/os , reading ebcdic file. few of lines in file have multiple records separated ebcdic 'lf' x'025'. using java readline , expected reading record till linefeed , discarding rest of records. besides parsing big line multiple records, there way make read methods split line multiple lines/records , return same? if needed, have option change new-line delimiter values.

input:

10,ibm,erwin,black,123,abc(lf)10,ibm,jack,rose,456 

expected output

10,ibm,erwin,black,123,abc 10,ibm,jack,rose,456 

current code:

public arraylist<string> readmainframefile()     {         //string ddname = zfile.allocdummyddname();         //system.out.println("the ddname " + ddname);         //zfile convout = new zfile("//dd:convout", "wb,type=record,noseek");          //recordreader reader=null;          try {             zfile convin = new zfile("//dd:convin", "rb,type=record,noseek");             system.out.println("the ddname is" + convin.getlrecl());             byte[] recordbuf = new byte[convin.getlrecl()];             int bytesread=0;             inputstream ins = null;             bufferedreader reader = null;             string temp=null;             arraylist<string> lines = new arraylist<string>();              while((bytesread = convin.read(recordbuf)) > 0) {                 //system.out.println("the number of bytes read is" + bytesread);                 try {                     ins = new bytearrayinputstream(recordbuf);                     reader = new bufferedreader(new inputstreamreader(ins,charset.forname("ibm500")));                     temp=reader.readline();                     lines.add(temp);                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                     return null;                 }              }              return lines;          } catch (zfileexception e) {             system.err.println(e.getmessage());             return null;            }         }  

you're opening file qsam binary i/o when should opening text file stream.

zfile convin = new zfile("//dd:convin", "r"); 

then read records stream. there's no need additional line reader. z/os unix newlines x'15' may need change linefeed character.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -