public void extract( @NotNull File destination, @NotNull final InputStream inputStream ) throws IOException {
if ( !destination.exists() || !destination.isDirectory() ) {
throw new IllegalArgumentException( "Invalid destination: " + destination.getCanonicalPath() );
}
ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream( inputStream );
try {
byte[] buf = new byte[BUFFER_LENGTH];
for ( ArchiveEntry zipEntry = zipInputStream.getNextEntry(); zipEntry != null; zipEntry = zipInputStream.getNextEntry() ) {
if ( condition != null && !condition.shallExtract( zipEntry ) ) {
continue;
}
String entryName = zipEntry.getName();
File newFile = new File( destination, entryName );
//Is a directory
if ( zipEntry.isDirectory() ) {
newFile.mkdirs();
continue;
}
//Make the directory structure
newFile.getParentFile().mkdirs();
FileOutputStream fileoutputstream = new FileOutputStream( newFile );
try {
int n;
while ( ( n = zipInputStream.read( buf, 0, BUFFER_LENGTH ) ) > -1 ) {
fileoutputstream.write( buf, 0, n );
}
} finally {
fileoutputstream.close();
}
}
} finally {
zipInputStream.close();
}
}