package com.nbsp.materialfilepicker.utils;

import java.io.File;
import java.io.FileFilter;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by Dimorinny on 24.10.15.
 */
public class FileUtils {
    public static List<File> getFileListByDirPath(String path, FileFilter filter) {
        File directory = new File(path);
        List<File> result = Arrays.asList(directory.listFiles(filter));
        Collections.sort(result, new FileComparator());
        return result;
    }

    public static String cutLastSegmentOfPath(String path) {
        return path.substring(0, path.lastIndexOf("/"));
    }

    public static String getReadableFileSize(long size) {
        if (size <= 0) return "0";
        final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"};
        int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
        return new DecimalFormat("#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
    }
}

@@ -117,16 +117,44 @@
 Format;%0A
+import java.util.ArrayList;%0A
 import j
@@ -431,69 +431,178 @@
     
-List%3CFile%3E result = Arrays.asList(directory.listFiles(filter)
+File%5B%5D files = directory.listFiles(filter);%0A%0A        if (files == null) %7B%0A            return new ArrayList%3C%3E();%0A        %7D%0A%0A        List%3CFile%3E result = Arrays.asList(files
 );%0A 

Add listFiles null check