use of java.util.jar.JarEntry 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.JarEntry in project storm by apache.
the class Utils method extractDirFromJarImpl.
public void extractDirFromJarImpl(String jarpath, String dir, File destdir) {
try (JarFile jarFile = new JarFile(jarpath)) {
Enumeration<JarEntry> jarEnums = jarFile.entries();
while (jarEnums.hasMoreElements()) {
JarEntry entry = jarEnums.nextElement();
if (!entry.isDirectory() && entry.getName().startsWith(dir)) {
File aFile = new File(destdir, entry.getName());
aFile.getParentFile().mkdirs();
try (FileOutputStream out = new FileOutputStream(aFile);
InputStream in = jarFile.getInputStream(entry)) {
IOUtils.copy(in, out);
}
}
}
} catch (IOException e) {
LOG.info("Could not extract {} from {}", dir, jarpath);
}
}
use of java.util.jar.JarEntry in project storm by apache.
the class DefaultShader method addRemappedClass.
private void addRemappedClass(RelocatorRemapper remapper, JarOutputStream jos, String name, InputStream is) throws IOException {
LOG.debug("Remapping class... " + name);
if (!remapper.hasRelocators()) {
try {
LOG.debug("Just copy class...");
jos.putNextEntry(new JarEntry(name));
IOUtil.copy(is, jos);
} catch (ZipException e) {
LOG.info("zip exception ", e);
}
return;
}
ClassReader cr = new ClassReader(is);
// We don't pass the ClassReader here. This forces the ClassWriter to rebuild the constant pool.
// Copying the original constant pool should be avoided because it would keep references
// to the original class names. This is not a problem at runtime (because these entries in the
// constant pool are never used), but confuses some tools such as Felix' maven-bundle-plugin
// that use the constant pool to determine the dependencies of a class.
ClassWriter cw = new ClassWriter(0);
final String pkg = name.substring(0, name.lastIndexOf('/') + 1);
ClassVisitor cv = new RemappingClassAdapter(cw, remapper) {
@Override
public void visitSource(final String source, final String debug) {
LOG.debug("visitSource " + source);
if (source == null) {
super.visitSource(source, debug);
} else {
final String fqSource = pkg + source;
final String mappedSource = remapper.map(fqSource);
final String filename = mappedSource.substring(mappedSource.lastIndexOf('/') + 1);
LOG.debug("Remapped to " + filename);
super.visitSource(filename, debug);
}
}
};
try {
cr.accept(cv, ClassReader.EXPAND_FRAMES);
} catch (Throwable ise) {
throw new IOException("Error in ASM processing class " + name, ise);
}
byte[] renamedClass = cw.toByteArray();
// Need to take the .class off for remapping evaluation
String mappedName = remapper.map(name.substring(0, name.indexOf('.')));
LOG.debug("Remapped class name to " + mappedName);
try {
// Now we put it back on so the class file is written out with the right extension.
jos.putNextEntry(new JarEntry(mappedName + ".class"));
jos.write(renamedClass);
} catch (ZipException e) {
LOG.info("zip exception ", e);
}
}
use of java.util.jar.JarEntry in project storm by apache.
the class DefaultShader method addJavaSource.
private void addJavaSource(Set<String> resources, JarOutputStream jos, String name, InputStream is, List<Relocator> relocators) throws IOException {
jos.putNextEntry(new JarEntry(name));
String sourceContent = IOUtil.toString(new InputStreamReader(is, "UTF-8"));
for (Relocator relocator : relocators) {
sourceContent = relocator.applyToSourceContent(sourceContent);
}
OutputStreamWriter writer = new OutputStreamWriter(jos, "UTF-8");
writer.append(sourceContent);
writer.flush();
resources.add(name);
}
use of java.util.jar.JarEntry in project storm by apache.
the class DefaultShader method addDirectory.
private void addDirectory(Set<String> resources, JarOutputStream jos, String name) throws IOException {
if (name.lastIndexOf('/') > 0) {
String parent = name.substring(0, name.lastIndexOf('/'));
if (!resources.contains(parent)) {
addDirectory(resources, jos, parent);
}
}
// directory entries must end in "/"
JarEntry entry = new JarEntry(name + "/");
LOG.debug("Adding JAR directory " + entry);
jos.putNextEntry(entry);
resources.add(name);
}
Aggregations