473,385 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading of an ebcdic GZ ( file zipped) in java

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;
GzipCompressorInputStream gzIn = null;
FileInputStream fin = null;
BufferedInputStream in = null;
FileOutputStream out = null;
ByteBuffer bb = ByteBuffer.allocateDirect(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.getFileWithUtil("txt.gz");
//declaring file input stream using file object
fin = new FileInputStream(result1);
//declaring the reader for gzip with buffered reader object
gzIn = new GzipCompressorInputStream(fin);
//delcaring buffered input stream reader
in = new BufferedInputStream(gzIn,6*1024*1024);
// declaring chaneel with buffereinput stream
ReadableByteChannel rbc = Channels.newChannel(in);
//delcarin the output file
out = new FileOutputStream("gzsample2.txt");
final byte[] buffer = new byte[buffersize];
BufferedReader bfrdr = new BufferedReader(new InputStreamReader(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.println("in write cond meet:");
}
// log.info("record is :" +content);
}
//
//// int bytesRead = rbc.read(bb);
//
// int bytesRead =0;
//
// bytesRead = rbc.read(bb);
// int position = 1;
// int length = 8;
//// System.out.println(bb.asCharBuffer());
// ByteBuffer rec = bb.get(buffer, position, length);
//
// // PrintByteBuffer(bb, position, 32);
//
//to write

// while (-1 != (n = gzIn.read(buffer))) {
// out.write(buffer, 0, n);
// }

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//Now close the all the readers
try {
out.close();
gzIn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private File getFileWithUtil(String fileName) {
System.out.println("getFileWithUtil");
System.out.println(fileName);
// Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(fileName).getFile());
System.out.println(file.getAbsolutePath());
return file;
}
}
Oct 5 '17 #1
0 1601

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ohaya | last post by:
Hi, I'm a real newbie, but have been asked to try to fix a problem in one of our JSP pages that is suppose to read in a text file and display it. From my testing thus far, it appears this page...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
1
by: sunilkumar.r80 | last post by:
Hi I have a problem in reading a .xls file using java. I am using jakarta POI ApI for that it work fine for a 9000 rows contians 25 colums. But i need to read more than 25000 rows (in a single...
7
by: tackleberi | last post by:
hi, im having some trouble reading a file into java and then storing it in an array here the code i have so far: import java.io.FileNotFoundException; import java.io.FileReader; import...
2
by: yaveus | last post by:
Hi?I am studying java on my own and got stack on how to read and post data to a file using java e.g how will you solve this: A simple application that, when run, Welcomes the users and tells them...
10
by: wanni | last post by:
Hi All, I want to store data in a encypted form (in form of some file) and later on i want to read encrypted data in Java Script and want to pass that encrypted buffer to some Active X component. ...
1
by: sanabeel | last post by:
Hello all, I want to read the following file through java.... Anyone who knows plz help me ... The file is <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns="http://ContextML/1.6c"...
7
by: SakthiPriya28 | last post by:
i am trying to execute a .sql file in java. It works fine when i am giving exit at the end of the .sql file. Is there any solution to run without giving exit at the end of file, please reply me....
0
by: rspvsanjay | last post by:
This program (below), I am able to run from command prompt but when i am using eclipse that is not returning any text. May this is not running python file java file and python file is present...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.