Java Properties Load from File loadManifest(File bundleLocation)

Here you can find the source of loadManifest(File bundleLocation)

Description

load Manifest

License

Open Source License

Declaration

public static Dictionary loadManifest(File bundleLocation) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w w w.j  a  v  a  2 s  . c  om
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.*;

import java.util.*;
import java.util.jar.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.core.runtime.*;

public class Main {
    public static Dictionary loadManifest(File bundleLocation) throws IOException {
        ZipFile jarFile = null;
        InputStream manifestStream = null;
        try {
            String extension = new Path(bundleLocation.getName()).getFileExtension();
            bundleLocation = new File(bundleLocation.getAbsolutePath());
            if (extension != null && (extension.equals("jar") || extension.equals("jar!")) //$NON-NLS-1$//$NON-NLS-2$
                    && bundleLocation.isFile()) {
                jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
                ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME);
                if (manifestEntry != null) {
                    manifestStream = jarFile.getInputStream(manifestEntry);
                }
            } else {
                File file = new File(bundleLocation, JarFile.MANIFEST_NAME);
                if (file.exists())
                    manifestStream = new FileInputStream(file);
            }
        } catch (IOException e) {
        }
        if (manifestStream == null)
            return null;
        try {
            Manifest m = new Manifest(manifestStream);
            return manifestToProperties(m.getMainAttributes());
        } finally {
            try {
                manifestStream.close();
            } catch (IOException e1) {
            }
            try {
                if (jarFile != null)
                    jarFile.close();
            } catch (IOException e2) {
            }
        }
    }

    public static Properties manifestToProperties(Attributes d) {
        Iterator iter = d.keySet().iterator();
        Properties result = new Properties();
        while (iter.hasNext()) {
            Attributes.Name key = (Attributes.Name) iter.next();
            result.put(key.toString(), d.get(key));
        }
        return result;
    }
}

Related

  1. loadLibrary(String libFileName)
  2. loadLibrarySmart(String libraryName)
  3. loadLocalization(final ZipFile file, final String loc)
  4. loadLocatorInfo(String fileName)
  5. loadLWJGL()
  6. loadMetaConfiguration()
  7. loadMimeTypes(InputStream inputStream)
  8. loadNative(File nativeLibsFolder)
  9. loadNecessaryPackagePrivateProperties(Class aClass, String aFileName)