/** * Writes this {@code Manifest}'s name/attributes pairs to the given {@code OutputStream}. * The {@code MANIFEST_VERSION} or {@code SIGNATURE_VERSION} attribute must be set before * calling this method, or no attributes will be written. * * @throws IOException * If an error occurs writing the {@code Manifest}. */ public void write(OutputStream os) throws IOException { write(this, os); }
/** * {@inheritDoc} */ public Sink write(Manifest manifest) throws IOException { if (manifest != null) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { manifest.write(outputStream); } finally { outputStream.close(); } storage.put(JarFile.MANIFEST_NAME, outputStream.toByteArray()); } return this; }
/** * Write out manifest to destfile. * * @param manifest the manifest * @throws IOException if error writing file */ private void writeManifest(final Manifest manifest) throws IOException { try (OutputStream output = Files.newOutputStream(destFile.toPath())) { manifest.write(output); output.flush(); } }
/** * {@inheritDoc} */ public Sink write(Manifest manifest) throws IOException { if (manifest != null) { File target = new File(folder, JarFile.MANIFEST_NAME); if (!target.getParentFile().isDirectory() && !target.getParentFile().mkdirs()) { throw new IOException("Could not create directory: " + target.getParent()); } OutputStream outputStream = new FileOutputStream(target); try { manifest.write(outputStream); } finally { outputStream.close(); } } return this; }
/** * Constructs a new {@code JarOutputStream} using an output stream. The * content of the {@code Manifest} must match the JAR entry information * written subsequently to the stream. * * @param os * the {@code OutputStream} to write to * @param manifest * the {@code Manifest} to output for this JAR file. * @throws IOException * if an error occurs creating the {@code JarOutputStream}. */ public JarOutputStream(OutputStream os, Manifest manifest) throws IOException { super(os); if (manifest == null) { throw new NullPointerException("manifest == null"); } this.manifest = manifest; ZipEntry ze = new ZipEntry(JarFile.MANIFEST_NAME); putNextEntry(ze); this.manifest.write(this); closeEntry(); }
private void addManifest(ZipOutputStream destination, Collection<File> dexFiles) throws IOException { final Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Created-By"), "Soot Dex Printer"); if (dexFiles != null && !dexFiles.isEmpty()) { manifest.getMainAttributes().put(new Attributes.Name("Dex-Location"), dexFiles.stream().map(File::getName).collect(Collectors.joining(" "))); } final ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); destination.putNextEntry(manifestEntry); manifest.write(new BufferedOutputStream(destination)); destination.closeEntry(); }
public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException { Preconditions.checkNotNull(relativePath, "relativePath"); Preconditions.checkNotNull(zos, "zos"); // by JAR spec, if there is a manifest, it must be the first entry in // the // ZIP. File manifestFile = new File(dir, JarFile.MANIFEST_NAME); ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); if (!manifestFile.exists()) { zos.putNextEntry(manifestEntry); new Manifest().write(new BufferedOutputStream(zos)); zos.closeEntry(); } else { InputStream is = new FileInputStream(manifestFile); copyToZipStream(is, manifestEntry, zos); } zos.closeEntry(); zipDir(dir, relativePath, zos, true); zos.close(); }
mf.write(baos); baos.flush(); Files.write(targetPath, baos.toByteArray());
private String getJarVersion(Path jarPath) throws IOException { try (final JarFile jarFile = new JarFile(jarPath.toFile())) { final Manifest manifest; try { manifest = jarFile.getManifest(); } catch (IOException ex) { throw new IOException("Version not found. Failed to load the manifest.", ex); } String manifestContents; try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { manifest.write(outputStream); manifestContents = outputStream.toString(); } catch (IOException ex) { manifestContents = "(Failed to read the contents of the manifest.)"; } final Attributes mainAttributes = manifest.getMainAttributes(); final String implementationVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); if (implementationVersion == null) { throw new IOException("Version not found. Failed to read \"" + Attributes.Name.IMPLEMENTATION_VERSION + "\": " + manifestContents); } return implementationVersion; } catch (IOException ex) { throw new IOException("Version not found. Failed to load the jar file.", ex); } // NOTE: Checking embulk/version.rb is no longer needed. // The jar manifest with "Implementation-Version" has been included in Embulk jars from v0.4.0. }
public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException { Preconditions.checkNotNull(relativePath, "relativePath"); Preconditions.checkNotNull(zos, "zos"); // by JAR spec, if there is a manifest, it must be the first entry in the // ZIP. File manifestFile = new File(dir, JarFile.MANIFEST_NAME); ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); if (!manifestFile.exists()) { zos.putNextEntry(manifestEntry); new Manifest().write(new BufferedOutputStream(zos)); zos.closeEntry(); } else { copyToZipStream(manifestFile, manifestEntry, zos); } zos.closeEntry(); zipDir(dir, relativePath, zos, true); zos.close(); }
private void updateManifest(String symbolicName, String classPath, String bundleActivator) throws IOException { try (FileInputStream manifestInputStream = new FileInputStream(manifestLocation)) { Manifest manifest = new Manifest(manifestInputStream); Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes.containsKey(new Attributes.Name(BUNDLE_SYMBOLICNAME))) { descriptor.markAsInvalid(Arrays.asList("Plugin JAR is invalid. MANIFEST.MF already contains header: " + BUNDLE_SYMBOLICNAME), null); return; } mainAttributes.put(new Attributes.Name(BUNDLE_SYMBOLICNAME), symbolicName); mainAttributes.put(new Attributes.Name(BUNDLE_CLASSPATH), classPath); mainAttributes.put(new Attributes.Name(BUNDLE_ACTIVATOR), bundleActivator); descriptor.updateBundleInformation(symbolicName, classPath, bundleActivator); try (FileOutputStream manifestOutputStream = new FileOutputStream(manifestLocation)) { manifest.write(manifestOutputStream); } } }
private void addHeaderToManifest(String header, String value) throws IOException { FileInputStream manifestInputStream = new FileInputStream(manifestFile); Manifest manifest = new Manifest(manifestInputStream); Attributes entries = manifest.getMainAttributes(); entries.put(new Attributes.Name(header), value); FileOutputStream manifestOutputStream = new FileOutputStream(manifestFile, false); manifest.write(manifestOutputStream); manifestOutputStream.close(); manifestInputStream.close(); }
je.setTime(timestamp); outputJar.putNextEntry(je); manifest.write(outputJar);
@Test public void testExistingManifest() throws Exception { File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), TestJarFinder.class.getName() + "-testExistingManifest"); delete(dir); dir.mkdirs(); File metaInfDir = new File(dir, "META-INF"); metaInfDir.mkdirs(); File manifestFile = new File(metaInfDir, "MANIFEST.MF"); Manifest manifest = new Manifest(); OutputStream os = new FileOutputStream(manifestFile); manifest.write(os); os.close(); File propsFile = new File(dir, "props.properties"); Writer writer = new FileWriter(propsFile); new Properties().store(writer, ""); writer.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream zos = new JarOutputStream(baos); JarFinder.jarDir(dir, "", zos); JarInputStream jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); Assert.assertNotNull(jis.getManifest()); jis.close(); }
/** * Writes the manifest out to a writer. * * @param writer the Writer to which the manifest is written * * @throws IOException if the manifest cannot be written */ public void write( Writer writer ) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); super.write( byteArrayOutputStream ); // We know that UTF-8 is the encoding of the JAR file specification writer.write( byteArrayOutputStream.toString( "UTF-8" ) ); }
private File createManifestFileIfNecessary(File targetDirectory, Manifest sourceManifest) { try { File manifestFile = new File(targetDirectory.getPath(), "MANIFEST.MF"); if (!manifestFile.exists()) { Manifest manifest = new Manifest(sourceManifest); try (FileOutputStream fileOutputStream = new FileOutputStream(manifestFile)) { manifest.write(fileOutputStream); } } return manifestFile; } catch (IOException e) { throw new RuntimeException("Error creating discoverer", e); } }
try (OutputStream fout = new FileOutputStream(f)) manifest.write(fout);
public void open() throws IOException { // Update the manifest Manifest updated = m_manifestBuilder.build(m_manifest); // Write it to disk OutputStream os = new FileOutputStream(m_manifest_file); try { updated.write(os); } finally { Streams.close(os); } }
private void saveManifest() throws CoreException, IOException { ByteArrayOutputStream manifestOutput= new ByteArrayOutputStream(); Manifest manifest= fJarPackage.getManifestProvider().create(fJarPackage); manifest.write(manifestOutput); ByteArrayInputStream fileInput= new ByteArrayInputStream(manifestOutput.toByteArray()); IFile manifestFile= fJarPackage.getManifestFile(); if (manifestFile.isAccessible()) { if (fJarPackage.allowOverwrite() || JarPackagerUtil.askForOverwritePermission(fParentShell, manifestFile.getFullPath(), false)) manifestFile.setContents(fileInput, true, true, null); } else manifestFile.create(fileInput, true, null); }