Solved

read .gz file in java

Posted on 2010-08-20
6
1,135 Views
Last Modified: 2013-11-21
Hi:

I need to download a .gz file online. Inside the gzip file is one csv file. All is well except that I am only getting first line (the table head) of the file.  Here's the code, please help:

String url  = new URL ("myurl");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
con.setRequestProperty("Cookie",cookielist.toString());
con.getContent();
                                    
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
GZIPInputStream gzin = new GZIPInputStream(in);
BufferedReader br = new BufferedReader(new InputStreamReader(gzin));
while ((line=br.readLine())!=null) {
     System.out.println("read: " + line);
}
0
Comment
Question by:sdc248
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 33488414
>>con.getContent();

You should get rid of that. Is this url publicly available?
0
 

Author Comment

by:sdc248
ID: 33488514
With or without that line doesn't seem to make a difference.

The url is a password protected https web page. My code manages to login and read the html content of the web page where the file is published.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33488534
Make sure you're not ignoring any exceptions.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 10

Accepted Solution

by:
Hegemon earned 250 total points
ID: 33488703
- My code manages to login and read the html content of the web page where the file is published

So html content or gzip content ?

If you manage to retrieve gzip and can see the first line of your csv file, then everything looks ok. If you are sure there is more than line, make sure the "lines" are understood equally on both platforms - where the file was created and where it is being downloaded to. I.e. if the fie was created on Unix and processed on Windows, the whole content can be interpreted as one long line simply because of the differences between just <LF> and <CR><LF>
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 33489093
>>If you are sure there is more than line, make sure the "lines" are understood equally on both platforms


Actually BR makes no distinction between platforms:

http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/io/BufferedReader.html#readLine()
0
 

Author Comment

by:sdc248
ID: 33513825
I tried to have my code to download and read another .gz file on the same web page and it worked!

Looks like my code is fine. The mistery is on how the files were created, perhaps?

Anyway, thank you guys for your help.
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question