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:de.mgd.simplesoundboard.dao.FileSystemSoundResourceDao.java
@Override public List<String> findSoundCategories() { List<File> files = findFilesInStorageDirectoryIfAny(this::isSoundCategory); if (files.isEmpty()) { return Collections.emptyList(); }/*from w w w .j a v a2 s. c om*/ files.sort(NameFileComparator.NAME_INSENSITIVE_COMPARATOR); return files.stream().map(File::getName).collect(Collectors.toList()); }
From source file:de.mgd.simplesoundboard.dao.FileSystemSoundResourceDao.java
@Override public List<SoundResource> findExistingSoundResources(final String category) { List<File> files = findFilesInStorageDirectoryIfAny(this::isMediaFile, category); if (files.isEmpty()) { return Collections.emptyList(); }/*w w w.ja v a 2 s. co m*/ files.sort(NameFileComparator.NAME_INSENSITIVE_COMPARATOR); return files.stream().map(f -> soundResourceService.createSoundResourceFromFile(f)) .collect(Collectors.toList()); }
From source file:com.psaravan.filebrowserview.lib.FileBrowserEngine.FileBrowserEngine.java
/** * Loads the specified folder./*from www . j av a 2s . com*/ * * @param directory The file object to points to the directory to load. * @return An {@link AdapterData} object that holds the data of the specified directory. */ public AdapterData loadDir(File directory) { mCurrentDir = directory; //Init the directory's data arrays. ArrayList<String> namesList = new ArrayList<String>(); ArrayList<String> pathsList = new ArrayList<String>(); ArrayList<Integer> typesList = new ArrayList<Integer>(); ArrayList<String> sizesList = new ArrayList<String>(); //Grab a list of all files/subdirs within the specified directory. File[] files = directory.listFiles(); if (files != null) { //Sort the files/subdirs by name. Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i]; if ((!file.isHidden() || mFileBrowserView.shouldShowHiddenFiles()) && file.canRead()) { if (file.isDirectory() && mFileBrowserView.shouldShowFolders()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); pathsList.add(filePath); namesList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { typesList.add(FOLDER); if (listOfFiles.length == 1) { sizesList.add("" + listOfFiles.length + " item"); } else { sizesList.add("" + listOfFiles.length + " items"); } } else { typesList.add(FOLDER); sizesList.add("Unknown items"); } } else { try { String path = file.getCanonicalPath(); //Check if the file ends with an excluded extension. String[] splits = path.split("."); if (mFileBrowserView.getFileExtensionFilter().getFilterMap() .containsKey("." + splits[splits.length - 1])) continue; pathsList.add(path); } catch (IOException e) { continue; } namesList.add(file.getName()); String fileName = ""; try { fileName = file.getCanonicalPath(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Add the file element to typesList based on the file type. if (getFileExtension(fileName).equalsIgnoreCase("mp3") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("m4a") || getFileExtension(fileName).equalsIgnoreCase("aac") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("flac") || getFileExtension(fileName).equalsIgnoreCase("mid") || getFileExtension(fileName).equalsIgnoreCase("xmf") || getFileExtension(fileName).equalsIgnoreCase("mxmf") || getFileExtension(fileName).equalsIgnoreCase("midi") || getFileExtension(fileName).equalsIgnoreCase("rtttl") || getFileExtension(fileName).equalsIgnoreCase("rtx") || getFileExtension(fileName).equalsIgnoreCase("ota") || getFileExtension(fileName).equalsIgnoreCase("imy") || getFileExtension(fileName).equalsIgnoreCase("ogg") || getFileExtension(fileName).equalsIgnoreCase("mkv") || getFileExtension(fileName).equalsIgnoreCase("wav")) { //The file is an audio file. typesList.add(FILE_AUDIO); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("jpg") || getFileExtension(fileName).equalsIgnoreCase("gif") || getFileExtension(fileName).equalsIgnoreCase("png") || getFileExtension(fileName).equalsIgnoreCase("bmp") || getFileExtension(fileName).equalsIgnoreCase("webp")) { //The file is a picture file. typesList.add(FILE_PICTURE); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("webm") || getFileExtension(fileName).equalsIgnoreCase("mkv")) { //The file is a video file. typesList.add(FILE_VIDEO); sizesList.add("" + getFormattedFileSize(file.length())); } else { //We don't have an icon for this file type so give it the generic file flag. typesList.add(FILE_GENERIC); sizesList.add("" + getFormattedFileSize(file.length())); } } } } } return new AdapterData(namesList, typesList, pathsList, sizesList); }
From source file:ie.programmer.catcher.browser.FileBrowserEngine.FileBrowserEngine.java
/** * Loads the specified folder./*from w w w. j av a2 s . co m*/ * * @param directory The file object to points to the directory to load. * @return An {@link AdapterData} object that holds the data of the specified directory. */ public AdapterData loadDir(File directory) { mCurrentDir = directory; //Init the directory's data arrays. ArrayList<String> namesList = new ArrayList<String>(); ArrayList<String> pathsList = new ArrayList<String>(); ArrayList<Integer> typesList = new ArrayList<Integer>(); ArrayList<String> sizesList = new ArrayList<String>(); //Grab a list of all files/subdirs within the specified directory. File[] files = directory.listFiles(); if (files != null) { //Sort the files/subdirs by name. Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i]; if ((!file.isHidden() || mFileBrowserView.shouldShowHiddenFiles()) && file.canRead()) { if (file.isDirectory() && mFileBrowserView.shouldShowFolders()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); pathsList.add(filePath); namesList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { typesList.add(FOLDER); if (listOfFiles.length == 1) { sizesList.add("" + listOfFiles.length + " item"); } else { sizesList.add("" + listOfFiles.length + " items"); } } else { typesList.add(FOLDER); sizesList.add("Unknown items"); } } else { try { String path = file.getCanonicalPath(); if (isFilteredFile(path)) { continue; } pathsList.add(path); } catch (Exception e) { Log.e("File Error", e.getMessage()); continue; } namesList.add(file.getName()); String fileName = ""; try { fileName = file.getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); } //Add the file element to typesList based on the file type. if (getFileExtension(fileName).equalsIgnoreCase("mp3") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("m4a") || getFileExtension(fileName).equalsIgnoreCase("aac") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("flac") || getFileExtension(fileName).equalsIgnoreCase("mid") || getFileExtension(fileName).equalsIgnoreCase("xmf") || getFileExtension(fileName).equalsIgnoreCase("mxmf") || getFileExtension(fileName).equalsIgnoreCase("midi") || getFileExtension(fileName).equalsIgnoreCase("rtttl") || getFileExtension(fileName).equalsIgnoreCase("rtx") || getFileExtension(fileName).equalsIgnoreCase("ota") || getFileExtension(fileName).equalsIgnoreCase("imy") || getFileExtension(fileName).equalsIgnoreCase("ogg") || getFileExtension(fileName).equalsIgnoreCase("mkv") || getFileExtension(fileName).equalsIgnoreCase("wav")) { //The file is an audio file. typesList.add(FILE_AUDIO); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("jpg") || getFileExtension(fileName).equalsIgnoreCase("gif") || getFileExtension(fileName).equalsIgnoreCase("png") || getFileExtension(fileName).equalsIgnoreCase("bmp") || getFileExtension(fileName).equalsIgnoreCase("webp")) { //The file is a picture file. typesList.add(FILE_PICTURE); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("webm") || getFileExtension(fileName).equalsIgnoreCase("mkv")) { //The file is a video file. typesList.add(FILE_VIDEO); sizesList.add("" + getFormattedFileSize(file.length())); } else { //We don't have an icon for this file type so give it the generic file flag. typesList.add(FILE_GENERIC); sizesList.add("" + getFormattedFileSize(file.length())); } } } } } return new AdapterData(namesList, typesList, pathsList, sizesList); }
From source file:com.meltmedia.cadmium.core.config.impl.YamlConfigurationParser.java
/** * This will only parse the files with the extensions of <code>.yml</code> or <code>.yaml</code> in the directory specified. *///from w ww . jav a 2 s. c om @Override public void parseDirectory(File configurationDirectory) throws Exception { this.configurationDirectory = configurationDirectory; if (configurationDirectory != null && configurationDirectory.isDirectory() && configurationDirectory.canRead()) { Collection<File> configFiles = FileUtils.listFiles(configurationDirectory, new String[] { "yml", "yaml" }, true); List<File> files = new ArrayList<File>(configFiles); Collections.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); Map<String, Map<String, ?>> configurationMap = new HashMap<String, Map<String, ?>>(); Yaml yamlParser = new Yaml(getClassTags()); for (File configFile : files) { FileReader reader = null; try { reader = new FileReader(configFile); for (Object parsed : yamlParser.loadAll(reader)) { mergeConfigs(configurationMap, parsed); } } finally { IOUtils.closeQuietly(reader); } } this.configuration = configurationMap; } else if (configurationDirectory != null && configurationDirectory.isDirectory()) { logger.warn("Directory {} cannot be read.", configurationDirectory); } else if (configurationDirectory != null) { logger.warn("Directory {} is not a directory or does not exist.", configurationDirectory); } else { throw new IllegalArgumentException("The configurationDirectory must be specified."); } }
From source file:com.soebes.maven.plugins.iterator.AbstractIteratorMojo.java
protected Comparator<File> convertSortOrder() { Comparator<File> result = NameFileComparator.NAME_COMPARATOR; if (getSortOrder().equalsIgnoreCase("NAME_INSENSITIVE_COMPARATOR")) { result = NameFileComparator.NAME_INSENSITIVE_COMPARATOR; } else if (getSortOrder().equalsIgnoreCase("NAME_INSENSITIVE_REVERSE")) { result = NameFileComparator.NAME_INSENSITIVE_REVERSE; } else if (getSortOrder().equalsIgnoreCase("NAME_REVERSE")) { result = NameFileComparator.NAME_REVERSE; } else if (getSortOrder().equalsIgnoreCase("NAME_SYSTEM_COMPARATOR")) { result = NameFileComparator.NAME_SYSTEM_COMPARATOR; } else if (getSortOrder().equalsIgnoreCase("NAME_SYSTEM_REVERSE")) { result = NameFileComparator.NAME_SYSTEM_REVERSE; }/*www. ja va2s . c o m*/ return result; }
From source file:bjerne.gallery.service.impl.GalleryServiceImpl.java
@Override public List<GalleryFile> getDirectoryListingFiles(String publicPath) throws IOException, NotAllowedException { File dir = getRealFileOrDir(publicPath); if (!dir.isDirectory()) { LOG.debug("File {} is not a directory. Returning null.", dir); return null; }/* w w w . ja v a 2 s . c o m*/ Collection<File> fileCollection = (Collection<File>) listFiles(dir, fileFilter, null); List<File> fileList = new ArrayList<File>(fileCollection); Collections.sort(fileList, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); LOG.debug("Found {} files for path {}", fileList.size(), publicPath); ArrayList<GalleryFile> galleryFiles = new ArrayList<GalleryFile>(fileList.size()); for (File oneFile : fileList) { galleryFiles.add(createGalleryFile(publicPath + '/' + oneFile.getName(), oneFile)); } return galleryFiles; }
From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java
/** * Retrieves the folder hierarchy for the specified folder. * * @param dirPath The path of the new folder. * @param restoreState The state of the ListView that should be restored. Pass * null if the ListView's position should not be restored. *///w w w. j a v a 2 s . c o m private void getDir(String dirPath, Parcelable restoreState) { ((MainActivity) getActivity()).showFolderFragmentActionItems(dirPath, getActivity().getMenuInflater(), ((MainActivity) getActivity()).getMenu(), mIsPasteShown); fileFolderNameList = new ArrayList<String>(); fileFolderPathList = new ArrayList<String>(); fileFolderSizeList = new ArrayList<String>(); fileFolderTypeList = new ArrayList<Integer>(); File f = new File(dirPath); File[] files = f.listFiles(); if (files != null) { //Sort the files by name. Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isHidden() == SHOW_HIDDEN_FILES && file.canRead()) { if (file.isDirectory()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); fileFolderPathList.add(filePath); fileFolderNameList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { fileFolderTypeList.add(FOLDER); if (listOfFiles.length == 1) { fileFolderSizeList.add("" + listOfFiles.length + " item"); } else { fileFolderSizeList.add("" + listOfFiles.length + " items"); } } else { fileFolderTypeList.add(FOLDER); fileFolderSizeList.add("Unknown items"); } } else { try { String path = file.getCanonicalPath(); fileFolderPathList.add(path); } catch (IOException e) { continue; } fileFolderNameList.add(file.getName()); String fileName = ""; try { fileName = file.getCanonicalPath(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Add the file element to fileFolderTypeList based on the file type. if (getFileExtension(fileName).equalsIgnoreCase("mp3") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("m4a") || getFileExtension(fileName).equalsIgnoreCase("aac") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("flac") || getFileExtension(fileName).equalsIgnoreCase("mid") || getFileExtension(fileName).equalsIgnoreCase("xmf") || getFileExtension(fileName).equalsIgnoreCase("mxmf") || getFileExtension(fileName).equalsIgnoreCase("midi") || getFileExtension(fileName).equalsIgnoreCase("rtttl") || getFileExtension(fileName).equalsIgnoreCase("rtx") || getFileExtension(fileName).equalsIgnoreCase("ota") || getFileExtension(fileName).equalsIgnoreCase("imy") || getFileExtension(fileName).equalsIgnoreCase("ogg") || getFileExtension(fileName).equalsIgnoreCase("mkv") || getFileExtension(fileName).equalsIgnoreCase("wav")) { //The file is an audio file. fileFolderTypeList.add(AUDIO_FILE); fileFolderSizeList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("jpg") || getFileExtension(fileName).equalsIgnoreCase("gif") || getFileExtension(fileName).equalsIgnoreCase("png") || getFileExtension(fileName).equalsIgnoreCase("bmp") || getFileExtension(fileName).equalsIgnoreCase("webp")) { //The file is a picture file. fileFolderTypeList.add(PICTURE_FILE); fileFolderSizeList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("webm") || getFileExtension(fileName).equalsIgnoreCase("mkv")) { //The file is a video file. fileFolderTypeList.add(VIDEO_FILE); fileFolderSizeList.add("" + getFormattedFileSize(file.length())); } else { //We don't have an icon for this file type so give it the generic file flag. fileFolderTypeList.add(FILE); fileFolderSizeList.add("" + getFormattedFileSize(file.length())); } } } } } FoldersListViewAdapter foldersListViewAdapter = new FoldersListViewAdapter(getActivity(), this, fileFolderNameList, fileFolderTypeList, fileFolderSizeList, fileFolderPathList); listView.setAdapter(foldersListViewAdapter); foldersListViewAdapter.notifyDataSetChanged(); //Restore the ListView's previous state. if (restoreState != null) { listView.onRestoreInstanceState(restoreState); } else if (mFolderStateMap.containsKey(dirPath)) { listView.onRestoreInstanceState(mFolderStateMap.get(dirPath)); } listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) { //Store the current folder's state in the HashMap. if (mFolderStateMap.size() == 3) { mFolderStateMap.clear(); } mFolderStateMap.put(currentDir, listView.onSaveInstanceState()); String newPath = fileFolderPathList.get(index); if ((Integer) view.getTag(R.string.folder_list_item_type) == FOLDER) currentDir = newPath; //Check if the selected item is a folder or a file. if (fileFolderTypeList.get(index) == FOLDER) { getDir(newPath, null); } else { int fileIndex = 0; for (int i = 0; i < index; i++) { if (fileFolderTypeList.get(i) == AUDIO_FILE) fileIndex++; } play(fileFolderTypeList.get(index), fileIndex, currentDir); } } }); }
From source file:com.rsmart.kuali.kfs.cr.batch.CheckReconciliationImportStep.java
/** * Get File List//from w w w .jav a2s . c o m * * @return List * @throws Exception */ private List<String> getFileList() throws Exception { List<String> fileList = new ArrayList<String>(); String prop = kualiConfigurationService.getPropertyValueAsString( com.rsmart.kuali.kfs.sys.KFSConstants.STAGING_DIRECTORY_KEY) + "/cr/upload"; File folder = new File(prop); if (!folder.exists()) { boolean created = folder.mkdir(); if (created) { LOG.info("Created new CR upload folder : " + folder.getAbsolutePath()); } else { throw new Exception("Unable to create folder : " + folder.getAbsolutePath()); } } else if (!folder.isDirectory()) { throw new Exception("'" + prop + "' is not a folder."); } else { File[] files = folder.listFiles(); Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { fileList.add(files[i].getAbsolutePath()); } } } return fileList; }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.code.RServe.java
public static File[] ListFilesDirectory(File filedirectory, final String[] extensions) { File dir = filedirectory;/*from w w w . ja va2s . co m*/ String[] children = dir.list(); if (children == null) { } else { for (int i = 0; i < children.length; i++) { // Get filename of the file or directory inside Plugin. String filename = children[i]; } } // Filter the extension of the file. FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(extensions[0]) || name.endsWith(extensions[1]) || name.endsWith(extensions[2]) || name.endsWith(extensions[3]) || name.endsWith(extensions[4]) || name.endsWith(extensions[5])); } }; File[] files = dir.listFiles(filter); /* Sort the filenames! */ Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); return files; }