org.apache.commons.io.comparator.LastModifiedFileComparator Java Examples
The following examples show how to use
org.apache.commons.io.comparator.LastModifiedFileComparator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinResourcePackRepository.java From LiquidBounce with GNU General Public License v3.0 | 6 votes |
/** * @author Mojang * @reason Fix a bug */ @Overwrite private void deleteOldServerResourcesPacks() { try { List<File> lvt_1_1_ = Lists.newArrayList(FileUtils.listFiles(this.dirServerResourcepacks, TrueFileFilter.TRUE, null)); Collections.sort(lvt_1_1_, LastModifiedFileComparator.LASTMODIFIED_REVERSE); int lvt_2_1_ = 0; Iterator lvt_3_1_ = lvt_1_1_.iterator(); while(lvt_3_1_.hasNext()) { File lvt_4_1_ = (File) lvt_3_1_.next(); if(lvt_2_1_++ >= 10) { logger.info("Deleting old server resource pack " + lvt_4_1_.getName()); FileUtils.deleteQuietly(lvt_4_1_); } } }catch(final Throwable e) { e.printStackTrace(); } }
Example #2
Source File: MixinResourcePackRepository.java From LiquidBounce with GNU General Public License v3.0 | 6 votes |
/** * @author Mojang * @reason Fix a bug */ @Overwrite private void deleteOldServerResourcesPacks() { try { List<File> lvt_1_1_ = Lists.newArrayList(FileUtils.listFiles(this.dirServerResourcepacks, TrueFileFilter.TRUE, null)); Collections.sort(lvt_1_1_, LastModifiedFileComparator.LASTMODIFIED_REVERSE); int lvt_2_1_ = 0; Iterator lvt_3_1_ = lvt_1_1_.iterator(); while(lvt_3_1_.hasNext()) { File lvt_4_1_ = (File) lvt_3_1_.next(); if(lvt_2_1_++ >= 10) { logger.info("Deleting old server resource pack " + lvt_4_1_.getName()); FileUtils.deleteQuietly(lvt_4_1_); } } }catch(final Throwable e) { e.printStackTrace(); } }
Example #3
Source File: ImpalaLineageTool.java From atlas with Apache License 2.0 | 6 votes |
/** * This function figures out the right lineage file path+name to process sorted by the last * time they are modified. (old -> new) * @return get the lineage files from given directory with given prefix. */ public File[] getCurrentFiles() { try { LOG.info("Scanning: " + directoryName); File folder = new File(directoryName); File[] listOfFiles = folder.listFiles((FileFilter) new PrefixFileFilter(prefix, IOCase.SENSITIVE)); if ((listOfFiles == null) || (listOfFiles.length == 0)) { LOG.info("Found no lineage files."); return new File[0]; } if(listOfFiles.length > 1) { Arrays.sort(listOfFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); } LOG.info("Found {} lineage files" + listOfFiles.length); return listOfFiles; } catch(Exception e) { LOG.error("Import lineage file failed.", e); } return new File[0]; }
Example #4
Source File: SingerUtils.java From singer with Apache License 2.0 | 5 votes |
public int compare(File file1, File file2) { int lastModifiedTimeComparison = LastModifiedFileComparator.LASTMODIFIED_COMPARATOR.compare(file1, file2); if (lastModifiedTimeComparison != 0) { return lastModifiedTimeComparison; } int fileNameLengthComparsion = file2.getName().length() - file1.getName().length(); if (fileNameLengthComparsion != 0) { return fileNameLengthComparsion; } return NameFileComparator.NAME_REVERSE.compare(file1, file2); }
Example #5
Source File: ThriftLogGenerator.java From singer with Apache License 2.0 | 5 votes |
private void removeLogFileIfNeeded(int numOfLogFiles) throws IOException { File dir = new File(logDir); FilenameFilter filter = new PrefixFileFilter(logFileName); List<File> files = Arrays.asList(dir.listFiles(filter)); Collections.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); if (files.size() > numOfLogFiles) { for (int i = 0; i < files.size() - numOfLogFiles; ++i) { FileUtils.forceDelete(files.get(i)); System.out.print( String.format( "Removed log file: %s.\n", files.get(i).getPath())); } } }
Example #6
Source File: LogStream.java From singer with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public void initialize() throws IOException { SingerLogConfig singerLogConfig = singerLog.getSingerLogConfig(); String regexStr = fileNamePrefix; File logDir = new File(singerLogConfig.getLogDir()); if (singerLogConfig.getFilenameMatchMode() == FileNameMatchMode.PREFIX) { regexStr += ".*"; } LOG.info("Matching files under {} with filter {}", logDir, regexStr); FileFilter fileFilter = new RegexFileFilter(regexStr); File[] files = logDir.listFiles(fileFilter); // Sort the file first by last_modified timestamp and then by name in case two files have // the same mtime due to precision (mtime is up to seconds). Ordering ordering = Ordering.from( new CompositeFileComparator( LastModifiedFileComparator.LASTMODIFIED_COMPARATOR, NameFileComparator.NAME_REVERSE)); List<File> logFiles = ordering.sortedCopy(Arrays.asList(files)); LOG.info(files.length + " files matches the regex '{}'", regexStr); synchronized (logFilesInfoLock) { logFilePaths.clear(); logFilePathsIndex.clear(); for (File entry : logFiles) { long inode = SingerUtils.getFileInode(entry.toPath()); append(new LogFile(inode), entry.toPath().toString()); } } OpenTsdbMetricConverter.incr(SingerMetrics.LOGSTREAM_INITIALIZE, 1, "log=" + logStreamName, "host=" + SingerUtils.getHostname()); }
Example #7
Source File: NavigationHelper.java From Android-FileBrowser-FilePicker with MIT License | 5 votes |
public ArrayList<FileItem> getFilesItemsInCurrentDirectory() { Operations op = Operations.getInstance(mContext); Constants.SORT_OPTIONS option = op.getmCurrentSortOption(); Constants.FILTER_OPTIONS filterOption = op.getmCurrentFilterOption(); if (mFileNavigator.getmCurrentNode() == null) mFileNavigator.setmCurrentNode(mFileNavigator.getmRootNode()); File[] files = mFileNavigator.getFilesInCurrentDirectory(); if (files != null) { mFiles.clear(); Comparator<File> comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR; switch(option) { case SIZE: comparator = SizeFileComparator.SIZE_COMPARATOR; break; case LAST_MODIFIED: comparator = LastModifiedFileComparator.LASTMODIFIED_COMPARATOR; break; } Arrays.sort(files,comparator); for (int i = 0; i < files.length; i++) { boolean addToFilter = true; switch(filterOption) { case FILES: addToFilter = !files[i].isDirectory(); break; case FOLDER: addToFilter = files[i].isDirectory(); break; } if (addToFilter) mFiles.add(new FileItem(files[i])); } } return mFiles; }
Example #8
Source File: ReportSourceLocator.java From pitest with Apache License 2.0 | 5 votes |
private File executeLocator(File reportsDirectory, Log log) { File[] subdirectories = reportsDirectory .listFiles(TIMESTAMPED_REPORTS_FILE_FILTER); File latest = reportsDirectory; log.debug("ReportSourceLocator starting search in directory [" + reportsDirectory.getAbsolutePath() + "]"); if (subdirectories != null) { LastModifiedFileComparator c = new LastModifiedFileComparator(); for (File f : subdirectories) { log.debug("comparing directory [" + f.getAbsolutePath() + "] with the current latest directory of [" + latest.getAbsolutePath() + "]"); if (c.compare(latest, f) < 0) { latest = f; log.debug("directory [" + f.getAbsolutePath() + "] is now the latest"); } } } else { throw new PitError("could not list files in directory [" + reportsDirectory.getAbsolutePath() + "] because of an unknown I/O error"); } log.debug("ReportSourceLocator determined directory [" + latest.getAbsolutePath() + "] is the directory containing the latest pit reports"); return latest; }
Example #9
Source File: LocalStorage.java From ods-provisioning-app with Apache License 2.0 | 4 votes |
/** * Load all files from the defined storage path and map them to the corresponding object * * <p>TODO Fix comparator, because it does not sort in the correct order * * @return a desc date sorted list of projects */ @Override public Map<String, OpenProjectData> listProjectHistory() { HashMap<String, OpenProjectData> history = new HashMap<>(); try { File folder = new File(localStoragePath); if (folder.isDirectory()) { File[] fileList = folder.listFiles(); Arrays.sort(fileList, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); for (File file : fileList) { if (!file.isDirectory() && !file.isHidden() && file.getName().endsWith(".txt")) { logger.debug("File {}:", file); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); DateTimeFormatter targetDt = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); String project = FileUtils.readFileToString(file); LocalDateTime dt = LocalDateTime.parse(file.getName().substring(0, 14), formatter); ProjectData temp = null; try { temp = MAPPER.readValue(project, ProjectData.class); } catch (Exception MapperEx) { // legacy :) } OpenProjectData data = null; if (temp != null && temp.key != null) { data = ProjectData.toOpenProjectData((ProjectData) temp); logger.debug("Project {} is in legacy format, upgrading.", data.projectKey); } else { try { data = MAPPER.readValue(project, OpenProjectData.class); logger.debug("Project {} is in std format", data.projectKey); } catch (PropertyBindingException crackedFileEx) { logger.error("Project {} is CRACKED - skipping", file.getName()); continue; } } data.physicalLocation = file.getAbsolutePath(); history.put(dt.format(targetDt), data); } } } } catch (IOException ex) { logger.error("Unable to read history", ex); } return history; }