use of java.util.jar.JarInputStream in project flink by apache.
the class JarHelper method unjar.
/**
* Given an InputStream on a jar file, unjars the contents into the given
* directory.
*/
public void unjar(InputStream in, File destDir) throws IOException {
BufferedOutputStream dest = null;
JarInputStream jis = new JarInputStream(in);
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
if (entry.isDirectory()) {
File dir = new File(destDir, entry.getName());
dir.mkdir();
if (entry.getTime() != -1) {
dir.setLastModified(entry.getTime());
}
continue;
}
int count;
byte[] data = new byte[BUFFER_SIZE];
File destFile = new File(destDir, entry.getName());
if (mVerbose) {
System.out.println("unjarring " + destFile + " from " + entry.getName());
}
FileOutputStream fos = new FileOutputStream(destFile);
dest = new BufferedOutputStream(fos, BUFFER_SIZE);
try {
while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
} finally {
dest.close();
}
if (entry.getTime() != -1) {
destFile.setLastModified(entry.getTime());
}
}
jis.close();
}
use of java.util.jar.JarInputStream in project robovm by robovm.
the class OldJarInputStreamTest method test_ConstructorLjava_io_InputStreamZ.
public void test_ConstructorLjava_io_InputStreamZ() {
try {
// we need a buffered stream because ByteArrayInputStream.close() is a no-op
InputStream is = new BufferedInputStream(new ByteArrayInputStream(new byte[0]));
is.close();
new JarInputStream(is, false);
fail("IOException expected");
} catch (IOException ee) {
// expected
}
}
use of java.util.jar.JarInputStream in project robovm by robovm.
the class OldJarInputStreamTest method test_read$ZII.
public void test_read$ZII() throws Exception {
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "Broken_entry_data.jar");
InputStream is = Support_Resources.getStream("Broken_entry_data.jar");
JarInputStream jis = new JarInputStream(is, true);
byte[] b = new byte[100];
jis.getNextEntry();
jis.read(b, 0, 100);
jis.getNextEntry();
jis.getNextEntry();
jis.getNextEntry();
try {
jis.read(b, 0, 100);
fail("ZipException expected");
} catch (ZipException ee) {
// expected
}
try {
// Android throws exception here, already!
jis.close();
// But RI here, only!
jis.read(b, 0, 100);
fail("IOException expected");
} catch (IOException ee) {
// expected
}
}
use of java.util.jar.JarInputStream in project reflections by ronmamo.
the class JarInputDir method getFiles.
public Iterable<Vfs.File> getFiles() {
return new Iterable<Vfs.File>() {
public Iterator<Vfs.File> iterator() {
return new AbstractIterator<Vfs.File>() {
{
try {
jarInputStream = new JarInputStream(url.openConnection().getInputStream());
} catch (Exception e) {
throw new ReflectionsException("Could not open url connection", e);
}
}
protected Vfs.File computeNext() {
while (true) {
try {
ZipEntry entry = jarInputStream.getNextJarEntry();
if (entry == null) {
return endOfData();
}
long size = entry.getSize();
//JDK-6916399
if (size < 0)
size = 0xffffffffl + size;
nextCursor += size;
if (!entry.isDirectory()) {
return new JarInputFile(entry, JarInputDir.this, cursor, nextCursor);
}
} catch (IOException e) {
throw new ReflectionsException("could not get next zip entry", e);
}
}
}
};
}
};
}
use of java.util.jar.JarInputStream in project spring-boot by spring-projects.
the class JarFile method setupEntryCertificates.
void setupEntryCertificates(JarEntry entry) {
// happening that often.
try {
JarInputStream inputStream = new JarInputStream(getData().getInputStream(ResourceAccess.ONCE));
try {
java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry();
while (certEntry != null) {
inputStream.closeEntry();
if (entry.getName().equals(certEntry.getName())) {
setCertificates(entry, certEntry);
}
setCertificates(getJarEntry(certEntry.getName()), certEntry);
certEntry = inputStream.getNextJarEntry();
}
} finally {
inputStream.close();
}
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
Aggregations