I am trying to read an GZ file which has EBCDIC data and need to write the records into output file if that records has an character in a given position.
I have done the below:
Read the GZ file line by line using Buffered reader and GZInputStream, however when I read line ny line I am not able to compare the input char with the record.
I have specified the encoding as Cp1047 for the reader.
I am converting the character to ebcdic and got the byte . How can now i compare this byte with record
Can some help me out or tell me how can this be achieved?
PFB code
public static void main(String[] args) {
// TODO Auto-generated method stub
int buffersize = 1024;
File file = null;
GzipCompressorI nputStream gzIn = null;
FileInputStream fin = null;
BufferedInputSt ream in = null;
FileOutputStrea m out = null;
ByteBuffer bb = ByteBuffer.allo cateDirect(6* 1024 * 1024);
try {
//creating the object to access the methods in this class
ReadZipFile obj = new ReadZipFile();
// calingmethod to get the file name from src/main/resources
File result1 =obj.getFileWit hUtil("txt.gz") ;
//declaring file input stream using file object
fin = new FileInputStream (result1);
//declaring the reader for gzip with buffered reader object
gzIn = new GzipCompressorI nputStream(fin) ;
//delcaring buffered input stream reader
in = new BufferedInputSt ream(gzIn,6*102 4*1024);
// declaring chaneel with buffereinput stream
ReadableByteCha nnel rbc = Channels.newCha nnel(in);
//delcarin the output file
out = new FileOutputStrea m("gzsample2.tx t");
final byte[] buffer = new byte[buffersize];
BufferedReader bfrdr = new BufferedReader( new InputStreamRead er(gzIn,"Cp1047 "));
String content = null;
char logrequired = 'j'; // This is the value that i will get as job paramter
while ((content = bfrdr.readLine( )) != null) {
if (logrequired == content.charAt( 10)) {
System.out.prin tln("in write cond meet:");
}
// log.info("recor d is :" +content);
}
//
//// int bytesRead = rbc.read(bb);
//
// int bytesRead =0;
//
// bytesRead = rbc.read(bb);
// int position = 1;
// int length = 8;
//// System.out.prin tln(bb.asCharBu ffer());
// ByteBuffer rec = bb.get(buffer, position, length);
//
// // PrintByteBuffer (bb, position, 32);
//
//to write
// while (-1 != (n = gzIn.read(buffe r))) {
// out.write(buffe r, 0, n);
// }
} catch (FileNotFoundEx ception e) {
// TODO Auto-generated catch block
e.printStackTra ce();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTra ce();
}
//Now close the all the readers
try {
out.close();
gzIn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTra ce();
}
}
private File getFileWithUtil (String fileName) {
System.out.prin tln("getFileWit hUtil");
System.out.prin tln(fileName);
// Get file from resources folder
ClassLoader classLoader = getClass().getC lassLoader();
File file = new File(classLoade r.getResource(f ileName).getFil e());
System.out.prin tln(file.getAbs olutePath());
return file;
}
}