use of java.util.zip.ZipInputStream in project NabAlive by jcheype.
the class ApplicationGroovyLoader method registerZip.
private void registerZip(File file) throws IOException, InstantiationException, IllegalAccessException {
ZipInputStream zipinputstream = new ZipInputStream(new FileInputStream(file));
String name = stripExtension(file.getName());
Application application = null;
byte[] logo = null;
String descriptor = null;
ZipEntry zipentry = zipinputstream.getNextEntry();
while (zipentry != null) {
String entryName = zipentry.getName();
if ("main.groovy".equalsIgnoreCase(entryName)) {
application = loadApplication(zipentry, zipinputstream, name);
} else if ("icon.png".equalsIgnoreCase(entryName)) {
logo = loadLogo(zipentry, zipinputstream);
} else if ("descriptor.json".equalsIgnoreCase(entryName)) {
descriptor = loadDescriptor(zipentry, zipinputstream);
}
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
}
zipinputstream.close();
if (application != null && logo != null && descriptor != null) {
applicationManager.registerApp(application, name, descriptor, logo);
}
}
use of java.util.zip.ZipInputStream in project neo4j by neo4j.
the class ProcedureJarLoader method listClassesIn.
private RawIterator<Class<?>, IOException> listClassesIn(URL jar, ClassLoader loader) throws IOException {
ZipInputStream zip = new ZipInputStream(jar.openStream());
return new PrefetchingRawIterator<Class<?>, IOException>() {
@Override
protected Class<?> fetchNextOrNull() throws IOException {
try {
while (true) {
ZipEntry nextEntry = zip.getNextEntry();
if (nextEntry == null) {
zip.close();
return null;
}
String name = nextEntry.getName();
if (name.endsWith(".class")) {
String className = name.substring(0, name.length() - ".class".length()).replace("/", ".");
try {
Class<?> aClass = loader.loadClass(className);
// We do getDeclaredMethods to trigger NoClassDefErrors, which loadClass above does
// not do.
// This way, even if some of the classes in a jar cannot be loaded, we still check
// the others.
aClass.getDeclaredMethods();
return aClass;
} catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
log.warn("Failed to load `%s` from plugin jar `%s`: %s", className, jar.getFile(), e.getMessage());
}
}
}
} catch (IOException | RuntimeException e) {
zip.close();
throw e;
}
}
};
}
use of java.util.zip.ZipInputStream in project nutz by nutzam.
the class JarResource method getInputStream.
public InputStream getInputStream() throws IOException {
ZipInputStream zis = Scans.makeZipInputStream(jarPath);
ZipEntry ens = null;
while (null != (ens = zis.getNextEntry())) {
if (ens.getName().equals(entryName))
return zis;
}
throw Lang.impossible();
}
use of java.util.zip.ZipInputStream in project orientdb by orientechnologies.
the class OZIPCompressionUtil method uncompressDirectory.
/***
* Extract zipfile to outdir with complete directory structure
*/
public static void uncompressDirectory(final InputStream in, final String out, final OCommandOutputListener iListener) throws IOException {
final File outdir = new File(out);
final ZipInputStream zin = new ZipInputStream(in);
try {
ZipEntry entry;
String name, dir;
while ((entry = zin.getNextEntry()) != null) {
name = entry.getName();
if (entry.isDirectory()) {
mkdirs(outdir, name);
continue;
}
/*
* this part is necessary because file entry can come before directory entry where is file located i.e.: /foo/foo.txt /foo/
*/
dir = getDirectoryPart(name);
if (dir != null)
mkdirs(outdir, dir);
extractFile(zin, outdir, name, iListener);
}
} finally {
zin.close();
}
}
use of java.util.zip.ZipInputStream in project orientdb by orientechnologies.
the class OZIPCompression method uncompress.
@Override
public byte[] uncompress(final byte[] content, final int offset, final int length) {
try {
final OMemoryInputStream memoryInputStream = new OMemoryInputStream(content, offset, length);
// 16KB
final ZipInputStream gzipInputStream = new ZipInputStream(memoryInputStream);
try {
final byte[] buffer = new byte[1024];
byte[] result = new byte[1024];
int bytesRead;
ZipEntry entry = gzipInputStream.getNextEntry();
int len = 0;
while ((bytesRead = gzipInputStream.read(buffer, 0, buffer.length)) > -1) {
if (len + bytesRead > result.length) {
int newSize = 2 * result.length;
if (newSize < len + bytesRead)
newSize = Integer.MAX_VALUE;
final byte[] oldResult = result;
result = new byte[newSize];
System.arraycopy(oldResult, 0, result, 0, oldResult.length);
}
System.arraycopy(buffer, 0, result, len, bytesRead);
len += bytesRead;
}
return Arrays.copyOf(result, len);
} finally {
gzipInputStream.close();
}
} catch (IOException ioe) {
throw new IllegalStateException("Exception during data uncompression", ioe);
}
}
Aggregations