gunzipping an URL

G

Guest

I have an applet which reads some astronomical images via a class of its
own. This class uses at present two constructors:

- one constructor (used for tests) receives as argument a String file
name and does

DataInputStream in = new DataInputStream
(new BufferedInputStream(
new FileInputStream(file)
, 2880
)
);

- the other constructor (used in real life) receives as argument
an URL url and then

URLConnection urlc = url.openConnection() ;
urlc.connect();
DataInputStream in = new DataInputStream
(new BufferedInputStream(
urlc.getInputStream()
, 2880
)
);

The URL correspond to a binary file of the same kind as for a local
file. The 2880-byte record length is intrinsic to that kind of file.

Now I'd want to replace such files (name) with gzipped files (name.gz)

I see that there is a class GZIPInputStream. What is the correct way
to use it ? should I wrap it around the innermost stream ?

DataInputStream in = new DataInputStream
(new BufferedInputStream(
new GZIPInputStream(
urlc.getInputStream()
)
, 2880
)
);

Is it correct to expect that this will receive the gzipped data
(transferred as such between apache httpd server and applet) and
do the gunzipping locally within the applet ?
 
D

Daniel Pitts

LC's No-Spam Newsreading account said:
I have an applet which reads some astronomical images via a class of its
own. This class uses at present two constructors:

- one constructor (used for tests) receives as argument a String file
name and does

DataInputStream in = new DataInputStream
(new BufferedInputStream(
new FileInputStream(file)
, 2880
)
);

- the other constructor (used in real life) receives as argument
an URL url and then

URLConnection urlc = url.openConnection() ;
urlc.connect();
DataInputStream in = new DataInputStream
(new BufferedInputStream(
urlc.getInputStream()
, 2880
)
);

The URL correspond to a binary file of the same kind as for a local
file. The 2880-byte record length is intrinsic to that kind of file.

Now I'd want to replace such files (name) with gzipped files (name.gz)

I see that there is a class GZIPInputStream. What is the correct way
to use it ? should I wrap it around the innermost stream ?

DataInputStream in = new DataInputStream
(new BufferedInputStream(
new GZIPInputStream(
urlc.getInputStream()
)
, 2880
)
);

Is it correct to expect that this will receive the gzipped data
(transferred as such between apache httpd server and applet) and
do the gunzipping locally within the applet ?
That would work, although you need to keep references to the inner-most
input stream so that you can close it in a "finally" block.
 
M

Mike Schilling

Daniel said:
That would work, although you need to keep references to the
inner-most input stream so that you can close it in a "finally"
block.

Won't closing the outermost stream close all the others?
 
D

Daniel Pitts

Mike said:
Won't closing the outermost stream close all the others?
Yes, but any one of those constructors may through an exception, in
which case you've lost the reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top