outputJar.setLevel(9);
/** * Creates the base output stream to which to write our bundle's files. */ protected OutputStream createOutputStream (File target) throws IOException { JarOutputStream jout = new JarOutputStream(new FileOutputStream(target)); jout.setLevel(Deflater.BEST_COMPRESSION); return jout; }
/** * Creates the base output stream to which to write our bundle's files. */ protected OutputStream createOutputStream (File target) throws IOException { JarOutputStream jout = new JarOutputStream(new FileOutputStream(target)); jout.setLevel(Deflater.BEST_COMPRESSION); return jout; }
/** * Opens the exporter and initializes the undelying structures. * * @throws IOException if an I/O error occurs */ public void open() throws IOException { if (jOut == null) { if (jarFile != null) { jOut = new JarOutputStream(new FileOutputStream(jarFile)); jOut.setLevel(level); } else if (out != null) { jOut = new JarOutputStream(out); jOut.setLevel(level); } else { throw new IllegalArgumentException("Either out or jarFile needs to be set."); } } }
/** * Creates the base output stream to which to write our bundle's files. */ protected OutputStream createOutputStream (File target) throws IOException { // make sure the parent directory exists target.getParentFile().mkdirs(); // now create our file JarOutputStream jout = new JarOutputStream(new FileOutputStream(target)); jout.setLevel(uncompressed() ? Deflater.NO_COMPRESSION : Deflater.BEST_COMPRESSION); return jout; }
/** * Creates the base output stream to which to write our bundle's files. */ protected OutputStream createOutputStream (File target) throws IOException { // make sure the parent directory exists target.getParentFile().mkdirs(); // now create our file JarOutputStream jout = new JarOutputStream(new FileOutputStream(target)); jout.setLevel(uncompressed() ? Deflater.NO_COMPRESSION : Deflater.BEST_COMPRESSION); return jout; }
public File create(List<String> classPath, String startClassName, File buildDirectory, String fileName) throws IOException { File file = new File(buildDirectory, fileName); file.deleteOnExit(); FileOutputStream fileOutputStream = new FileOutputStream(file); try (JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream)) { jarOutputStream.setLevel(JarOutputStream.STORED); JarEntry je = new JarEntry("META-INF/MANIFEST.MF"); jarOutputStream.putNextEntry(je); Manifest manifest = new Manifest(); StringBuilder cp = new StringBuilder(); for (String el : classPath) { cp.append(new File(el).toURI().toURL().toExternalForm()).append(" "); } manifest.getMainAttributes().putValue("Manifest-Version", MANIFEST_VERSION); manifest.getMainAttributes().putValue("Class-Path", cp.toString().trim()); manifest.getMainAttributes().putValue("Main-Class", startClassName); manifest.write(jarOutputStream); } return file; }
/** * Creates a {@link SignedJarBuilder} with a given output stream, and signing information. * <p>If either <code>key</code> or <code>certificate</code> is <code>null</code> then * the archive will not be signed. * @param out the {@link OutputStream} where to write the Jar archive. * @param key the {@link PrivateKey} used to sign the archive, or <code>null</code>. * @param certificate the {@link X509Certificate} used to sign the archive, or * <code>null</code>. * @throws IOException * @throws NoSuchAlgorithmException */ public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate) throws IOException, NoSuchAlgorithmException { mOutputJar = new JarOutputStream(new BufferedOutputStream(out)); mOutputJar.setLevel(9); mKey = key; mCertificate = certificate; if (mKey != null && mCertificate != null) { mManifest = new Manifest(); Attributes main = mManifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (Android)"); mBase64Encoder = new BASE64Encoder(); mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM); } }
/** * Creates a {@link SignedJarBuilder} with a given output stream, and signing information. * <p/>If either <code>key</code> or <code>certificate</code> is <code>null</code> then * the archive will not be signed. * * @param out the {@link OutputStream} where to write the Jar archive. * @param key the {@link PrivateKey} used to sign the archive, or <code>null</code>. * @param certificate the {@link X509Certificate} used to sign the archive, or * <code>null</code>. * @throws IOException * @throws NoSuchAlgorithmException */ public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate) throws IOException, NoSuchAlgorithmException { mOutputJar = new JarOutputStream(new BufferedOutputStream(out)); mOutputJar.setLevel(9); mKey = key; mCertificate = certificate; if (mKey != null && mCertificate != null) { mManifest = new Manifest(); Attributes main = mManifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (ApkPatch)"); mBase64Encoder = new BASE64Encoder(); mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM); } }
FileOutputStream fos = new FileOutputStream( file ); JarOutputStream jos = new JarOutputStream( fos ); jos.setLevel( JarOutputStream.STORED ); JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" ); jos.putNextEntry( je );
private JarOutputStream getJarOutputStream(File jarFile) throws IOException { FileUtils.deleteQuietly(jarFile); if (compilerData.isMkdirs()) { FileUtils.forceMkdirParent(jarFile); } FileOutputStream fileOutputStream = new FileOutputStream(jarFile); JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream); int level = compilerData.getComprLevel(); if (level >= 0 && level < 10) { jarOutputStream.setLevel(level); } else { jarOutputStream.setLevel(Deflater.BEST_COMPRESSION); } return jarOutputStream; }
/** * Creates a {@link SignedJarBuilder} with a given output stream, and signing information. * <p>If either <code>key</code> or <code>certificate</code> is <code>null</code> then * the archive will not be signed. * @param out the {@link OutputStream} where to write the Jar archive. * @param key the {@link PrivateKey} used to sign the archive, or <code>null</code>. * @param certificate the {@link X509Certificate} used to sign the archive, or * <code>null</code>. * @throws IOException * @throws NoSuchAlgorithmException */ public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate) throws IOException, NoSuchAlgorithmException { mOutputJar = new JarOutputStream(new BufferedOutputStream(out)); mOutputJar.setLevel(9); mKey = key; mCertificate = certificate; if (mKey != null && mCertificate != null) { mManifest = new Manifest(); Attributes main = mManifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (Android)"); mBase64Encoder = Base64.getMimeEncoder(); mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM); } }
public void write(ZipFile zip, ZipEntry entry) throws IOException { track("A", entry.getName()); boolean changeCompressionLevel = !compressedLevel && CompressionUtil.ENV_SUPPORTS_COMPRESSION_LEVEL_CHANGE; if (changeCompressionLevel) { // The entry to be written is assumed to be incompressible jOut.setLevel(NO_COMPRESSION); } exportInfo.update(ExportInfo.Type.ADD, entry.getName()); ZipEntry copy = new ZipEntry(entry); copy.setCompressedSize(-1); jOut.putNextEntry(copy); if (!entry.isDirectory()) { // copy InputStream in = zip.getInputStream(entry); IOUtils.copy(in, jOut); in.close(); } jOut.closeEntry(); if (changeCompressionLevel) { jOut.setLevel(level); } }
private void copyBootJar(JarOutputStream zOs, File bootJar) throws IOException { try (FileInputStream fIn = new FileInputStream(bootJar)) { zOs.setLevel(9); try (ZipInputStream zIn = new ZipInputStream(fIn)) { ZipEntry entry; String pkg = BaratineBoot.class.getPackage().getName().replace('.', '/') + "/"; while ((entry = zIn.getNextEntry()) != null) { String name = entry.getName(); if (! name.startsWith(pkg)) { continue; } ZipEntry entryOut = new ZipEntry(name); entryOut.setSize(entry.getSize()); zOs.putNextEntry(entryOut); if (name.startsWith(pkg)) { IoUtil.copy(zIn, zOs); } } } } }
Set<String> classpath = new TreeSet<>(); try (JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(targetFile)))) { jarOut.setLevel(Deflater.NO_COMPRESSION);
/** * Creates the uninstaller jar file. * * @throws IOException for any I/O error */ private void createOutputJar() throws IOException { // Create the uninstaller directory String dirPath = IoHelper.translatePath(installData.getInfo().getUninstallerPath(), installData.getVariables()); String jarPath = dirPath + File.separator + installData.getInfo().getUninstallerName(); File dir = new File(dirPath); if (!dir.exists() && !dir.mkdirs()) { throw new IOException("Failed to create output path: " + dir); } // Log the uninstaller deletion information uninstallData.setUninstallerJarFilename(jarPath); uninstallData.setUninstallerPath(dirPath); // Create the jar file jarStream = new FileOutputStream(jarPath); jar = new JarOutputStream(new BufferedOutputStream(jarStream)); jar.setLevel(9); uninstallData.addFile(jarPath, true); }
private void writeDependencies(JarOutputStream zOs) throws IOException { Configuration targetConfig; targetConfig = _project.getConfigurations().getByName("runtime"); for (File lib : targetConfig.resolve()) { if (isBootJar(lib)) { copyBootJar(zOs, lib); } String name = lib.getName(); zOs.setLevel(0); ZipEntry entry = new ZipEntry("lib/" + name); entry.setMethod(ZipEntry.STORED); entry.setSize(lib.length()); entry.setCrc(calculateCrc(lib.toPath())); zOs.putNextEntry(entry); Files.copy(lib.toPath(), zOs); } }