Java Jar Usage getMatchingResourcesFromJar(JarFile jarFile, String suffix)

Here you can find the source of getMatchingResourcesFromJar(JarFile jarFile, String suffix)

Description

Retrieve all resources with the specified suffix in the jar.

License

Open Source License

Parameter

Parameter Description
jarFile : the jar in which search for resources must be performed
suffix : the suffix resources must match. If null all resources will be retrieved

Return

the retrieved resource names.

Declaration

public static List<String> getMatchingResourcesFromJar(JarFile jarFile, String suffix) 

Method Source Code

//package com.java2s;
/*//  w  w  w  . ja  v a2  s  .  co  m
 * (c) Copyright 2010-2011 AgileBirds
 *
 * This file is part of OpenFlexo.
 *
 * OpenFlexo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * OpenFlexo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenFlexo. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.util.ArrayList;

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

public class Main {
    /**
     * Retrieve all resources with the specified suffix in the jar.
     * 
     * @param jarFile : the jar in which search for resources must be performed
     * @param suffix : the suffix resources must match. If null all resources will be retrieved
     * @return the retrieved resource names.
     */
    public static List<String> getMatchingResourcesFromJar(JarFile jarFile, String suffix) {
        List<String> result = new ArrayList<String>();
        Enumeration<JarEntry> entries = jarFile.entries(); // gives ALL entries in jar
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            if (suffix == null || entry.getName().endsWith(suffix))
                result.add("/" + entry.getName());
        }

        return result;
    }
}

Related

  1. getClassNameByJar(String jarPath, boolean childPackage)
  2. getEntriesName(String jarFileName)
  3. getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)
  4. getInfo(String jarFileName)
  5. getJarInFileList(JarFile jarFile, String targetPath)
  6. getSortedAttributes(Attributes mainAttributes)
  7. getSortedJarEntries(JarFile jarFile)
  8. isSet(Attributes attributes, String name)
  9. listFiles(JarFile jarFile, String path)