use of java.io.FileFilter in project druid by druid-io.
the class LocalFileTimestampVersionFinder method mostRecentInDir.
private URI mostRecentInDir(final Path dir, final Pattern pattern) throws IOException {
long latestModified = Long.MIN_VALUE;
URI latest = null;
for (File file : dir.toFile().listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.exists() && pathname.isFile() && (pattern == null || pattern.matcher(pathname.getName()).matches());
}
})) {
final long thisModified = file.lastModified();
if (thisModified >= latestModified) {
latestModified = thisModified;
latest = file.toURI();
}
}
return latest;
}
use of java.io.FileFilter in project druid by druid-io.
the class FileTaskLogs method killOlderThan.
@Override
public void killOlderThan(final long timestamp) throws IOException {
File taskLogDir = config.getDirectory();
if (taskLogDir.exists()) {
if (!taskLogDir.isDirectory()) {
throw new IOException(String.format("taskLogDir [%s] must be a directory.", taskLogDir));
}
File[] files = taskLogDir.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.lastModified() < timestamp;
}
});
for (File file : files) {
log.info("Deleting local task log [%s].", file.getAbsolutePath());
FileUtils.forceDelete(file);
if (Thread.currentThread().isInterrupted()) {
throw new IOException(new InterruptedException("Thread interrupted. Couldn't delete all tasklogs."));
}
}
}
}
use of java.io.FileFilter in project nutz by nutzam.
the class UTF8_BOM method main.
public static void main(String[] args) {
final byte[] UTF_BOM = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
final byte[] bom = new byte[3];
Disks.visitFile(new File("."), new FileVisitor() {
public void visit(File file) {
try {
FileInputStream fis = new FileInputStream(file);
fis.read(bom);
if (bom[0] == UTF_BOM[0] && bom[1] == UTF_BOM[1] && bom[2] == UTF_BOM[2]) {
System.out.println("Found BOM --> " + file);
byte[] data = Streams.readBytes(fis);
fis.close();
Files.write(file, data);
System.out.println("Fixed");
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}, new FileFilter() {
public boolean accept(File pathname) {
if (pathname.isDirectory())
return true;
return pathname.getName().endsWith(".java") && pathname.length() > 3;
}
});
}
use of java.io.FileFilter in project superCleanMaster by joyoyao.
the class AppUtil method getNumCores.
/**
* Gets the number of cores available in this device, across all processors.
* Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
*
* @return The number of cores, or 1 if failed to get result
*/
public static int getNumCores() {
try {
// Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
// Filter to only list the devices we care about
File[] files = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
// number
if (Pattern.matches("cpu[0-9]", pathname.getName())) {
return true;
}
return false;
}
});
// Return the number of cores (virtual CPU devices)
return files.length;
} catch (Exception e) {
e.printStackTrace();
return 1;
}
}
use of java.io.FileFilter in project tdi-studio-se by Talend.
the class CustomComponentSettingPage method finish.
private void finish(IProgressMonitor... monitorWrap) {
IProgressMonitor monitor = null;
if (monitorWrap != null && monitorWrap.length == 1) {
monitor = monitorWrap[0];
}
final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor subMonitor) throws CoreException {
ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
File componentFolder = new File(targetRoot);
URL url = null;
try {
if (!componentFolder.exists()) {
FilesUtils.createFoldersIfNotExists(targetRoot, false);
}
Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
String sourceRoot = url.getFile();
// delete share
for (IComponent component : backAdded.keySet()) {
String componentFullPath = targetRoot + File.separator + component.getName();
if (service.isSVNProject(pro)) {
service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
if (subMonitor != null) {
subMonitor.worked(10);
}
} else {
File file = new File(componentFullPath);
if (file != null && file.exists()) {
org.talend.utils.io.FilesUtils.deleteFolder(file, true);
}
}
}
if (!backAdded.isEmpty()) {
getCustomComponentSettings().removeAll(backAdded.values());
}
FileFilter ff = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (FilesUtils.isSVNFolder(pathname)) {
return false;
}
return true;
}
};
// share
for (IComponent component : sharedAdded.keySet()) {
String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
File sourceFile = new File(sourcePath);
String targetPath = targetRoot + File.separatorChar + component.getName();
File targetFile = new File(targetPath);
FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
if (subMonitor != null) {
subMonitor.worked(10);
}
}
} catch (Exception e) {
resetCustomComponentSetting();
ExceptionHandler.process(e);
}
try {
prf.saveProject(pro);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
try {
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
throw new PersistenceException(e.getCause());
}
}
};
repositoryWorkUnit.setRefreshRepository(false);
repositoryWorkUnit.setForceTransaction(true);
prf.executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
e.printStackTrace();
}
}
if (monitor != null) {
monitor.done();
}
// refresh again after the gui closed .
try {
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
Aggregations