当前位置: 首页>>代码示例>>Java>>正文


Java LastModifiedFileComparator类代码示例

本文整理汇总了Java中org.apache.commons.io.comparator.LastModifiedFileComparator的典型用法代码示例。如果您正苦于以下问题:Java LastModifiedFileComparator类的具体用法?Java LastModifiedFileComparator怎么用?Java LastModifiedFileComparator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LastModifiedFileComparator类属于org.apache.commons.io.comparator包,在下文中一共展示了LastModifiedFileComparator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteOldServerResourcesPacks

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
/**
 * Keep only the 10 most recent resources packs, delete the others
 */
private void deleteOldServerResourcesPacks()
{
    try
    {
        List<File> list = Lists.newArrayList(FileUtils.listFiles(this.dirServerResourcepacks, TrueFileFilter.TRUE, (IOFileFilter)null));
        Collections.sort(list, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
        int i = 0;

        for (File file1 : list)
        {
            if (i++ >= 10)
            {
                LOGGER.info("Deleting old server resource pack {}", new Object[] {file1.getName()});
                FileUtils.deleteQuietly(file1);
            }
        }
    }
    catch (IllegalArgumentException illegalargumentexception)
    {
        LOGGER.error("Error while deleting old server resource pack : {}", new Object[] {illegalargumentexception.getMessage()});
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:26,代码来源:ResourcePackRepository.java

示例2: findByDate

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
private void findByDate(String param){
    SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
    SimpleDateFormat df2 = new SimpleDateFormat("dd-MMM-yyyy");
    LastModifiedFileComparator c = new LastModifiedFileComparator();
    
    Date file = new Date();
    String d = df.format(file);
    sorted.clear();

    List<File> l1 = new ArrayList<>();
    toSort.stream().filter((image) -> ( df2.format(new File(image).lastModified()).equals(d))).forEach((image) -> {
        l1.add(new File(image));
    });

    List<File> f = c.sort(l1);
    f.forEach(x ->{
        sorted.add(x.getAbsolutePath());
    });
}
 
开发者ID:Obsidiam,项目名称:joanne,代码行数:20,代码来源:Sorter.java

示例3: func_183028_i

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
private void func_183028_i()
{
    List<File> list = Lists.newArrayList(FileUtils.listFiles(this.dirServerResourcepacks, TrueFileFilter.TRUE, (IOFileFilter)null));
    Collections.sort(list, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
    int i = 0;

    for (File file1 : list)
    {
        if (i++ >= 10)
        {
            logger.info("Deleting old server resource pack " + file1.getName());
            FileUtils.deleteQuietly(file1);
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:16,代码来源:ResourcePackRepository.java

示例4: getTheNewestFile

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
public File getTheNewestFile(File directory, String extension) {
    File newestFile = null;
    if (directory == null || !directory.exists() || !directory.isDirectory()) {
    	return newestFile;
    }

    FileFilter fileFilter = new WildcardFileFilter("*." + extension);
    File[] files = directory.listFiles(fileFilter);

    if (files.length > 0) {
        Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
        newestFile = files[0];
    }

    return newestFile;
}
 
开发者ID:fastconnect,项目名称:tibco-fcunit,代码行数:17,代码来源:MenuPage.java

示例5: getFilesItemsInCurrentDirectory

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
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;
}
 
开发者ID:adityak368,项目名称:Android-FileBrowser-FilePicker,代码行数:35,代码来源:NavigationHelper.java

示例6: doInBackground

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
/**
 * This method is called when invoke <b>execute()</b>.<br />
 * Do not invoke manually. Use: <i>new Daemon().execute("");</i>
 *
 * @param params blank string.
 * @return null if all is going ok.
 */
@Override
protected String doInBackground(String... params) {

    while (folder.listFiles().length > 0)
    {
        // Select only files, no directory.
        File[] files = folder.listFiles((FileFilter) FileFileFilter.FILE);
        // Sorting following FIFO idea.
        Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);

        if (files[0].getName().endsWith(".csv") || files[0].getName().endsWith(".txt")) {
            String commandsList = "";
            try {
                commandsList = f.getStringFromFile(files[0].getPath());
            } catch (Exception e) {
                e.printStackTrace();
            }
            Log.e(TAG, "Lista comandi: " + commandsList);
            Interpreter in = new Interpreter(deviceController);
            in.doListCommands(commandsList);
            files[0].delete();
        } else {
            Log.e(TAG, "Error: There is no csv|txt files or is not a file but a directory.");
        }
    }
    return null;
}
 
开发者ID:Bayway,项目名称:JumperSumo,代码行数:35,代码来源:Daemon.java

示例7: findLatestFileByLastModified

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
/**
 * Find latest file by last modified.
 *
 * @param fileNamePattern the file name pattern
 * @param directory the directory
 * @param recursive the recursive
 * @return the string
 */
public static String findLatestFileByLastModified( final String directory, final String fileNamePattern,
                                                   final boolean recursive )
{

    // check that file name is not null or blank and is a valid pattern
    if ( StringUtils.isBlank( fileNamePattern ) || !FileUtil.isValidPattern( fileNamePattern ) )
    {
        logger.warn( "In findFileByLastModified, file name '{}' is either null or blank or is not a valid pattern.",
                     fileNamePattern );
        return null;
    }

    // check that directory is not null or empty (string) and exists.
    if ( !FileUtil.isDirExists( directory ) )
    {
        logger.warn( "In findLatestFileByLastModified, directory '{}' is either null or empty or does not exist.",
                     directory );
        return null;
    }

    // find files matching pattern in the directory
    File[] files = FileUtil.findFiles( directory, fileNamePattern, recursive );
    if ( files == null || files.length == 0 )
    {
        logger.warn( "In findLatestFileByLastModified, no files found matching pattern '{}' in directory '{}'.",
                     fileNamePattern, directory );
        return null;
    }

    // Sort the array to get the newest file come first
    Arrays.sort( files, LastModifiedFileComparator.LASTMODIFIED_REVERSE );
    String fileName = files[0].getAbsolutePath();
    logger.debug( "In findLatestFileByLastModified, latest file in the directory '{}' "
        + "matching the file name pattern '{}' is '{}'.", directory, fileNamePattern, fileName );
    return fileName;
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:45,代码来源:FileUtil.java

示例8: listWatchedFolder

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
@HandlesEvent("listWatchedFolders")
public Resolution listWatchedFolder() {
    ArrayList<HashMap<String, String>> folders = new ArrayList<HashMap<String, String>>();
    // CHECK THIS Does import have / will have sub directories, or just ingest dir?
    String watchedDir = this.getIngestDirectory(true);
    File dir = new File(watchedDir);

    HashMap<String, String> root = new HashMap<String, String>();
    root.put("name", "ROOT");
    folders.add(root);
    int rootcount = 0;

    if (!dir.exists()) {
    	folders.get(0).put("count", String.valueOf(rootcount));
    	return new StreamingResolution(MIME_JS, new flexjson.JSONSerializer().serialize(folders));
	}
    File[] folderList = dir.listFiles();
    // Sort folders by their modification date, descending order
    Arrays.sort(folderList, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
    for (File file : folderList) {
        if (file.isDirectory()) {
            HashMap<String, String> entry = new HashMap<String, String>();
            entry.put("name", file.getName());
            int count = file.listFiles().length;
            entry.put("count", String.valueOf(count));
            folders.add(entry);
        } else {
            rootcount++;
        }
    }

    folders.get(0).put("count", String.valueOf(rootcount));
    
    return new StreamingResolution(MIME_JS, new flexjson.JSONSerializer().serialize(folders));
}
 
开发者ID:mikkeliamk,项目名称:osa,代码行数:36,代码来源:IngestAction.java

示例9: getLatestAnnotationOutputFileInDirectory

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
/**
 * Returns the latest annotation file in a directory.
 * 
 * @param directory directory to search for annotation files
 * @return Last modified annotation file or null if no annotation file
 *         exists in the directory
 * @throws IOException When reading the directory fails.
 */
public static File getLatestAnnotationOutputFileInDirectory(File directory)
    throws IOException {
  File[] filesInDir = Helper.getAnnotationFilesInDirectory(directory);
  Arrays.sort(filesInDir, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
  if (filesInDir.length > 0) {
    return filesInDir[0];
  }
  return null;
}
 
开发者ID:shell88,项目名称:bdd_videoannotator,代码行数:18,代码来源:TestUtils.java

示例10: saveJSON

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
public static void saveJSON(File file, Object toSave, boolean isClient, boolean backups) {
    try {
        if (Options.debugMode) Progression.logger.log(Level.INFO, "Writing to the file is being done at saveJSON");

        //Make a backup
        if (Options.enableCriteriaBackups && backups) {
            File backup = FileHelper.getBackupFile(serverName, isClient);
            FileUtils.copyFile(file, backup);
            File[] files = FileHelper.getBackup().listFiles();
            if (files.length > Options.maximumCriteriaBackups) {
                Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
                for (File filez : files) {
                    filez.delete();
                    break;
                }
            }
        }

        Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
        writer.write(getGson().toJson(toSave));
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (Options.debugMode) Progression.logger.log(Level.INFO, "Saved JSON at " + System.currentTimeMillis());
}
 
开发者ID:joshiejack,项目名称:Progression,代码行数:28,代码来源:JSONLoader.java

示例11: getLogLines

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
/**
 * Gets lines from the log file which corresponds with specified correlation ID.
 *
 * @param correlationId the correlation ID
 * @param logDate which date to search log files for
 * @return log lines
 * @throws IOException when error occurred during file reading
 */
List<String> getLogLines(String correlationId, Date logDate) throws IOException {
    File logFolder = new File(logFolderPath);
    if (!logFolder.exists() || !logFolder.canRead()) {
        throw new FileNotFoundException("there is no readable log folder - " + logFolderPath);
    }

    final String logDateFormatted = fileFormat.format(logDate);

    // filter log files for current date
    IOFileFilter nameFilter = new IOFileFilter() {
        @Override
        public boolean accept(File file) {
            return logNameFilter.accept(file) && (StringUtils.contains(file.getName(), logDateFormatted)
                    || file.getName().endsWith(BASE_FILE_EXTENSION));
        }

        @Override
        public boolean accept(File dir, String name) {
            return StringUtils.contains(name, logDateFormatted)
                    || name.endsWith(BASE_FILE_EXTENSION);

        }
    };

    List<File> logFiles = new ArrayList<File>(FileUtils.listFiles(logFolder, nameFilter, null));
    Collections.sort(logFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);

    // go through all log files
    List<String> logLines = new ArrayList<String>();
    for (File logFile : logFiles) {
        logLines.addAll(getLogLines(logFile, correlationId));
    }

    return logLines;
}
 
开发者ID:integram,项目名称:cleverbus,代码行数:44,代码来源:MessageLogParser.java

示例12: getLogFiles

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
public File[] getLogFiles(final DateTime date) throws FileNotFoundException {
    File logFolder = new File(logFolderPath);
    if (!logFolder.exists() || !logFolder.canRead()) {
        throw new FileNotFoundException("there is no readable log folder - " + logFolderPath);
    }

    final String logDateFormatted = FILE_DATE_FORMAT.print(date);
    final long dateMillis = date.getMillis();

    File[] files = logFolder.listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            String name = file.getName();
            return name.endsWith(FILE_EXTENSION) // it's a log file
                    && name.contains(logDateFormatted) // it contains the date in the name
                    && file.lastModified() >= dateMillis; // and it's not older than the search date
        }
    });

    Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);

    if (files.length == 0) {
        Log.debug("No log files ending with {}, containing {}, modified after {}, at {}",
                FILE_EXTENSION, logDateFormatted, date, logFolderPath);
    } else {
        Log.debug("Found log files for {}: {}", date, files);
    }

    return files;
}
 
开发者ID:integram,项目名称:cleverbus,代码行数:31,代码来源:LogParser.java

示例13: executeLocator

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
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;
}
 
开发者ID:hcoles,项目名称:pitest,代码行数:32,代码来源:ReportSourceLocator.java

示例14: cleanupRepositories

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
private void cleanupRepositories() throws Exception
{
	RepositoryManager rm =
		(RepositoryManager) servletContext.getAttribute("repositoryManager");
	
	RepositoryManager backgroundIndexingRepositoryManager = null;
	if (isBackgroundIndex)
		backgroundIndexingRepositoryManager = getBackgroundRepositoryManager();

	File repositoryBaseDir = new File(servletContext.getInitParameter("repositoryData"));
	File[] repositoryDirectories = repositoryBaseDir.listFiles();
	if(repositoryDirectories!=null && repositoryDirectories.length!=0)
	{
		Arrays.sort(repositoryDirectories, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
		int succesfullBackupCount = 0;
		int errorBackupCount = 0;
		for(File repositoryDirectory:repositoryDirectories)
		{
			
			// If the file is not a director and does not start with the prefix repository_, then its not a 
			// repos. If the directory we are looking at is the current repository or the background don't count
			// those either.
			if(!repositoryDirectory.isDirectory() || !repositoryDirectory.getName().startsWith("repository_")||
					repositoryDirectory.getAbsolutePath().equals(rm.getRepositoryDirectory().getAbsolutePath())||
					(backgroundIndexingRepositoryManager!=null && 
							repositoryDirectory.getAbsolutePath().equals(
									backgroundIndexingRepositoryManager.getRepositoryDirectory().getAbsolutePath()))
					)
				continue;
			
			// Otherwise its a backup, now figure out if its a valid repos or invalid,
			// If the repos doesn't have a summary, might be a legacy repository treat it as
			// a successful one
			IndexDataBean summary = rm.getIndexSummary(repositoryDirectory.getAbsoluteFile());
			if(summary==null || summary.getIndexStatus().equals(IndexDataBean.STATUS_VALID))
			{
				if(succesfullBackupCount<NUM_REPO_BACKUPS)
				{
					succesfullBackupCount++;
					continue;
				}
			}
			else
			{
				// Ignored statuses are considered errored backups
				if(errorBackupCount<NUM_ERROR_REPO_BACKUPS)
				{
					errorBackupCount++;
					continue;
				}
			}
			FileUtils.deleteDirectory(repositoryDirectory);
		}
	}		
}
 
开发者ID:NCAR,项目名称:dls-repository-stack,代码行数:56,代码来源:Maintenance.java

示例15: importRepositories

import org.apache.commons.io.comparator.LastModifiedFileComparator; //导入依赖的package包/类
public void importRepositories() throws Exception
{		
	RepositoryManager repositoryManager = (RepositoryManager) servletContext.getAttribute("repositoryManager");
	File repositoryBaseDir = new File(servletContext.getInitParameter("repositoryData"));
	
	File firstAddedRepository = null;
	if(importRepositoryDestinationString!=null)
	{
		for(String destination:importRepositoryDestinationString.split(","))
		{
			File destinationDirecotry = new File(destination);
			if(!destinationDirecotry.exists() || !destinationDirecotry.isDirectory())
			{
				prtlnErr(destination+ " is not a valid directory that can hold repositories.");
				continue;
			}
			File[] possibleRepositories = new File(destination).listFiles();
			Arrays.sort(possibleRepositories, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
			for(File possibleRepository:possibleRepositories)
			{
				if(!possibleRepository.isDirectory() || !possibleRepository.getName().startsWith("repository_"))
						continue;
				IndexDataBean summary = repositoryManager.getIndexSummary(possibleRepository);
				if(summary!=null && summary.getIndexStatus().equals(IndexDataBean.STATUS_VALID))
				{
					prtln(String.format("External repository %s was found at %s and is being copied into a local directory.", 
							possibleRepository.getName(), destination));
					FileUtils.moveDirectoryToDirectory(possibleRepository, repositoryBaseDir, false);
					
					// We need to change the index path to point the the new location, set the new one
					// and write it
					File newRepository = new File(repositoryBaseDir, possibleRepository.getName());
					summary.getIndexDetail().put(IndexDataBean.INDEX_PATH,  newRepository.getAbsolutePath());
					repositoryManager.writeIndexSummary(summary, newRepository);
					if(firstAddedRepository==null)
						firstAddedRepository = newRepository;
				}
				else
				{
					// if its not a valid index or if it doesn't have a summary get rid of it
					FileUtils.deleteDirectory(possibleRepository);
				}
			}
		}
	}
	if(firstAddedRepository!=null)
	{
		prtln(String.format("Making imported repository %s current.", firstAddedRepository.getName()));
		// Only set it at live if the option for makeImportedRepositories is true
		if(getRepositoryInfoBean().isMakeImportedRepositoriesCurrentRepository())
			this.setCurrentRepository(firstAddedRepository.getAbsolutePath(),false, true);
		
		// To make sure a repository that is never turned off nor does its own indexing.
		// gets to many indexes loaded we call cleanup to keep the file disk usage down
		this.cleanupRepositories();
	}
}
 
开发者ID:NCAR,项目名称:dls-repository-stack,代码行数:58,代码来源:Maintenance.java


注:本文中的org.apache.commons.io.comparator.LastModifiedFileComparator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。