use of java.io.FileFilter in project ansj_seg by NLPchina.
the class File2Stream method multiple.
private InputStream multiple(String path) throws FileNotFoundException {
File[] libs = new File[0];
File file = new File(path);
if (file.exists() && file.canRead()) {
if (file.isFile()) {
libs = new File[1];
libs[0] = file;
} else if (file.isDirectory()) {
File[] files = file.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.canRead() && !file.isHidden() && !file.isDirectory();
}
});
if (files != null && files.length > 0) {
libs = files;
}
}
}
if (libs.length == 0) {
throw new LibraryException("not find any file in path : " + path);
}
if (libs.length == 1) {
return new FileInputStream(libs[0]);
}
Vector<InputStream> vector = new Vector<>(libs.length);
for (int i = 0; i < libs.length; i++) {
vector.add(new FileInputStream(libs[i]));
}
return new SequenceInputStream(vector.elements());
}
use of java.io.FileFilter in project atlas by alibaba.
the class BundleReleaser method dexOptimization.
private void dexOptimization() {
Log.e(TAG, "dexOptimization start");
final File[] validDexes = reversionDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
if (!DexReleaser.isArt()) {
return pathname.getName().endsWith(DEX_SUFFIX);
} else {
return pathname.getName().endsWith(".zip");
}
}
});
dexFiles = new DexFile[validDexes.length];
final CountDownLatch countDownLatch = new CountDownLatch(validDexes.length);
for (int i = 0; i < validDexes.length; i++) {
final int j = i;
service.submit(new Runnable() {
@Override
public void run() {
long startTime = System.currentTimeMillis();
String optimizedPath = optimizedPathFor(validDexes[j], dexOptDir());
try {
dexFiles[j] = DexFile.loadDex(validDexes[j].getPath(), optimizedPath, 0);
boolean result = verifyDexFile(dexFiles[j]);
if (!result) {
handler.sendMessage(handler.obtainMessage(MSG_ID_RELEASE_FAILED));
}
} catch (IOException e) {
e.printStackTrace();
handler.sendMessage(handler.obtainMessage(MSG_ID_RELEASE_FAILED));
} finally {
//后面需要loadclass,这里不能close
// if (dexFile != null) {
// try {
// dexFile.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}
Log.e(TAG, String.format("dex %s consume %d ms", validDexes[j].getAbsolutePath(), System.currentTimeMillis() - startTime));
countDownLatch.countDown();
}
});
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.e(TAG, "dex opt done");
handler.sendMessage(handler.obtainMessage(MSG_ID_DEX_OPT_DONE));
}
use of java.io.FileFilter in project atlas by alibaba.
the class MD5Util method getFileMd5.
public static String getFileMd5(Collection<File> inputFiles) {
StringBuilder stringBuilder = new StringBuilder();
FileFilter fileFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile();
}
};
for (File file : inputFiles) {
if (null == file || !file.exists()) {
continue;
}
if (file.isFile()) {
stringBuilder.append(MD5Util.getFileMD5(file));
} else {
List<File> files = new ArrayList<File>();
listFilesForFolder(file, files);
for (File file1 : files) {
stringBuilder.append(MD5Util.getFileMD5(file1));
}
}
}
try {
return MD5Util.getMD5(stringBuilder.toString());
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
use of java.io.FileFilter in project atlas by alibaba.
the class PatchUtils method getTpatchClassDef.
public static void getTpatchClassDef(File tpatchFile, Map<String, Map<String, ClassDef>> bundleMap) throws IOException {
if (tpatchFile == null || !tpatchFile.exists()) {
return;
}
File unZipFolder = new File(tpatchFile.getParentFile(), tpatchFile.getName().split("\\.")[0]);
unZipFolder.mkdirs();
ZipUtils.unzip(tpatchFile, unZipFolder.getAbsolutePath());
File[] bundleFolder = unZipFolder.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory() && pathname.getName().startsWith("lib");
}
});
for (File file : bundleFolder) {
Map<String, ClassDef> dexClasses = getBundleClassDef(file);
bundleMap.put(file.getName(), dexClasses);
}
FileUtils.deleteDirectory(tpatchFile.getParentFile());
}
use of java.io.FileFilter in project canal by alibaba.
the class SpringInstanceConfigMonitor method scan.
private void scan() {
File rootdir = new File(rootConf);
if (!rootdir.exists()) {
return;
}
File[] instanceDirs = rootdir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
String filename = pathname.getName();
return pathname.isDirectory() && !"spring".equalsIgnoreCase(filename);
}
});
// 扫描目录的新增
Set<String> currentInstanceNames = new HashSet<String>();
// 判断目录内文件的变化
for (File instanceDir : instanceDirs) {
String destination = instanceDir.getName();
currentInstanceNames.add(destination);
File[] instanceConfigs = instanceDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
// 限制一下,只针对instance.properties文件,避免因为.svn或者其他生成的临时文件导致出现reload
return StringUtils.equalsIgnoreCase(name, "instance.properties");
}
});
if (!actions.containsKey(destination) && instanceConfigs.length > 0) {
// 存在合法的instance.properties,并且第一次添加时,进行启动操作
notifyStart(instanceDir, destination);
} else if (actions.containsKey(destination)) {
// 历史已经启动过
if (instanceConfigs.length == 0) {
// 如果不存在合法的instance.properties
notifyStop(destination);
} else {
InstanceConfigFiles lastFile = lastFiles.get(destination);
boolean hasChanged = judgeFileChanged(instanceConfigs, lastFile.getInstanceFiles());
// 通知变化
if (hasChanged) {
notifyReload(destination);
}
if (hasChanged || CollectionUtils.isEmpty(lastFile.getInstanceFiles())) {
// 更新内容
List<FileInfo> newFileInfo = new ArrayList<FileInfo>();
for (File instanceConfig : instanceConfigs) {
newFileInfo.add(new FileInfo(instanceConfig.getName(), instanceConfig.lastModified()));
}
lastFile.setInstanceFiles(newFileInfo);
}
}
}
}
// 判断目录是否删除
Set<String> deleteInstanceNames = new HashSet<String>();
for (String destination : actions.keySet()) {
if (!currentInstanceNames.contains(destination)) {
deleteInstanceNames.add(destination);
}
}
for (String deleteInstanceName : deleteInstanceNames) {
notifyStop(deleteInstanceName);
}
}
Aggregations