commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject [compress] unzip a file in one go API?
Date Mon, 10 Oct 2011 17:30:06 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message