use of java.util.jar.JarEntry 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.JarEntry 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.JarEntry 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();
}
}
use of java.util.jar.JarEntry in project weave by continuuity.
the class ApplicationBundler method saveEntry.
/**
* Saves a class entry to the jar output.
*/
private void saveEntry(String entry, URL url, Set<String> entries, JarOutputStream jarOut, boolean compress) {
if (!entries.add(entry)) {
return;
}
try {
JarEntry jarEntry = new JarEntry(entry);
InputStream is = url.openStream();
try {
if (compress) {
jarOut.putNextEntry(jarEntry);
ByteStreams.copy(is, jarOut);
} else {
crc32.reset();
TransferByteOutputStream os = new TransferByteOutputStream();
CheckedOutputStream checkedOut = new CheckedOutputStream(os, crc32);
ByteStreams.copy(is, checkedOut);
checkedOut.close();
long size = os.size();
jarEntry.setMethod(JarEntry.STORED);
jarEntry.setSize(size);
jarEntry.setCrc(checkedOut.getChecksum().getValue());
jarOut.putNextEntry(jarEntry);
os.transfer(jarOut);
}
} finally {
is.close();
}
jarOut.closeEntry();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of java.util.jar.JarEntry in project crunch by cloudera.
the class WordCountHBaseTest method jarUp.
private void jarUp(JarOutputStream jos, File baseDir, String classDir) throws IOException {
File file = new File(baseDir, classDir);
JarEntry e = new JarEntry(classDir);
e.setTime(file.lastModified());
jos.putNextEntry(e);
ByteStreams.copy(new FileInputStream(file), jos);
jos.closeEntry();
}
Aggregations