List of usage examples for java.util.jar Manifest Manifest
public Manifest()
From source file:com.textocat.textokit.morph.opencorpora.resource.XmlDictionaryPSP.java
public static void main(String[] args) throws Exception { XmlDictionaryPSP cfg = new XmlDictionaryPSP(); new JCommander(cfg, args); MorphDictionaryImpl dict = new MorphDictionaryImpl(); DictionaryExtension ext = cfg.dictExtensionClass.newInstance(); FileInputStream fis = FileUtils.openInputStream(cfg.dictXmlFile); try {//from w w w. j a v a2s. c o m new XmlDictionaryParser(dict, ext, fis).run(); } finally { IOUtils.closeQuietly(fis); } System.out.println("Preparing to serialization..."); long timeBefore = currentTimeMillis(); OutputStream fout = new BufferedOutputStream(FileUtils.openOutputStream(cfg.outputJarFile), 8192 * 8); Manifest manifest = new Manifest(); manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_VERSION, dict.getVersion()); manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_REVISION, dict.getRevision()); manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_VARIANT, cfg.variant); String dictEntryName = String.format( OpencorporaMorphDictionaryAPI.FILENAME_PATTERN_OPENCORPORA_SERIALIZED_DICT, dict.getVersion(), dict.getRevision(), cfg.variant); JarOutputStream jarOut = new JarOutputStream(fout, manifest); jarOut.putNextEntry(new ZipEntry(dictEntryName)); ObjectOutputStream serOut = new ObjectOutputStream(jarOut); try { serOut.writeObject(dict.getGramModel()); serOut.writeObject(dict); } finally { serOut.flush(); jarOut.closeEntry(); serOut.close(); } System.out.println(String.format("Serialization finished in %s ms.\nOutput size: %s bytes", currentTimeMillis() - timeBefore, cfg.outputJarFile.length())); }
From source file:Main.java
private static Manifest getCompositeManifest(Map compositeManifest) { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); //$NON-NLS-1$//$NON-NLS-2$ // get the common headers Bundle-ManifestVersion, Bundle-SymbolicName and Bundle-Version // get the manifest version from the map String manifestVersion = (String) compositeManifest.remove(Constants.BUNDLE_MANIFESTVERSION); // here we assume the validation got the correct version for us attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, manifestVersion); // Ignore the Equinox composite bundle header compositeManifest.remove(BaseStorageHook.COMPOSITE_HEADER); attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.COMPOSITE_BUNDLE); for (Iterator entries = compositeManifest.entrySet().iterator(); entries.hasNext();) { Map.Entry entry = (Entry) entries.next(); if (entry.getKey() instanceof String && entry.getValue() instanceof String) attributes.putValue((String) entry.getKey(), (String) entry.getValue()); }//w w w.j a va 2 s. c om return manifest; }
From source file:Main.java
private static Manifest getSurrogateManifest(Dictionary compositeManifest, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports) { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); //$NON-NLS-1$//$NON-NLS-2$ // Ignore the manifest version from the map // always use bundle manifest version 2 attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$ // Ignore the Equinox composite bundle header attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.SURROGATE_BUNDLE); if (compositeDesc != null && matchingExports != null) { // convert the exports from the composite into imports addImports(attributes, compositeDesc, matchingExports); // convert the matchingExports from the composite into exports addExports(attributes, compositeDesc, matchingExports); }/*from ww w.ja v a 2 s . c o m*/ // add the rest for (Enumeration keys = compositeManifest.keys(); keys.hasMoreElements();) { Object header = keys.nextElement(); if (Constants.BUNDLE_MANIFESTVERSION.equals(header) || BaseStorageHook.COMPOSITE_HEADER.equals(header) || Constants.IMPORT_PACKAGE.equals(header) || Constants.EXPORT_PACKAGE.equals(header)) continue; if (header instanceof String && compositeManifest.get(header) instanceof String) attributes.putValue((String) header, (String) compositeManifest.get(header)); } return manifest; }
From source file:Main.java
void createJarArchive(File archiveFile, File[] tobeJared) throws Exception { byte buffer[] = new byte[BUFFER_SIZE]; FileOutputStream stream = new FileOutputStream(archiveFile); JarOutputStream out = new JarOutputStream(stream, new Manifest()); for (int i = 0; i < tobeJared.length; i++) { if (tobeJared[i] == null || !tobeJared[i].exists() || tobeJared[i].isDirectory()) continue; // Just in case... JarEntry jarAdd = new JarEntry(tobeJared[i].getName()); jarAdd.setTime(tobeJared[i].lastModified()); out.putNextEntry(jarAdd);/*from w w w .ja v a 2s.com*/ FileInputStream in = new FileInputStream(tobeJared[i]); while (true) { int nRead = in.read(buffer, 0, buffer.length); if (nRead <= 0) break; out.write(buffer, 0, nRead); } in.close(); } out.close(); stream.close(); }
From source file:CreateJarFile.java
protected void createJarArchive(File archiveFile, File[] tobeJared) { try {/*w w w . j av a 2s.c o m*/ byte buffer[] = new byte[BUFFER_SIZE]; // Open archive file FileOutputStream stream = new FileOutputStream(archiveFile); JarOutputStream out = new JarOutputStream(stream, new Manifest()); for (int i = 0; i < tobeJared.length; i++) { if (tobeJared[i] == null || !tobeJared[i].exists() || tobeJared[i].isDirectory()) continue; // Just in case... System.out.println("Adding " + tobeJared[i].getName()); // Add archive entry JarEntry jarAdd = new JarEntry(tobeJared[i].getName()); jarAdd.setTime(tobeJared[i].lastModified()); out.putNextEntry(jarAdd); // Write file to archive FileInputStream in = new FileInputStream(tobeJared[i]); while (true) { int nRead = in.read(buffer, 0, buffer.length); if (nRead <= 0) break; out.write(buffer, 0, nRead); } in.close(); } out.close(); stream.close(); System.out.println("Adding completed OK"); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Error: " + ex.getMessage()); } }
From source file:oz.hadoop.yarn.api.utils.JarUtils.java
/** * Will create a JAR file frombase dir/*from w w w . j av a2s . co m*/ * * @param source * @param jarName * @return */ public static File toJar(File source, String jarName) { if (!source.isAbsolute()) { throw new IllegalArgumentException("Source must be expressed through absolute path"); } StringAssertUtils.assertNotEmptyAndNoSpacesAndEndsWith(jarName, ".jar"); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); File jarFile = new File(jarName); try { JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest); add(source, source.getAbsolutePath().length(), target); target.close(); } catch (Exception e) { throw new IllegalStateException( "Failed to create JAR file '" + jarName + "' from " + source.getAbsolutePath(), e); } return jarFile; }
From source file:org.talend.designer.maven.utils.ClasspathsJarGenerator.java
public static String createJar(Property property, String classpath, String separator) throws Exception { String newClasspath = generateClasspathForManifest(classpath, separator); Manifest manifest = new Manifest(); Attributes a = manifest.getMainAttributes(); a.put(Attributes.Name.MANIFEST_VERSION, "1.0"); //$NON-NLS-1$ a.put(Attributes.Name.IMPLEMENTATION_VENDOR, "Talend Open Studio"); //$NON-NLS-1$ a.put(Attributes.Name.CLASS_PATH, newClasspath); String jarLocation = getJarLocation(property); File jarFile = new File(jarLocation); if (!jarFile.exists()) { jarFile.createNewFile();/*from www. j a v a 2 s. com*/ } JarOutputStream stream = null; try { stream = new JarOutputStream(new FileOutputStream(jarLocation), manifest); stream.flush(); } finally { stream.close(); } return getFinalClasspath(classpath, separator, jarLocation); }
From source file:oz.tez.deployment.utils.ClassPathUtils.java
/** * //w ww .j ava 2 s.c o m * @param source * @return */ public static byte[] toJarBytes(File source) { if (!source.isAbsolute()) { throw new IllegalArgumentException("Source must be expressed through absolute path"); } Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { JarOutputStream target = new JarOutputStream(bos, manifest); add(source, source.getAbsolutePath().length(), target); target.close(); } catch (Exception e) { throw new IllegalStateException("Failed to generate JAR bytes from " + source.getAbsolutePath(), e); } return bos.toByteArray(); }
From source file:org.mule.ibeans.internal.config.IBeansInfo.java
public static Manifest getManifest() { if (manifest == null) { manifest = new Manifest(); InputStream is = null;/*from www . ja va2 s . c o m*/ try { // We want to load the MANIFEST.MF from the mule-core jar. Sine we // don't know the version we're using we have to search for the jar on the classpath URL url = AccessController.doPrivileged(new PrivilegedAction<URL>() { public URL run() { try { Enumeration e = MuleConfiguration.class.getClassLoader() .getResources(("META-INF/MANIFEST.MF")); while (e.hasMoreElements()) { URL url = (URL) e.nextElement(); if ((url.toExternalForm().indexOf("ibeans-core") > -1 && url.toExternalForm().indexOf("tests.jar") < 0)) { return url; } } } catch (IOException e1) { logger.warn("Failure reading manifest: " + e1.getMessage(), e1); } return null; } }); if (url != null) { is = url.openStream(); } if (is != null) { manifest.read(is); } } catch (IOException e) { logger.warn("Failed to read manifest Info, Manifest information will not display correctly: " + e.getMessage()); } } return manifest; }
From source file:com.ikon.util.WarUtils.java
/** * /*from w w w .j a v a2 s.c o m*/ */ public static synchronized void readAppVersion(ServletContext sc) { String appServerHome = sc.getRealPath("/"); File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF"); FileInputStream fis = null; try { fis = new FileInputStream(manifestFile); Manifest mf = new Manifest(); mf.read(fis); Attributes atts = mf.getMainAttributes(); String impVersion = atts.getValue("Implementation-Version"); String impBuild = atts.getValue("Implementation-Build"); log.info("Implementation-Version: " + impVersion); log.info("Implementation-Build: " + impBuild); if (impVersion != null) { String[] version = impVersion.split("\\."); if (version.length > 0 && version[0] != null) { appVersion.setMajor(version[0]); } if (version.length > 1 && version[1] != null) { appVersion.setMinor(version[1]); } if (version.length > 2 && version[2] != null && !version[2].equals("")) { appVersion.setMaintenance(version[2]); } } if (impBuild != null) { appVersion.setBuild(impBuild); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(fis); } }