File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes gunzipping the file more than once at the same time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "gunzipping the file more than once at the same time" Watch "gunzipping the file more than once at the same time" New topic
Author

gunzipping the file more than once at the same time

Vani Bhatia
Greenhorn

Joined: Nov 25, 2009
Posts: 7
Hello,

Iam new to Java programming. I want to know if a gzipped file can be gunzipped simultaneously more than once using GZIPInputStream and FileOutputStream classes. For instance, I have a file gzippedFileName.gz. I want to gunzip it into filename1 , filename 2,filename3 etc
at the same time(by using different threads to access it,may be). Is it possible to do like this?

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Although I don't get why you would want to do this (as you would get identical files), it most certainly is possible. However, I wouldn't use a thread for this; you would read the entire file over and over. Instead, use a special OutputStream subclass that writes to multiple other output streams as well. I've given an example for a Writer subclass here, although that uses only two streams. You can modify it to store an OutputStream[] or List<OutputStream>; each method then executes in a loop. E.g.:
With this class you can now simply read the file once, then copy to an instance of this class. It will take care of writing to all its backing output streams.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: gunzipping the file more than once at the same time