Example usage for java.util.jar JarFile getName

List of usage examples for java.util.jar JarFile getName

Introduction

In this page you can find the example usage for java.util.jar JarFile getName.

Prototype

public String getName() 

Source Link

Document

Returns the path name of the ZIP file.

Usage

From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAIntfUtil.java

/**
 * Load metadata props./*from w w w  . j a  v  a 2 s  .co m*/
 *
 * @param zipFiles the zip files
 * @param serviceName the service name
 * @return the properties
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws CoreException the core exception
 */
public static Properties loadMetadataProps(final JarFile zipFiles[], String serviceName)
        throws IOException, CoreException {
    if (SOALogger.DEBUG)
        logger.entering(Arrays.asList(zipFiles), serviceName);
    Properties properties = null;
    for (JarFile zipFile : zipFiles) {
        try {
            serviceName = StringUtils.isEmpty(serviceName) ? zipFile.getName() : serviceName;
            final String jarEntryPath = SOAProjectConstants.METADATA_PROPS_LOCATION_JAR + serviceName
                    + WorkspaceUtil.PATH_SEPERATOR + SOAProjectConstants.PROPS_FILE_SERVICE_METADATA;
            properties = IOUtil.loadProperties(zipFile, jarEntryPath);
            // a project can have many jar files and we never
            // know which one has the props file
            if (properties != null)
                break;
        } catch (Exception e) {
            // This exception is swallowed... One jar not having it doesnt
            // mean failure
        }
    }
    if (SOALogger.DEBUG)
        logger.exiting(properties);
    return properties;
}

From source file:org.javaan.bytecode.JarFileLoader.java

public List<Type> loadJavaClasses(String[] fileNames) throws IOException {
    List<Type> classes = new ArrayList<Type>();
    for (String fileName : fileNames) {
        File file = new File(fileName);
        if (!file.exists()) {
            throw new IOException(String.format("JAR file %s does not exist", fileName));
        }/*from ww w  .j ava2 s  . c o m*/
        JarFile jar = new JarFile(file);
        processJar(jar.getName(), fileName, jar, classes);
    }

    return classes;
}

From source file:org.nuxeo.osgi.util.jar.URLJarFileCloser.java

@Override
public void close(JarFile file) throws IOException {
    file.close();// w  w  w  . j a v  a2s  . c om
    URL location = new File(file.getName()).toURI().toURL();
    boolean closed = false;
    try {
        final SharedResourceLoader loader = Framework.getResourceLoader();
        if (loader != null) {
            closed = introspector.newURLClassLoaderCloser(loader).close(location);
        }
    } catch (URLJarFileIntrospectionError cause) {
        LogFactory.getLog(URLJarFileCloser.class).error("Cannot introspect shared resource loader", cause);

    }
    if (closed == false) {
        if (applicationCloser != null) {
            closed = applicationCloser.close(location);
        }
    }
    introspector.close(location);
}

From source file:com.navercorp.pinpoint.bootstrap.java9.module.JarFileAnalyzerTest.java

@Test
public void jarFileToURI() throws IOException {
    URL url = CodeSourceUtils.getCodeLocation(Logger.class);
    logger.debug("url:{}", url);

    JarFile jarFile = new JarFile(url.getFile());
    logger.debug("jarFile:{}", jarFile.getName());
    File file = new File(jarFile.getName());
    logger.debug("url1:{}", file.toURI());
}

From source file:com.navercorp.pinpoint.bootstrap.java9.module.JarFileAnalyzerTest.java

@Test
public void packageAnalyzer() throws IOException {
    URL url = CodeSourceUtils.getCodeLocation(Logger.class);

    JarFile jarFile = new JarFile(url.getFile());
    logger.debug("jarFile:{}", jarFile.getName());

    PackageAnalyzer packageAnalyzer = new JarFileAnalyzer(jarFile);
    PackageInfo packageInfo = packageAnalyzer.analyze();
    Set<String> packageSet = packageInfo.getPackage();

    logger.debug("package:{}", packageSet);

    Assert.assertEquals(packageSet, SLF4J_API_PACKAGE);
}

From source file:org.ngrinder.jnlp.impl.JNLPLoaderImpl.java

@Override
public List<File> resolveRemoteJars(File jnlpLibPath) {

    List<File> fileString = new ArrayList<File>();

    JNLPClassLoader jnlpClassLoader = (JNLPClassLoader) localClassLoader;
    try {//from  w  w w. j a  v a 2  s  . c  o m
        URL[] urls = jnlpClassLoader.getURLs();

        for (URL each : urls) {
            String jarName = FilenameUtils.getName(each.toString());
            JarFile jar = jnlpClassLoader.getJarFile(each);

            String jarLocalPath = jar.getName();
            File srcFile = new File(jarLocalPath);
            long srcFIleStamp = FileUtils.checksumCRC32(srcFile);
            File desFile = new File(jnlpLibPath, jarName);
            if (!desFile.exists() || (FileUtils.checksumCRC32(desFile) != srcFIleStamp)) {
                FileUtils.copyFile(srcFile, desFile);
            }
            if (jarName.equals("native.jar")) {
                CompressionUtil.unjar(desFile, jnlpLibPath.getAbsolutePath());
            }
            fileString.add(desFile);
        }
    } catch (IOException e) {
        LOG.error("Resolving remote jars error: {}", e.getMessage());
    }
    return fileString;
}

From source file:ru.objective.jni.utils.Utils.java

public static String[] getContainedExportClasses(JarFile jarFile, String[] excludes, String[] excludedPackages)
        throws Exception {
    Enumeration<JarEntry> entries = jarFile.entries();

    ArrayList<String> containedClasses = new ArrayList<>();

    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        String entryName = entry.getName();

        if (!entry.isDirectory() && entryName.endsWith(Constants.CLASS_SUFFIX)) {
            // check this is export class
            JavaClass parsed = OJNIClassLoader.getInstance().loadClass(entryName);

            if (!isExportClass(parsed, excludes, excludedPackages))
                continue;

            containedClasses.add(entryName);
        }//from   ww  w.ja va 2 s  .c o m
    }

    if (containedClasses.size() == 0)
        throw new BadParsingException("Error parsing specified jar file" + jarFile.getName());

    String[] result = new String[containedClasses.size()];

    containedClasses.toArray(result);

    return result;
}

From source file:org.wso2.carbon.automation.test.utils.common.FileManager.java

public void copyJarFile(String sourceFileLocationWithFileName, String destinationDirectory)
        throws IOException, URISyntaxException {
    File sourceFile = new File(getClass().getResource(sourceFileLocationWithFileName).toURI());
    File destinationFileDirectory = new File(destinationDirectory);
    JarFile jarFile = new JarFile(sourceFile);
    String fileName = jarFile.getName();
    String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator));
    File destinationFile = new File(destinationFileDirectory, fileNameLastPart);
    JarOutputStream jarOutputStream = null;
    try {/*  w ww .  jav a2  s .co  m*/
        jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile));
        Enumeration<JarEntry> entries = jarFile.entries();
        InputStream inputStream = null;
        while (entries.hasMoreElements()) {
            try {
                JarEntry jarEntry = entries.nextElement();
                inputStream = jarFile.getInputStream(jarEntry);
                //jarOutputStream.putNextEntry(jarEntry);
                //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size
                jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName()));
                byte[] buffer = new byte[4096];
                int bytesRead = 0;
                while ((bytesRead = inputStream.read(buffer)) != -1) {
                    jarOutputStream.write(buffer, 0, bytesRead);
                }
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                    jarOutputStream.flush();
                    jarOutputStream.closeEntry();
                }
            }
        }
    } finally {
        if (jarOutputStream != null) {
            jarOutputStream.close();
        }
    }
}

From source file:us.mn.state.health.lims.plugin.PluginLoader.java

private boolean loadFromXML(JarFile jar, JarEntry entry) {

    try {//from  ww w. j  av a  2  s  . com
        URL url = new URL("jar:file:///" + jar.getName() + "!/");
        InputStream input = jar.getInputStream(entry);

        String xml = IOUtils.toString(input, "UTF-8");

        //System.out.println(xml);

        Document doc = DocumentHelper.parseText(xml);

        Element versionElement = doc.getRootElement().element(VERSION);

        if (!SUPPORTED_VERSION.equals(versionElement.getData())) {
            System.out.println("Unsupported version number.  Expected " + SUPPORTED_VERSION + " got "
                    + versionElement.getData());
            return false;
        }

        Element analyzerImporter = doc.getRootElement().element(ANALYZER_IMPORTER);

        if (analyzerImporter != null) {
            Attribute description = analyzerImporter.element(EXTENSION_POINT).element(DESCRIPTION)
                    .attribute(VALUE);
            System.out.println("Loading: " + description.getValue());
            Attribute path = analyzerImporter.element(EXTENSION_POINT).element(EXTENSION).attribute(PATH);
            loadActualPlugin(url, path.getValue());
        }

        Element menu = doc.getRootElement().element(MENU);

        if (menu != null) {
            Attribute description = menu.element(EXTENSION_POINT).element(DESCRIPTION).attribute(VALUE);
            System.out.println("Loading: " + description.getValue());
            Attribute path = menu.element(EXTENSION_POINT).element(EXTENSION).attribute(PATH);
            loadActualPlugin(url, path.getValue());
        }

        Element permissions = doc.getRootElement().element(PERMISSION);

        if (permissions != null) {
            Attribute description = permissions.element(EXTENSION_POINT).element(DESCRIPTION).attribute(VALUE);
            Attribute path = permissions.element(EXTENSION_POINT).element(EXTENSION).attribute(PATH);
            boolean loaded = loadActualPlugin(url, path.getValue());
            if (loaded) {
                System.out.println("Loading: " + description.getValue());
            } else {
                System.out.println("Failed Loading: " + description.getValue());
            }
        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    return true;
}

From source file:org.wso2.esb.integration.common.utils.common.FileManager.java

public void copyJarFile(String sourceFileLocationWithFileName, String destinationDirectory)
        throws IOException, URISyntaxException {
    File sourceFile = new File(getClass().getResource(sourceFileLocationWithFileName).toURI());
    File destinationFileDirectory = new File(destinationDirectory);
    JarFile jarFile = new JarFile(sourceFile);
    String fileName = jarFile.getName();
    String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator));
    File destinationFile = new File(destinationFileDirectory, fileNameLastPart);

    JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile));
    Enumeration<JarEntry> entries = jarFile.entries();

    while (entries.hasMoreElements()) {
        JarEntry jarEntry = entries.nextElement();
        InputStream inputStream = jarFile.getInputStream(jarEntry);

        //jarOutputStream.putNextEntry(jarEntry);
        //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size
        jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName()));
        byte[] buffer = new byte[4096];
        int bytesRead = 0;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            jarOutputStream.write(buffer, 0, bytesRead);
        }/*from  w  w  w. j ava2 s .  c om*/
        inputStream.close();
        jarOutputStream.flush();
        jarOutputStream.closeEntry();
    }
    jarOutputStream.close();
}