use of java.io.FilenameFilter in project atlas by alibaba.
the class Framework method checkInstallDebugBundle.
/**
* for debug not release
*/
static void checkInstallDebugBundle() {
File debugDirectory = new File(ATLAS_DEBUG_DIRECTORY);
if (debugDirectory.exists()) {
File[] bundles = debugDirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
if (filename.endsWith(".so")) {
return true;
}
return false;
}
});
if (bundles != null) {
String[] packageNames = new String[bundles.length];
String[] versions = new String[bundles.length];
for (int x = 0; x < bundles.length; x++) {
versions[x] = "1.0.0";
if (bundles[x].getName().startsWith("kernal") || bundles[x].getName().contains("com_taobao_mainDex")) {
//主dexbundle
packageNames[x] = "com.taobao.maindex";
} else {
//业务bundle
PackageInfo info = RuntimeVariables.androidApplication.getPackageManager().getPackageArchiveInfo(bundles[x].getAbsolutePath(), 0);
if (info != null) {
packageNames[x] = info.applicationInfo.packageName;
} else {
String fileName = bundles[x].getName();
fileName = fileName.substring(3, fileName.length() - 3);
packageNames[x] = fileName.replace("_", ".");
}
}
}
try {
Atlas.getInstance().installOrUpdate(packageNames, bundles, versions, -1);
Log.d("Framework", "patch success and delete file");
try {
for (File installFile : bundles) {
if (installFile.exists()) {
installFile.delete();
}
}
} catch (Exception e) {
}
} catch (BundleException e) {
e.printStackTrace();
}
}
}
}
use of java.io.FilenameFilter in project atlas by alibaba.
the class BundleArchive method downgradeRevision.
public static boolean downgradeRevision(String location, File bundleDir, boolean forceDelete) throws IOException {
File[] revisionFiles = bundleDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
if (filename.startsWith(REVISION_DIRECTORY) && !new File(dir + File.separator + filename, DEPRECATED_MARK).exists()) {
return true;
}
return false;
}
});
if (revisionFiles != null && revisionFiles.length > 0) {
File deprecatedDir = revisionFiles[revisionFiles.length - 1];
if (forceDelete) {
try {
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(location);
if (impl != null && impl.getArchive().getCurrentRevision() != null) {
if (impl.getArchive().getCurrentRevision().getRevisionDir().equals(deprecatedDir)) {
return true;
}
}
} catch (Throwable e) {
}
//deprecatedDir.delete();
Framework.deleteDirectory(deprecatedDir);
}
if (deprecatedDir.exists()) {
File deprecatedFile = new File(deprecatedDir, DEPRECATED_MARK);
deprecatedFile.createNewFile();
if (!deprecatedFile.exists()) {
return false;
}
}
Log.d("BundleArchive", "downgrade " + bundleDir);
return true;
}
return false;
}
use of java.io.FilenameFilter 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);
}
}
use of java.io.FilenameFilter in project android_frameworks_base by ParanoidAndroid.
the class PackageManagerService method deleteTempPackageFiles.
private void deleteTempPackageFiles() {
final FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("vmdl") && name.endsWith(".tmp");
}
};
deleteTempPackageFilesInDirectory(mAppInstallDir, filter);
deleteTempPackageFilesInDirectory(mDrmAppPrivateInstallDir, filter);
}
use of java.io.FilenameFilter in project android_frameworks_base by ParanoidAndroid.
the class VideoDumpView method onResume.
@Override
public void onResume() {
Log.d(TAG, "onResume");
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(VideoDumpConfig.VIDEO_URI);
class RGBFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(VideoDumpConfig.IMAGE_SUFFIX));
}
}
File dump_dir = new File(VideoDumpConfig.ROOT_DIR);
File[] dump_files = dump_dir.listFiles(new RGBFilter());
for (File dump_file : dump_files) {
dump_file.delete();
}
File image_list = new File(VideoDumpConfig.ROOT_DIR + VideoDumpConfig.IMAGES_LIST);
image_list.delete();
mImageListWriter = new BufferedWriter(new FileWriter(image_list));
} catch (java.io.IOException e) {
Log.e(TAG, e.getMessage(), e);
}
queueEvent(new Runnable() {
public void run() {
mRenderer.setMediaPlayer(mMediaPlayer);
mRenderer.setImageListWriter(mImageListWriter);
}
});
super.onResume();
}
Aggregations