use of java.util.jar.JarInputStream in project sling by apache.
the class BundleFileProcessorTest method compareJarContents.
private static void compareJarContents(File orgJar, File actualJar) throws IOException {
JarInputStream jis1 = null;
JarInputStream jis2 = null;
try {
jis1 = new JarInputStream(new FileInputStream(orgJar));
jis2 = new JarInputStream(new FileInputStream(actualJar));
JarEntry je1 = null;
while ((je1 = jis1.getNextJarEntry()) != null) {
if (je1.isDirectory())
continue;
JarEntry je2 = null;
while ((je2 = jis2.getNextJarEntry()) != null) {
if (!je2.isDirectory())
break;
}
assertEquals(je1.getName(), je2.getName());
assertEquals(je1.getSize(), je2.getSize());
try {
byte[] buf1 = streamToByteArray(jis1);
byte[] buf2 = streamToByteArray(jis2);
assertArrayEquals("Contents not equal: " + je1.getName(), buf1, buf2);
} finally {
jis1.closeEntry();
jis2.closeEntry();
}
}
} finally {
closeQuietly(jis1);
closeQuietly(jis2);
}
}
use of java.util.jar.JarInputStream in project cloudstack by apache.
the class OnwireClassRegistry method getFromJARFile.
static Set<Class<?>> getFromJARFile(String jar, String packageName) throws IOException, ClassNotFoundException {
Set<Class<?>> classes = new HashSet<Class<?>>();
try (JarInputStream jarFile = new JarInputStream(new FileInputStream(jar))) {
JarEntry jarEntry;
do {
jarEntry = jarFile.getNextJarEntry();
if (jarEntry != null) {
String className = jarEntry.getName();
if (className.endsWith(".class")) {
className = stripFilenameExtension(className);
if (className.startsWith(packageName)) {
try {
Class<?> clz = Class.forName(className.replace('/', '.'));
classes.add(clz);
} catch (ClassNotFoundException | NoClassDefFoundError e) {
s_logger.warn("Unable to load class from jar file", e);
}
}
}
}
} while (jarEntry != null);
return classes;
}
}
use of java.util.jar.JarInputStream in project aries by apache.
the class Helper method getBundleDescriptor.
private static BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
File file = new File(path);
FileOutputStream fos = new FileOutputStream(file, true);
try {
copy(bundle.build(), fos);
} finally {
close(fos);
}
FileInputStream fis = null;
JarInputStream jis = null;
try {
fis = new FileInputStream(file);
jis = new JarInputStream(fis);
Map<String, String> headers = new HashMap<String, String>();
for (Map.Entry<Object, Object> entry : jis.getManifest().getMainAttributes().entrySet()) {
headers.put(entry.getKey().toString(), entry.getValue().toString());
}
return new BundleDescriptor(bundle.getClass().getClassLoader(), new URL("jar:" + file.toURI().toString() + "!/"), headers);
} finally {
close(fis, jis);
}
}
use of java.util.jar.JarInputStream in project aries by apache.
the class BundleManifestTest method testZipWithName.
@Test
public void testZipWithName() throws Exception {
// make sure that the manifest is not the first file in the jar archive
JarInputStream jarIs = new JarInputStream(new FileInputStream(BUNDLE_WITH_NAME_HEADER));
assertNull(jarIs.getManifest());
jarIs.close();
BundleManifest sut = BundleManifest.fromBundle(BUNDLE_WITH_NAME_HEADER);
assertEquals(EXPECTED_SYMBOLIC_NAME, sut.getSymbolicName());
assertEquals(EXPECTED_VERSION, sut.getVersion().toString());
}
use of java.util.jar.JarInputStream in project aries by apache.
the class BundleManifestTest method testZipFromIDirectory.
@Test
public void testZipFromIDirectory() throws Exception {
// make sure that the manifest is not the first file in the jar archive
JarInputStream jarIs = new JarInputStream(new FileInputStream(BUNDLE_WITHOUT_NAME_HEADER));
assertNull(jarIs.getManifest());
jarIs.close();
BundleManifest sut = BundleManifest.fromBundle(FileSystem.getFSRoot(BUNDLE_WITHOUT_NAME_HEADER));
assertEquals(EXPECTED_SYMBOLIC_NAME, sut.getSymbolicName());
assertEquals(EXPECTED_VERSION, sut.getVersion().toString());
}
Aggregations