You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2011/10/10 19:30:06 UTC

[compress] unzip a file in one go API?

Can you unzip a file in one shot using Apache Commons Compress?



>From https://wiki.apache.org/commons/Compress, I see:



final InputStream <https://wiki.apache.org/commons/InputStream> is = new
FileInputStream <https://wiki.apache.org/commons/FileInputStream>(input);

ArchiveInputStream <https://wiki.apache.org/commons/ArchiveInputStream> in =
new ArchiveStreamFactory<https://wiki.apache.org/commons/ArchiveStreamFactory>().createArchiveInputStream("zip",
is);

ZipArchiveEntry <https://wiki.apache.org/commons/ZipArchiveEntry> entry = (
ZipArchiveEntry
<https://wiki.apache.org/commons/ZipArchiveEntry>)in.getNextEntry();


OutputStream <https://wiki.apache.org/commons/OutputStream> out = new
FileOutputStream <https://wiki.apache.org/commons/FileOutputStream>(new
File(dir, entry.getName()));

IOUtils.copy(in, out);

out.close();

in.close();



But that looks like you (1) need to loop though the ZIP entries and (2)
create dirs yourself.


What am I missing?

How about adding a decompress(source, dest) API?


Thank you,
Gary

-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: [compress] unzip a file in one go API?

Posted by Christian Grobmeier <gr...@gmail.com>.
On Mon, Oct 10, 2011 at 7:30 PM, Gary Gregory <ga...@gmail.com> wrote:
> Can you unzip a file in one shot using Apache Commons Compress?
>
>
> But that looks like you (1) need to loop though the ZIP entries and (2)
> create dirs yourself.
> What am I missing?

Nothing :-)

> How about adding a decompress(source, dest) API?

Why not. Now we have a good "base" api, we really could need some cool
tools around it. one is already in svn, its a class called "Lister"
which outputs the content of an archive.

Cheers
Christian

>
>
> Thank you,
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
> Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
http://www.grobmeier.de

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [compress] unzip a file in one go API?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-10-10, Gary Gregory wrote:

> Can you unzip a file in one shot using Apache Commons Compress?
> But that looks like you (1) need to loop though the ZIP entries and (2)
> create dirs yourself.

What Christian said.

> How about adding a decompress(source, dest) API?

COMPRESS-118

Actually I'd like us to get Compress 1.3 out of the door soonish (more
on that on the dev list later) and start discussing changes to the lower
level API for 2.0, some of which might affect how we'd do higher level
APIs.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org