org.apache.commons.io.comparator.SizeFileComparator Java Examples

The following examples show how to use org.apache.commons.io.comparator.SizeFileComparator. 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: StandardQuotaStrategyTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void largeContentCacheFilesAreNotKeptOnDisk() throws IOException
{
    quota.setMaxFileSizeMB(3);
    writeSingleFileInMB(1);
    writeSingleFileInMB(2);
    writeSingleFileInMB(3);
    writeSingleFileInMB(4);
    
    List<File> files = new ArrayList<File>(findCacheFiles());
    assertEquals(3, files.size());
    Collections.sort(files,SizeFileComparator.SIZE_COMPARATOR);
    assertEquals(1, files.get(0).length() / FileUtils.ONE_MB);
    assertEquals(2, files.get(1).length() / FileUtils.ONE_MB);
    assertEquals(3, files.get(2).length() / FileUtils.ONE_MB);
}
 
Example #2
Source File: NavigationHelper.java    From Android-FileBrowser-FilePicker with MIT License 5 votes vote down vote up
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 #3
Source File: CommonsIOUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenSizeFileComparator_thenLargerFile() throws IOException {

    SizeFileComparator sizeFileComparator = new SizeFileComparator();
    File largerFile = FileUtils.getFile(getClass().getClassLoader().getResource("fileTest.txt").getPath());
    File smallerFile = FileUtils.getFile(getClass().getClassLoader().getResource("sample.txt").getPath());

    int i = sizeFileComparator.compare(largerFile, smallerFile);

    Assert.assertTrue(i > 0);
}