Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.javaswift.joss.util;
 
 
 import java.io.*;
 import java.net.URL;
public class FileAction {
    public static void handleEntity(File targetFileHttpEntity entitythrows IOException {
        OutputStream output = null;
        try {
            output = new FileOutputStream(targetFile);
            IOUtils.copy(entity.getContent(), output);
        } finally {
            close(output);
        }
    }
    public static String getMd5(File filethrows IOException {
        InputStream input = null;
        try {
            input = new FileInputStream(file);
            return DigestUtils.md5Hex(input);
        } finally {
            close(input);
        }
    }
    protected static void close(Closeable closeablethrows IOException {
        if (closeable != null) {
            closeable.close();
        }
    }
    public static List<FileReferencelistFiles(File root) {
        return listFiles(rootnew String[] {});
    }
    public static List<FileReferencelistFiles(File rootString[] ignoreFilters) {
        List<FileReferencefiles = new ArrayList<FileReference>();
        List<Stringpath = new ArrayList<String>();
        if (root.isDirectory()) {
            listFiles(filespathrootignoreFilters);
        }
        return files;
    }
    @SuppressWarnings("ConstantConditions")
    protected static void listFiles(List<FileReferencefilesList<StringpathFile directoryFileString[] ignoreFilters) {
        for (File currentFile : directoryFile.listFiles()) {
            if (ignore(pathignoreFilters)) {
                continue;
            }
            List<StringcurrentPath = getPath(pathcurrentFile.getName());
            if (currentFile.isDirectory()) {
                listFiles(filescurrentPathcurrentFileignoreFilters);
            } else {
                files.add(new FileReference(currentFilecurrentPath));
            }
        }
    }
    protected static boolean ignore(List<StringpathAndFileString[] ignoreFilters) {
        String path = FileReference.getPath(0, pathAndFile);
        for (String ignoreFilter : ignoreFilters) {
            if (path.equals(ignoreFilter)) {
                return true;
            }
        }
        return false;
    }
    protected static List<StringgetPath(List<StringcurrentPathString extension) {
        List<Stringpath = new ArrayList<String>();
        path.addAll(currentPath);
        path.add(extension);
        return path;
    }
    public static File getFile(String resourcethrows IOExceptionURISyntaxException {
        ClassLoader classLoader = FileAction.class.getClassLoader();
        Enumeration<URLurls = classLoader.getResources(resource);
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            if (url.getProtocol().equals("file")) {
                return new File(url.toURI());
            }
        }
        return null;
    }
New to GrepCode? Check out our FAQ X