use of java.util.jar.JarOutputStream in project xtext-eclipse by eclipse.
the class JavaProjectSetupUtil method jarInputStream.
/**
* creates a JarInputStream containing the passed text files. Each Pair<String
*/
public static InputStream jarInputStream(TextFile... files) {
try {
ByteArrayOutputStream out2 = new ByteArrayOutputStream();
JarOutputStream jo = new JarOutputStream(new BufferedOutputStream(out2));
for (TextFile textFile : files) {
JarEntry je = new JarEntry(textFile.path);
jo.putNextEntry(je);
byte[] bytes = textFile.content.getBytes();
jo.write(bytes, 0, bytes.length);
}
jo.close();
return new ByteArrayInputStream(out2.toByteArray());
} catch (IOException e) {
throw new WrappedException(e);
}
}
use of java.util.jar.JarOutputStream in project xtext-eclipse by eclipse.
the class JavaProjectSetupUtil method jarInputStream.
/**
* creates a JarInputStream containing the passed text files. Each Pair<String
*/
public static InputStream jarInputStream(TextFile... files) {
try {
ByteArrayOutputStream out2 = new ByteArrayOutputStream();
JarOutputStream jo = new JarOutputStream(new BufferedOutputStream(out2));
for (TextFile textFile : files) {
JarEntry je = new JarEntry(textFile.path);
jo.putNextEntry(je);
byte[] bytes = textFile.content.getBytes();
jo.write(bytes, 0, bytes.length);
}
jo.close();
return new ByteArrayInputStream(out2.toByteArray());
} catch (IOException e) {
throw new WrappedException(e);
}
}
use of java.util.jar.JarOutputStream in project sling by apache.
the class PreparePackageMojo method createSubsystemBaseFile.
private File createSubsystemBaseFile(Feature feature, AtomicInteger startLevelHolder) throws MojoExecutionException {
File subsystemFile = new File(getTmpDir(), feature.getName() + ".subsystem-base");
if (subsystemFile.exists()) {
// TODO is there a better way to avoid calling this multiple times?
return null;
}
startLevelHolder.set(-1);
// The runmodes information has to be the first item in the archive so that we always have it available when the
// archive is being processed. For this reason a Jar file is used here as it's guaranteed to store the manifest
// first.
Manifest runModesManifest = getRunModesManifest(feature);
getLog().info("Creating subsystem base file: " + subsystemFile.getName());
boolean created = subsystemFile.getParentFile().mkdirs();
if (!created) {
throw new MojoExecutionException("Failed creating " + subsystemFile.getParentFile().getAbsolutePath());
}
try (JarOutputStream os = new JarOutputStream(new FileOutputStream(subsystemFile), runModesManifest)) {
Map<String, Integer> bsnStartOrderMap = new HashMap<>();
for (RunMode rm : feature.getRunModes()) {
for (ArtifactGroup ag : rm.getArtifactGroups()) {
// For subsystems the start level on the artifact group is used as start order.
int startOrder = ag.getStartLevel();
for (org.apache.sling.provisioning.model.Artifact a : ag) {
Artifact artifact = ModelUtils.getArtifact(this.project, this.mavenSession, this.artifactHandlerManager, this.resolver, a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getType(), a.getClassifier());
File artifactFile = artifact.getFile();
String entryName = getEntryName(artifactFile, startOrder);
ZipEntry ze = new ZipEntry(entryName);
try {
os.putNextEntry(ze);
Files.copy(artifactFile.toPath(), os);
} finally {
os.closeEntry();
}
}
}
}
int sl = createSubsystemManifest(feature, bsnStartOrderMap, os);
if (sl != -1)
startLevelHolder.set(sl);
addReadme(os);
} catch (IOException ioe) {
throw new MojoExecutionException("Problem creating subsystem .esa file " + subsystemFile, ioe);
}
return subsystemFile;
}
use of java.util.jar.JarOutputStream in project android_frameworks_base by crdroidandroid.
the class AsmGenerator method createJar.
/**
* Writes the JAR file.
*
* @param outStream The file output stream were to write the JAR.
* @param all The map of all classes to output.
* @throws IOException if an I/O error has occurred
*/
void createJar(FileOutputStream outStream, Map<String, byte[]> all) throws IOException {
JarOutputStream jar = new JarOutputStream(outStream);
for (Entry<String, byte[]> entry : all.entrySet()) {
String name = entry.getKey();
JarEntry jar_entry = new JarEntry(name);
jar.putNextEntry(jar_entry);
jar.write(entry.getValue());
jar.closeEntry();
}
jar.flush();
jar.close();
}
use of java.util.jar.JarOutputStream in project processdash by dtuma.
the class ProcessAssetPackager method openJarOutputStream.
private static JarOutputStream openJarOutputStream() throws IOException {
Manifest mf = new Manifest();
Attributes attrs = mf.getMainAttributes();
attrs.putValue("Manifest-Version", "1.0");
attrs.putValue("Dash-Pkg-ID", packageId);
attrs.putValue("Dash-Pkg-Version", packageVersion);
attrs.putValue("Dash-Pkg-Name", packageName);
return new JarOutputStream(new FileOutputStream(destFile), mf);
}
Aggregations