use of java.util.jar.JarInputStream in project gocd by gocd.
the class TfsSDKCommandBuilderTest method implementationVersionFromManifrest.
private String implementationVersionFromManifrest(URL log4jJarFromClasspath) throws IOException {
JarInputStream in = new JarInputStream(log4jJarFromClasspath.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
in.getManifest().write(out);
out.close();
List<String> lines = IOUtils.readLines(new ByteArrayInputStream(out.toByteArray()));
for (String line : lines) {
if (line.startsWith("Implementation-Version")) {
return line.split(":")[1].trim();
}
}
return null;
}
use of java.util.jar.JarInputStream in project hibernate-orm by hibernate.
the class JarFileBasedArchiveDescriptor method visitArchive.
@Override
public void visitArchive(ArchiveContext context) {
final JarFile jarFile = resolveJarFileReference();
if (jarFile == null) {
return;
}
final Enumeration<? extends ZipEntry> zipEntries = jarFile.entries();
while (zipEntries.hasMoreElements()) {
final ZipEntry zipEntry = zipEntries.nextElement();
final String entryName = extractName(zipEntry);
if (getEntryBasePrefix() != null && !entryName.startsWith(getEntryBasePrefix())) {
continue;
}
if (zipEntry.isDirectory()) {
continue;
}
if (entryName.equals(getEntryBasePrefix())) {
// just any random entry
try (InputStream is = new BufferedInputStream(jarFile.getInputStream(zipEntry))) {
final JarInputStream jarInputStream = new JarInputStream(is);
ZipEntry subZipEntry = jarInputStream.getNextEntry();
while (subZipEntry != null) {
if (!subZipEntry.isDirectory()) {
final String name = extractName(subZipEntry);
final String relativeName = extractRelativeName(subZipEntry);
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess(name, jarInputStream);
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler(entry);
entryHandler.handleEntry(entry, context);
}
subZipEntry = jarInputStream.getNextEntry();
}
} catch (Exception e) {
throw new ArchiveException("Error accessing JarFile entry [" + zipEntry.getName() + "]", e);
}
} else {
final String name = extractName(zipEntry);
final String relativeName = extractRelativeName(zipEntry);
final InputStreamAccess inputStreamAccess;
try (InputStream is = jarFile.getInputStream(zipEntry)) {
inputStreamAccess = buildByteBasedInputStreamAccess(name, is);
} catch (IOException e) {
throw new ArchiveException(String.format("Unable to access stream from jar file [%s] for entry [%s]", jarFile.getName(), zipEntry.getName()));
}
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler(entry);
entryHandler.handleEntry(entry, context);
}
}
}
use of java.util.jar.JarInputStream in project lwjgl by LWJGL.
the class StandalonePublisher method readBundle.
protected BundleInfo readBundle(File location) throws ParserConfigurationException {
BundleInfo info = new BundleInfo();
info.jarFile = location;
info.size = (int) location.length();
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
JarInputStream jis = null;
try {
jis = new JarInputStream(new FileInputStream(location));
info.manifest = jis.getManifest();
JarEntry jarEntry;
while ((jarEntry = jis.getNextJarEntry()) != null) {
if (!jarEntry.isDirectory() && "plugin.xml".equals(jarEntry.getName())) {
Document doc = readXMLinJar(docBuilder, jis, jarEntry);
info.doc = doc;
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (jis != null)
try {
jis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return info;
}
use of java.util.jar.JarInputStream in project OpenAM by OpenRock.
the class TestHarness method getTestClasses.
public static void getTestClasses(ServletContext servletContext, Map map) {
JarInputStream in = null;
try {
in = new JarInputStream(servletContext.getResourceAsStream("WEB-INF/lib/unittest.jar"));
JarEntry jarEntry = in.getNextJarEntry();
while (jarEntry != null) {
String name = jarEntry.getName();
if (name.endsWith(".class") && (name.indexOf("$") == -1)) {
name = name.replaceAll("/", ".");
int idx = name.lastIndexOf('.');
name = name.substring(0, idx);
idx = name.lastIndexOf('.');
String pkgName = name.substring(0, idx);
if (!pkgName.equals("com.sun.identity.unittest")) {
Set set = (Set) map.get(pkgName);
if (set == null) {
set = new TreeSet();
map.put(pkgName, set);
}
set.add(name);
}
}
jarEntry = in.getNextJarEntry();
}
} catch (IOException e) {
UnittestLog.logError("TestHarness.getTestClasses: failed", e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
//ignore
}
}
}
}
use of java.util.jar.JarInputStream in project OpenAM by OpenRock.
the class FilesDigester method digestJarFile.
/**
* This function calculate the hash value of a jar file.
*
* This function handles the jar file as a concatenation of the decompressed
* files it contains.
*
* @param hashAlg The algorithm to be used for calculating the hash.
* @param in The InputStream of the jar file to be processed.
*/
protected byte[] digestJarFile(String hashAlg, InputStream in) {
JarInputStream jin = null;
try {
jin = new JarInputStream(in);
JarEntry je = null;
MessageDigest md = MessageDigest.getInstance(hashAlg);
while ((je = jin.getNextJarEntry()) != null) {
if (!je.isDirectory()) {
md = Utils.hashing(md, jin);
}
jin.closeEntry();
}
jin.close();
return md.digest();
} catch (IOException ex) {
ex.printStackTrace();
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
} finally {
if (jin != null) {
try {
jin.close();
} catch (IOException ignored) {
}
jin = null;
}
}
return null;
}
Aggregations