use of java.util.jar.JarFile in project byte-buddy by raphw.
the class ClassFileLocatorForJarFileTest method testClose.
@Test
public void testClose() throws Exception {
JarFile jarFile = mock(JarFile.class);
new ClassFileLocator.ForJarFile(jarFile).close();
verify(jarFile).close();
verifyNoMoreInteractions(jarFile);
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarURLConnectionImpl method openJarFile.
private JarFile openJarFile() throws IOException {
if (jarFileURL.getProtocol().equals("file")) {
String decodedFile = UriCodec.decode(jarFileURL.getFile());
return new JarFile(new File(decodedFile), true, ZipFile.OPEN_READ);
} else {
final InputStream is = jarFileURL.openConnection().getInputStream();
try {
FileOutputStream fos = null;
JarFile result = null;
try {
File tempJar = File.createTempFile("hyjar_", ".tmp", null);
tempJar.deleteOnExit();
fos = new FileOutputStream(tempJar);
byte[] buf = new byte[4096];
int nbytes = 0;
while ((nbytes = is.read(buf)) > -1) {
fos.write(buf, 0, nbytes);
}
fos.close();
return new JarFile(tempJar, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
} catch (IOException e) {
return null;
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException ex) {
return null;
}
}
}
} finally {
if (is != null) {
is.close();
}
}
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method testConstructor_file.
/**
* Constructs JarFile object.
*
* java.util.jar.JarFile#JarFile(java.io.File)
* java.util.jar.JarFile#JarFile(java.lang.String)
*/
public void testConstructor_file() throws IOException {
File f = new File(resources, jarName);
Support_Resources.copyFile(resources, null, jarName);
assertTrue(new JarFile(f).getEntry(entryName).getName().equals(entryName));
assertTrue(new JarFile(f.getPath()).getEntry(entryName).getName().equals(entryName));
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_Inserted_Entry_Manifest_with_DigestCode.
/*
* If another entry is inserted into Manifest, no security exception will be
* thrown out.
*/
public void test_Inserted_Entry_Manifest_with_DigestCode() throws IOException {
String modifiedJarName = "Inserted_Entry_Manifest_with_DigestCode.jar";
Support_Resources.copyFile(resources, null, modifiedJarName);
JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
Enumeration<JarEntry> entries = jarFile.entries();
int count = 0;
while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
jarFile.getInputStream(zipEntry);
count++;
}
assertEquals(5, count);
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_JarFile_Integrate_Jar.
/* The jar is intact, then everything is all right. */
public void test_JarFile_Integrate_Jar() throws IOException {
String modifiedJarName = "Integrate.jar";
Support_Resources.copyFile(resources, null, modifiedJarName);
JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
jarFile.getInputStream(zipEntry).skip(Long.MAX_VALUE);
}
}
Aggregations