Java Jar Usage getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)

Here you can find the source of getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)

Description

Convenience method to return the names of files specified in the jar file that end with the specified suffix.

License

Open Source License

Parameter

Parameter Description
jar Jar file
suffix Suffix for the file (can be the filename without the path)

Return

The fully-qualified names of the files with this suffix in the jar file

Declaration

private static String[] getFileNamesWithSuffixForJarFile(JarFile jar, String suffix) 

Method Source Code

//package com.java2s;
/**********************************************************************
Copyright (c) 2004 Andy Jefferson and others. All rights reserved. 
Licensed 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//  w  w  w.  j ava 2 s  .  c  o m
    
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. 
    
    
Contributors:
...
**********************************************************************/

import java.util.Enumeration;
import java.util.HashSet;

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

public class Main {
    /**
     * Convenience method to return the names of files specified in the jar file that end with
     * the specified suffix.
     * @param jar Jar file
     * @param suffix Suffix for the file (can be the filename without the path)
     * @return The fully-qualified names of the files with this suffix in the jar file
     */
    private static String[] getFileNamesWithSuffixForJarFile(JarFile jar, String suffix) {
        Enumeration jarEntries = jar.entries();
        Set<String> files = new HashSet();
        while (jarEntries.hasMoreElements()) {
            String entry = ((JarEntry) jarEntries.nextElement()).getName();
            if (entry.endsWith(suffix)) {
                files.add(entry);
            }
        }
        return files.toArray(new String[files.size()]);
    }
}

Related

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