Search in sources :

Example 71 with JarOutputStream

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);
    }
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) ByteArrayInputStream(java.io.ByteArrayInputStream) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) BufferedOutputStream(java.io.BufferedOutputStream)

Example 72 with JarOutputStream

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);
    }
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) ByteArrayInputStream(java.io.ByteArrayInputStream) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) BufferedOutputStream(java.io.BufferedOutputStream)

Example 73 with JarOutputStream

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;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) Artifact(org.apache.maven.artifact.Artifact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RunMode(org.apache.sling.provisioning.model.RunMode) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ArtifactGroup(org.apache.sling.provisioning.model.ArtifactGroup)

Example 74 with JarOutputStream

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();
}
Also used : JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry)

Example 75 with JarOutputStream

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);
}
Also used : FileOutputStream(java.io.FileOutputStream) Attributes(java.util.jar.Attributes) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest)

Aggregations

JarOutputStream (java.util.jar.JarOutputStream)485 FileOutputStream (java.io.FileOutputStream)308 File (java.io.File)265 JarEntry (java.util.jar.JarEntry)194 Manifest (java.util.jar.Manifest)140 IOException (java.io.IOException)130 ZipEntry (java.util.zip.ZipEntry)116 InputStream (java.io.InputStream)89 FileInputStream (java.io.FileInputStream)84 JarFile (java.util.jar.JarFile)82 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 ByteArrayInputStream (java.io.ByteArrayInputStream)55 Test (org.junit.Test)55 BufferedOutputStream (java.io.BufferedOutputStream)47 Path (java.nio.file.Path)42 JarInputStream (java.util.jar.JarInputStream)41 OutputStream (java.io.OutputStream)36 Attributes (java.util.jar.Attributes)36 ArrayList (java.util.ArrayList)35 Map (java.util.Map)27