• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Chaining readers

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been playing with reading a gzip'd file.

This works fine:

Two questions:

1. Is the approach I pieced together from various websites the best/most elegant way to read text from a gzip'd file?

2. There are two streams and a reader. Which of the streams/reader should I close when I'm done reading the file. All of them?

Thanks very much.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. I think you've got one more reader than you need there. You should be able to pass fstream straight into the InputStreamReader - I don't see any need to introduce a DataInputStream. Other than that, it looks fine.

2. Close the outer one (your BufferedReader) and that will cascade down - it will close all of them.
 
Stan Lederer
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:1. I think you've got one more reader than you need there. You should be able to pass fstream straight into the InputStreamReader - I don't see any need to introduce a DataInputStream. Other than that, it looks fine.

2. Close the outer one (your BufferedReader) and that will cascade down - it will close all of them.


Excellent. Thank you.
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic