com.baloise.maven.solr.UnZip Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-maven-plugin Show documentation
Show all versions of solr-maven-plugin Show documentation
A maven plugin to help develop and deploy SOLR based applications.
The newest version!
package com.baloise.maven.solr;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class UnZip {
public static void unzip(InputStream in, File dest) throws IOException {
if(in == null) throw new IOException("input must not be null");
try {
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze = null;
byte[] buffer = new byte[8 * 1024];
while ((ze = zin.getNextEntry()) != null) {
if (!ze.isDirectory()) {
String name = ze.getName();
File outputFile = new File(dest, name);
File outputDir = outputFile.getParentFile();
if (!(outputDir.exists() && outputDir.isDirectory())
&& !outputDir.mkdirs())
throw new IOException("Can not create directories for "
+ outputDir.getAbsolutePath());
outputFile.createNewFile();
FileOutputStream fout = new FileOutputStream(outputFile);
int len = 0;
while ((len = zin.read(buffer)) > 0) {
fout.write(buffer, 0, len);
}
fout.close();
}
zin.closeEntry();
}
zin.close();
} catch (IOException e) {
throw new IOException("Can not unzip to " + dest.getAbsolutePath());
}
}
}