List of usage examples for org.apache.commons.io.comparator NameFileComparator NAME_INSENSITIVE_COMPARATOR
Comparator NAME_INSENSITIVE_COMPARATOR
To view the source code for org.apache.commons.io.comparator NameFileComparator NAME_INSENSITIVE_COMPARATOR.
Click Source Link
From source file:org.cbio.portal.pipelines.foundation.FoundationFileTasklet.java
/** * Return a list of xml files sorted by date (oldest-newest). * Source XML filenames are expected to be date-controlled by <filename>_<date of transfer>.xml * if more than one date-controlled version of the source XML file exists. * @param sourceDirectory//from ww w . jav a 2s.com * @return */ private File[] getDateSortedFiles(File sourceDirectory) { File[] sourceFiles = sourceDirectory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); // sort files alphabetically by case-insensitive filename Arrays.sort(sourceFiles, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); return sourceFiles; }
From source file:org.jini.commands.files.List.java
/** * Get all the files from a array/*from ww w . java 2s . c o m*/ * * @param fileFilter * @return */ private File[] getFileArray(FileFilter fileFilter) { File dir = new File(this.directory); File[] files = dir.listFiles(fileFilter); if (this.orderByDate == true) { if (this.orderByDateOpt.equals("desc")) { Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); } if (this.orderByDateOpt.equals("asc")) { Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); } } if (this.orderByName == true) { if (this.orderByNameOpt.equals("asc")) { Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); } if (this.orderByNameOpt.equals("desc")) { Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_REVERSE); } } return files; }
From source file:org.mitre.mpf.mvc.controller.ServerMediaController.java
@RequestMapping(value = { "/server/get-all-files-filtered" }, method = RequestMethod.POST) @ResponseBody/* ww w . j ava 2 s . c o m*/ public ServerMediaFilteredListing getAllFilesFiltered( @RequestParam(value = "fullPath", required = true) String fullPath, @RequestParam(value = "draw", required = false) int draw, @RequestParam(value = "start", required = false) int start, @RequestParam(value = "length", required = false) int length, @RequestParam(value = "search", required = false) String search, @RequestParam(value = "sort", required = false) String sort) { log.debug("Params fullPath:{} draw:{} start:{},length:{},search:{} ", fullPath, draw, start, length, search, sort); File dir = new File(fullPath); if (!dir.isDirectory() && fullPath.startsWith(propertiesUtil.getServerMediaTreeRoot())) return null;//security check File[] files = dir.listFiles(File::isFile); //sort it by filename modified date (most current first) if (sort != null && sort == "lastModified") { Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); } else { Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR // Then make capital letters come before lowercase .thenComparing(NameFileComparator.NAME_COMPARATOR)); } //handle search if (search != null && search.length() > 0) { List<File> search_results = new ArrayList<File>(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (files[i].getName().toLowerCase().contains(search.toLowerCase())) { search_results.add(file); } } files = new File[search_results.size()]; files = search_results.toArray(files); } //filter by approved list of content type List<File> contentFiltered = new ArrayList<File>(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (ioUtils.isApprovedFile(file)) { contentFiltered.add(file); } } files = new File[contentFiltered.size()]; files = contentFiltered.toArray(files); int records_total = files.length; int records_filtered = records_total;// Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned for this page of data). //handle paging int end = start + length; end = (end > files.length) ? files.length : end; start = (start <= end) ? start : end; File[] filtered = Arrays.copyOfRange(files, start, end); List<ServerMediaFile> mediaFiles = new ArrayList<>(); //build output for (int i = 0; i < filtered.length; i++) { File file = filtered[i]; if (ioUtils.isApprovedFile(file)) { mediaFiles.add(new ServerMediaFile(file, ioUtils.getMimeType(file.getAbsolutePath()))); } } return new ServerMediaFilteredListing(draw, records_filtered, records_total, mediaFiles); }