use of java.util.jar.JarOutputStream in project elasticsearch by elastic.
the class JarHellTests method makeJar.
URL makeJar(Path dir, String name, Manifest manifest, String... files) throws IOException {
Path jarpath = dir.resolve(name);
ZipOutputStream out;
if (manifest == null) {
out = new JarOutputStream(Files.newOutputStream(jarpath, StandardOpenOption.CREATE));
} else {
out = new JarOutputStream(Files.newOutputStream(jarpath, StandardOpenOption.CREATE), manifest);
}
for (String file : files) {
out.putNextEntry(new ZipEntry(file));
}
out.close();
return jarpath.toUri().toURL();
}
use of java.util.jar.JarOutputStream in project buck by facebook.
the class ClassNodeListSupplierTest method testOneJar.
@Test
public void testOneJar() throws IOException {
File jar = new File(tmpDir.getRoot(), "primary.jar");
ZipOutputStream jarOut = new JarOutputStream(new FileOutputStream(jar));
jarOut.putNextEntry(new JarEntry("com/facebook/buck/android/ClassNodeListSupplierTest.class"));
writeClassBytes(ClassNodeListSupplierTest.class, jarOut);
jarOut.close();
Supplier<ImmutableList<ClassNode>> supplier = ClassNodeListSupplier.createMemoized(ImmutableList.of(jar.toPath()));
ImmutableList<ClassNode> classNodes = supplier.get();
assertEquals(1, classNodes.size());
assertEquals(Type.getType(ClassNodeListSupplierTest.class).getInternalName(), classNodes.get(0).name);
// Memoized should always return the same object
assertSame(classNodes, supplier.get());
}
use of java.util.jar.JarOutputStream in project jetty.project by eclipse.
the class WarURLConnection method substitueManifest.
/**
* Use PipedOuputStream and PipedInputStream to do the transformation without making
* a new temporary file ust to replace the manifest.
* @param newmanifest The new manifest
* @param rawIn The file input stream or equivalent. not the jar input stream.
*/
public static InputStream substitueManifest(final Manifest newmanifest, final InputStream rawIn) throws IOException {
final PipedOutputStream pOut = new PipedOutputStream();
PipedInputStream pIn = new PipedInputStream(pOut);
Runnable run = new Runnable() {
public void run() {
JarInputStream jin = null;
JarOutputStream dest = null;
try {
jin = new JarInputStream(rawIn, false);
dest = new JarOutputStream(pOut, newmanifest);
ZipEntry next = jin.getNextEntry();
while (next != null) {
if (next.getName().equalsIgnoreCase(JarFile.MANIFEST_NAME)) {
continue;
}
dest.putNextEntry(next);
if (next.getSize() > 0) {
IO.copy(jin, dest, next.getSize());
}
next = jin.getNextJarEntry();
}
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (dest != null)
IO.close(dest);
if (jin != null)
IO.close(jin);
IO.close(pOut);
}
}
};
Thread th = new Thread(run);
th.start();
return pIn;
}
use of java.util.jar.JarOutputStream in project weave by continuuity.
the class YarnWeavePreparer method saveLauncher.
/**
* Creates the launcher.jar for launch the main application.
*/
private void saveLauncher(Map<String, LocalFile> localFiles) throws URISyntaxException, IOException {
LOG.debug("Create and copy {}", Constants.Files.LAUNCHER_JAR);
Location location = createTempLocation(Constants.Files.LAUNCHER_JAR);
final String launcherName = WeaveLauncher.class.getName();
// Create a jar file with the WeaveLauncher optionally a json serialized classpath.json in it.
final JarOutputStream jarOut = new JarOutputStream(location.getOutputStream());
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
Dependencies.findClassDependencies(classLoader, new Dependencies.ClassAcceptor() {
@Override
public boolean accept(String className, URL classUrl, URL classPathUrl) {
Preconditions.checkArgument(className.startsWith(launcherName), "Launcher jar should not have dependencies: %s", className);
try {
jarOut.putNextEntry(new JarEntry(className.replace('.', '/') + ".class"));
InputStream is = classUrl.openStream();
try {
ByteStreams.copy(is, jarOut);
} finally {
is.close();
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
return true;
}
}, WeaveLauncher.class.getName());
try {
if (!classPaths.isEmpty()) {
jarOut.putNextEntry(new JarEntry("classpath"));
jarOut.write(Joiner.on(':').join(classPaths).getBytes(Charsets.UTF_8));
}
} finally {
jarOut.close();
}
LOG.debug("Done {}", Constants.Files.LAUNCHER_JAR);
localFiles.put(Constants.Files.LAUNCHER_JAR, createLocalFile(Constants.Files.LAUNCHER_JAR, location));
}
use of java.util.jar.JarOutputStream in project jersey by jersey.
the class JarUtils method createJarFile.
public static File createJarFile(final String name, final Suffix s, final String base, final Map<String, String> entries) throws IOException {
final File tempJar = File.createTempFile(name, "." + s);
tempJar.deleteOnExit();
final JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)), new Manifest());
final Set<String> usedSegments = new HashSet<String>();
for (final Map.Entry<String, String> entry : entries.entrySet()) {
for (final String path : getPaths(entry.getValue())) {
if (usedSegments.contains(path)) {
continue;
}
usedSegments.add(path);
final JarEntry e = new JarEntry(path);
jos.putNextEntry(e);
jos.closeEntry();
}
final JarEntry e = new JarEntry(entry.getValue());
jos.putNextEntry(e);
final InputStream f = new BufferedInputStream(new FileInputStream(base + entry.getKey()));
final byte[] buf = new byte[1024];
int read = 1024;
while ((read = f.read(buf, 0, read)) != -1) {
jos.write(buf, 0, read);
}
jos.closeEntry();
}
jos.close();
return tempJar;
}
Aggregations