Java Jar Usage getEntriesName(String jarFileName)

Here you can find the source of getEntriesName(String jarFileName)

Description

Util: gets the name of the entries from the given jar file name

License

Apache License

Parameter

Parameter Description
jarFileName the jar file name

Return

a tabular of the entries name or null if the jar file is empty.

Declaration

public static String[] getEntriesName(String jarFileName) throws Exception 

Method Source Code

//package com.java2s;
/*//from  w ww. ja  va  2  s .  c  o  m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 * Copyright (C) 2006-2010 Adele Team/LIG/Grenoble University, France
 */

import java.util.Enumeration;

import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class Main {
    /**
     *  Util: gets the name of the entries from the given jar file name
     *
     * @param  jarFileName    the jar file name
     * @return                a tabular of the entries name or null if the jar
     * file is empty.
     * @exception  Exception  an exception occurs
     */
    public static String[] getEntriesName(String jarFileName) throws Exception {
        // Create a Jar file.
        JarFile jarFile = new JarFile(jarFileName);

        String[] tabEntriesName = null;
        int nbEntries = jarFile.size();

        if (nbEntries > 0) {
            // Get all of the Jar entries.
            Enumeration jarEntries = jarFile.entries();

            tabEntriesName = new String[nbEntries];
            JarEntry currentJarEntry = null;
            int i = 0;

            while (jarEntries.hasMoreElements()) {
                currentJarEntry = (JarEntry) jarEntries.nextElement();

                // Ajouter le nom de la nouvelle entree
                tabEntriesName[i] = currentJarEntry.getName();

                // Incrementer l'indice
                i++;
            }
        }

        // Fermeture du fichier jar
        jarFile.close();

        return tabEntriesName;
    }
}

Related

  1. convertAttributes(Attributes attributes)
  2. createPacker()
  3. findClassesByJar(String packageName, JarFile jar, final boolean recursive, Set> classes)
  4. getAttribute(String name, String value)
  5. getClassNameByJar(String jarPath, boolean childPackage)
  6. getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)
  7. getInfo(String jarFileName)
  8. getJarInFileList(JarFile jarFile, String targetPath)
  9. getMatchingResourcesFromJar(JarFile jarFile, String suffix)