Here you can find the source of getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)
Parameter | Description |
---|---|
jar | Jar file |
suffix | Suffix for the file (can be the filename without the path) |
private static String[] getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)
//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()]); } }