use of java.util.jar.JarOutputStream in project felix by apache.
the class StartStopBundleTest method createBundle.
private static File createBundle(String manifest, File tempDir) throws IOException {
File f = File.createTempFile("felix-bundle", ".jar", tempDir);
Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
mf.getMainAttributes().putValue("Manifest-Version", "1.0");
mf.getMainAttributes().putValue(Constants.BUNDLE_ACTIVATOR, TestBundleActivator.class.getName());
JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
String path = TestBundleActivator.class.getName().replace('.', '/') + ".class";
os.putNextEntry(new ZipEntry(path));
InputStream is = TestBundleActivator.class.getClassLoader().getResourceAsStream(path);
byte[] b = new byte[is.available()];
is.read(b);
is.close();
os.write(b);
os.close();
return f;
}
use of java.util.jar.JarOutputStream in project felix by apache.
the class BundleCacheTest method createJar.
private void createJar(File source, File target) throws Exception {
File tmp = File.createTempFile("bundle", ".jar", filesDir);
JarOutputStream output;
if (new File(source, "META-INF/MANIFEST.MF").isFile()) {
output = new JarOutputStream(new FileOutputStream(tmp), new Manifest(new FileInputStream(new File(source, "META-INF/MANIFEST.MF"))));
} else {
output = new JarOutputStream(new FileOutputStream(tmp));
}
writeRecursive(source, "", output);
output.close();
target.delete();
tmp.renameTo(target);
}
use of java.util.jar.JarOutputStream in project jphp by jphp-compiler.
the class StandaloneCompiler method compileJar.
public void compileJar(File jarFile, File destinationDirectory, String mainClassName) throws IOException, InterruptedException {
Manifest manifest = null;
if (mainClassName != null) {
manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_TITLE, Information.NAME + " Compiler");
manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VENDOR, Information.NAME);
manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VERSION, Information.CORE_VERSION);
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, mainClassName);
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, "jphp-runtime.jar");
}
try (FileOutputStream outputStream = new FileOutputStream(jarFile)) {
JarOutputStream jarOutputStream = manifest != null ? new JarOutputStream(outputStream, manifest) : new JarOutputStream(outputStream);
try {
scan(destinationDirectory, new Callback<Boolean, File>() {
@Override
public Boolean call(File file) {
Path relPath = destinationDirectory.toPath().relativize(file.toPath());
String name = relPath.toString().replace('\\', '/');
try {
if (file.isFile()) {
JarEntry jarEntry = new JarEntry(name);
jarEntry.setTime(file.lastModified());
jarOutputStream.putNextEntry(jarEntry);
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
byte[] buffer = new byte[1024 * 32];
while (true) {
int count = in.read(buffer);
if (count == -1) {
break;
}
jarOutputStream.write(buffer, 0, count);
}
jarOutputStream.closeEntry();
}
} else if (file.isDirectory()) {
JarEntry jarEntry = new JarEntry(name);
jarEntry.setTime(file.lastModified());
jarOutputStream.putNextEntry(jarEntry);
jarOutputStream.closeEntry();
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
});
} catch (InterruptedException e) {
// nop.
}
jarOutputStream.close();
}
}
use of java.util.jar.JarOutputStream in project xtext-eclipse by eclipse.
the class CreateJar method invoke.
@Override
public void invoke(IWorkflowContext ctx) {
try {
File binDirectory = new File(binPath + "/" + packagePath);
if (!binDirectory.exists())
throw new RuntimeException(binPath + "/" + packagePath);
File targetDirectory = new File(targetDir);
if (!targetDirectory.exists())
throw new RuntimeException(targetDir);
File zipFile = new File(targetDirectory, "testData.jar");
if (!zipFile.exists())
zipFile.createNewFile();
JarOutputStream outputStream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
try {
String packagePathInJar = packagePath + "/";
for (File classFile : binDirectory.listFiles()) {
if (classFile.isFile() && classFile.getName().endsWith(".class") && !classFile.getName().endsWith("$RemoveMe.class")) {
addToJar(packagePathInJar, classFile, outputStream);
}
}
File rootBindDirectoy = new File(binPath);
File classFileWithoutPackage = new File(rootBindDirectoy, "ClassWithDefaultPackage.class");
if (classFileWithoutPackage.isFile()) {
addToJar("", classFileWithoutPackage, outputStream);
}
} finally {
outputStream.close();
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
use of java.util.jar.JarOutputStream in project xtext-eclipse by eclipse.
the class JavaProjectSetupUtil method jarInputStream.
public static InputStream jarInputStream(@SuppressWarnings("unchecked") Pair<String, InputStream>... entries) {
try {
ByteArrayOutputStream out2 = new ByteArrayOutputStream();
JarOutputStream jo = new JarOutputStream(new BufferedOutputStream(out2));
for (Pair<String, InputStream> entry : entries) {
JarEntry je = new JarEntry(entry.getKey());
jo.putNextEntry(je);
ByteStreams.copy(entry.getValue(), jo);
}
jo.close();
return new ByteArrayInputStream(out2.toByteArray());
} catch (IOException e) {
throw new WrappedException(e);
}
}
Aggregations