use of java.util.jar.JarOutputStream in project bytecode-viewer by Konloch.
the class JarArchive method write.
public void write(File target) {
try (JarOutputStream output = (manifest != null ? new JarOutputStream(new FileOutputStream(target), manifest) : new JarOutputStream(new FileOutputStream(target)))) {
for (Map.Entry<String, ClassNode> entry : build().entrySet()) {
output.putNextEntry(new JarEntry(entry.getKey().replaceAll("\\.", "/") + ".class"));
ClassWriter writer = new ClassWriter(0);
entry.getValue().accept(writer);
output.write(writer.toByteArray());
output.closeEntry();
}
output.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
use of java.util.jar.JarOutputStream in project J2ME-Loader by nikita36078.
the class AndroidProducer method processJar.
public static void processJar(File jarInputFile, File jarOutputFile, boolean isMidlet) throws IOException {
JarInputStream jis = null;
JarOutputStream jos = null;
HashMap<String, byte[]> resources = new HashMap<>();
try {
jis = new JarInputStream(new FileInputStream(jarInputFile));
Manifest manifest = jis.getManifest();
if (manifest == null) {
jos = new JarOutputStream(new FileOutputStream(jarOutputFile));
} else {
Attributes attributes = manifest.getMainAttributes();
if (!attributes.containsKey(Attributes.Name.MANIFEST_VERSION)) {
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
}
jos = new JarOutputStream(new FileOutputStream(jarOutputFile), manifest);
}
byte[] buffer = new byte[1024];
JarEntry jarEntry;
while ((jarEntry = jis.getNextJarEntry()) != null) {
if (!jarEntry.isDirectory()) {
String name = jarEntry.getName();
int size = 0;
int read;
int length = buffer.length;
while ((read = jis.read(buffer, size, length)) > 0) {
size += read;
length = 1024;
if (size + length > buffer.length) {
byte[] newInputBuffer = new byte[size + length];
System.arraycopy(buffer, 0, newInputBuffer, 0, buffer.length);
buffer = newInputBuffer;
}
}
byte[] inBuffer = new byte[size];
System.arraycopy(buffer, 0, inBuffer, 0, size);
resources.put(name, inBuffer);
if (name.endsWith(".class")) {
analyze(name.substring(0, name.length() - ".class".length()), new ByteArrayInputStream(inBuffer));
}
}
}
for (String name : resources.keySet()) {
byte[] inBuffer = resources.get(name);
byte[] outBuffer = inBuffer;
if (name.endsWith(".class")) {
outBuffer = instrument(name, new ByteArrayInputStream(inBuffer), isMidlet);
}
jos.putNextEntry(new JarEntry(name));
jos.write(outBuffer);
}
} finally {
if (jis != null) {
jis.close();
}
if (jos != null) {
jos.close();
}
}
}
use of java.util.jar.JarOutputStream in project Lucee by lucee.
the class Pack200Util method pack2Jar.
public static void pack2Jar(InputStream is, OutputStream os, boolean closeIS, boolean closeOS) throws IOException {
Unpacker unpacker = Pack200.newUnpacker();
SortedMap<String, String> p = unpacker.properties();
p.put(Unpacker.DEFLATE_HINT, Unpacker.TRUE);
is = new GZIPInputStream(is);
JarOutputStream jos = null;
try {
jos = new JarOutputStream(os);
unpacker.unpack(is, jos);
jos.finish();
} finally {
if (closeIS)
IOUtil.closeEL(is);
if (closeOS)
IOUtil.closeEL(jos);
}
}
use of java.util.jar.JarOutputStream in project Lucee by lucee.
the class Pack200Util method pack2Jar.
public static void pack2Jar(InputStream is, OutputStream os, boolean closeIS, boolean closeOS) throws IOException {
Unpacker unpacker = Pack200.newUnpacker();
SortedMap<String, String> p = unpacker.properties();
p.put(Unpacker.DEFLATE_HINT, Unpacker.TRUE);
is = new GZIPInputStream(is);
JarOutputStream jos = null;
try {
jos = new JarOutputStream(os);
unpacker.unpack(is, jos);
jos.finish();
} finally {
if (closeIS)
Util.closeEL(is);
if (closeOS)
Util.closeEL(jos);
}
}
use of java.util.jar.JarOutputStream in project knime-core by knime.
the class StringManipulatorProvider method getJarFile.
/**
* Give jar file with all *.class files returned by
* getManipulators(ALL_CATEGORY).
*
* @return file object of a jar file with all compiled manipulators
* @throws IOException if jar file cannot be created
*/
public synchronized File getJarFile() throws IOException {
if (m_jarFile == null || !m_jarFile.exists()) {
// Temp file must not be associated with a node therefore we need to specify the base directory
// explicitly.
m_jarFile = FileUtil.createTempFile("jsnippet-manipulators", ".jar", new File(KNIMEConstants.getKNIMETempDir()), true);
Collection<Object> classes = new ArrayList<Object>();
classes.add(Manipulator.class);
classes.addAll(m_manipulators.get(ALL_CATEGORY));
// create tree structure for classes
DefaultMutableTreeNode root = createTree(classes);
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(m_jarFile))) {
createJar(root, jar, null);
}
}
return m_jarFile;
}
Aggregations