473,499 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading of an ebcdic GZ ( file zipped) in java

1 New Member
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;
}
}
Mar 11 '17 #1
1 1674
chaarmann
785 Recognized Expert Contributor
Please use code tags next time when posting code.

You read a string in and then you just need to find the character inside the string.
original code:
Expand|Select|Wrap|Line Numbers
  1. while ((content = bfrdr.readLine()) != null) {
  2. if (logrequired == content.charAt(10)) {
  3. System.out.println("in write cond meet:");
  4. }
changed code:
Expand|Select|Wrap|Line Numbers
  1. while ((content = bfrdr.readLine()) != null) {
  2.   if (content.indexOf(logrequired) != -1) {
  3.     System.out.println("in write cond meet:");
  4.   }
  5. }
Mar 15 '17 #2

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

Similar topics

2
12967
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
6726
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
2609
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
4529
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
1435
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
3163
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
3688
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
14371
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
1237
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...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.