use of java.util.jar.JarInputStream in project camel by apache.
the class DefaultPackageScanClassResolver method doLoadJarClassEntries.
/**
* Loads all the class entries from the JAR.
*
* @param stream the inputstream of the jar file to be examined for classes
* @param urlPath the url of the jar file to be examined for classes
* @return all the .class entries from the JAR
*/
protected List<String> doLoadJarClassEntries(InputStream stream, String urlPath) {
List<String> entries = new ArrayList<String>();
JarInputStream jarStream = null;
try {
jarStream = new JarInputStream(stream);
JarEntry entry;
while ((entry = jarStream.getNextJarEntry()) != null) {
String name = entry.getName();
if (name != null) {
name = name.trim();
if (!entry.isDirectory() && name.endsWith(".class")) {
entries.add(name);
}
}
}
} catch (IOException ioe) {
log.warn("Cannot search jar file '" + urlPath + " due to an IOException: " + ioe.getMessage(), ioe);
} finally {
IOHelper.close(jarStream, urlPath, log);
}
return entries;
}
use of java.util.jar.JarInputStream in project hbase by apache.
the class ClassFinder method findClassesFromJar.
private Set<Class<?>> findClassesFromJar(String jarFileName, String packageName, boolean proceedOnExceptions) throws IOException, ClassNotFoundException, LinkageError {
JarInputStream jarFile = null;
try {
jarFile = new JarInputStream(new FileInputStream(jarFileName));
} catch (IOException ioEx) {
LOG.warn("Failed to look for classes in " + jarFileName + ": " + ioEx);
throw ioEx;
}
Set<Class<?>> classes = new HashSet<>();
JarEntry entry = null;
try {
while (true) {
try {
entry = jarFile.getNextJarEntry();
} catch (IOException ioEx) {
if (!proceedOnExceptions) {
throw ioEx;
}
LOG.warn("Failed to get next entry from " + jarFileName + ": " + ioEx);
break;
}
if (entry == null) {
// loop termination condition
break;
}
String className = entry.getName();
if (!className.endsWith(CLASS_EXT)) {
continue;
}
int ix = className.lastIndexOf('/');
String fileName = (ix >= 0) ? className.substring(ix + 1) : className;
if (null != this.fileNameFilter && !this.fileNameFilter.isCandidateFile(fileName, className)) {
continue;
}
className = className.substring(0, className.length() - CLASS_EXT.length()).replace('/', '.');
if (!className.startsWith(packageName)) {
continue;
}
Class<?> c = makeClass(className, proceedOnExceptions);
if (c != null) {
if (!classes.add(c)) {
LOG.warn("Ignoring duplicate class " + className);
}
}
}
return classes;
} finally {
jarFile.close();
}
}
use of java.util.jar.JarInputStream in project tomcat by apache.
the class JarWarResource method getJarInputStreamWrapper.
@Override
protected JarInputStreamWrapper getJarInputStreamWrapper() {
JarFile warFile = null;
JarInputStream jarIs = null;
JarEntry entry = null;
try {
warFile = getArchiveResourceSet().openJarFile();
JarEntry jarFileInWar = warFile.getJarEntry(archivePath);
InputStream isInWar = warFile.getInputStream(jarFileInWar);
jarIs = new JarInputStream(isInWar);
entry = jarIs.getNextJarEntry();
while (entry != null && !entry.getName().equals(getResource().getName())) {
entry = jarIs.getNextJarEntry();
}
if (entry == null) {
return null;
}
return new JarInputStreamWrapper(entry, jarIs);
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("jarResource.getInputStreamFail", getResource().getName(), getBaseUrl()), e);
}
return null;
} finally {
if (entry == null) {
if (jarIs != null) {
try {
jarIs.close();
} catch (IOException ioe) {
// Ignore
}
}
if (warFile != null) {
getArchiveResourceSet().closeJarFile();
}
}
}
}
use of java.util.jar.JarInputStream in project weave by continuuity.
the class WeaveLauncher method unJar.
private static void unJar(File jarFile, File targetDir) throws IOException {
JarInputStream jarInput = new JarInputStream(new FileInputStream(jarFile));
try {
JarEntry jarEntry = jarInput.getNextJarEntry();
while (jarEntry != null) {
File target = new File(targetDir, jarEntry.getName());
if (jarEntry.isDirectory()) {
target.mkdirs();
} else {
target.getParentFile().mkdirs();
copy(jarInput, target);
}
jarEntry = jarInput.getNextJarEntry();
}
} finally {
jarInput.close();
}
}
use of java.util.jar.JarInputStream in project weave by continuuity.
the class ApplicationBundlerTest method unjar.
private void unjar(File jarFile, File targetDir) throws IOException {
JarInputStream jarInput = new JarInputStream(new FileInputStream(jarFile));
try {
JarEntry jarEntry = jarInput.getNextJarEntry();
while (jarEntry != null) {
File target = new File(targetDir, jarEntry.getName());
if (jarEntry.isDirectory()) {
target.mkdirs();
} else {
target.getParentFile().mkdirs();
ByteStreams.copy(jarInput, Files.newOutputStreamSupplier(target));
}
jarEntry = jarInput.getNextJarEntry();
}
} finally {
jarInput.close();
}
}
Aggregations