Description
Reads zip file, returns a list of all entries that match the given regular expression
License
Open Source License
Parameter
Parameter | Description |
---|
zipName | a parameter |
fileNameRegEx | a parameter |
Exception
Parameter | Description |
---|
IOException | an exception |
Declaration
public static List<ZipEntry> getAllFiles(String zipName, String fileNameRegEx) throws IOException
Method Source Code
//package com.java2s;
/*// w w w . ja va 2 s. com
File: ZipMultipleFiles.java
Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
The Cytoscape Consortium is:
- Institute for Systems Biology
- University of California San Diego
- Memorial Sloan-Kettering Cancer Center
- Institut Pasteur
- Agilent Technologies
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
any later version.
This library 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. The software and
documentation provided hereunder is on an "as is" basis, and the
Institute for Systems Biology and the Whitehead Institute
have no obligations to provide maintenance, support,
updates, enhancements or modifications. In no event shall the
Institute for Systems Biology and the Whitehead Institute
be liable to any party for direct, indirect, special,
incidental or consequential damages, including lost profits, arising
out of the use of this software and its documentation, even if the
Institute for Systems Biology and the Whitehead Institute
have been advised of the possibility of such damage. See
the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
/**
* Reads zip file, returns a list of all entries that match the given
* regular expression
* @param zipName
* @param fileNameRegEx
* @return
* @throws IOException
*/
public static List<ZipEntry> getAllFiles(String zipName, String fileNameRegEx) throws IOException {
List<ZipEntry> Matching = new ArrayList<ZipEntry>();
Pattern p;
Matcher m;
p = Pattern.compile(fileNameRegEx);
m = p.matcher("");
ZipFile Zip = null;
try {
Zip = new ZipFile(zipName);
Enumeration Entries = Zip.entries();
while (Entries.hasMoreElements()) {
ZipEntry CurrentEntry = (ZipEntry) Entries.nextElement();
m.reset(CurrentEntry.getName());
if (m.matches()) {
Matching.add(CurrentEntry);
}
}
} finally {
if (Zip != null) {
Zip.close();
}
}
return Matching;
}
}
Related
- getAllFiles(String dirPath)
- getAllFiles(String folderPath)
- getAllFiles(String path)
- getAllFiles(String path, boolean isDepth)
- getAllFiles(String sDirectoryPath)
- getAllFiles(String[] args, boolean recurse)
- getAllFilesByExtension(String path, String extension)
- getAllFilesByProfix(String path, String suffix, List files)
- getAllFilesEndingWith(String path, final String extension)