473,566 Members | 3,245 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;
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;
}
}
Mar 11 '17 #1
1 1678
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
12971
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 is somehow hanging when relatively large file is used. My original intent was to try to just add a check for file size, and error out somehow if...
9
6742
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 get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger...
1
2613
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 sheet) It shows the message " java.lang.OutOfMemoryError: Java heap space" so can any one help me in this time Thanks
7
4540
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 java.util.Scanner; import javax.swing.JOptionPane; public class samplecode {
2
1439
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 the name of the last person to run the application, this information should be retrieved from a file. After welcoming the users, asks them for their...
10
3177
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. My first question how should i read/load a file in java Script and read its contents.? Also is it possible to parse data in javascript? Regards...
1
3709
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" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ContextML/1.6c" elementFormDefault="qualified" attributeFormDefault="unqualified">
7
14376
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. Thanks in advance. My java code: ------------- import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; import...
0
1243
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 in bin folder when i am using command prompt when i am using eclipse java and python both file is present in default package . what i do to run...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7953
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
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.