1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2025-09-09 04:33:09 +00:00

项目初始化,随框架更新

This commit is contained in:
GeekFrog
2017-07-08 09:47:15 +08:00
parent 3a920f5df0
commit 8fd9e9774d
10 changed files with 152 additions and 22 deletions

View File

@ -0,0 +1,46 @@
package gg.frog.mc.permissionstime.utils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class FileUtil {
public interface FindFilesDo {
boolean isProcess(String fileName);
void process(String fileName, InputStream is);
}
public static void findFilesFromJar(FindFilesDo ffd, Class<?> jarClazz){
JarFile jarFile = null;
try {
String jarFilePath = jarClazz.getProtectionDomain().getCodeSource().getLocation().getFile();
jarFile = new JarFile(jarFilePath);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if(ffd.isProcess(e.getName())){
InputStream is = jarFile.getInputStream(e);
ffd.process(e.getName(), is);
try {
is.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jarFile != null) {
try {
jarFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}