Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.common.utils
Class FileUtils

java.lang.Object
  extended by org.nuxeo.common.utils.FileUtils

public final class FileUtils
extends Object

Author:
Bogdan Stefanescu

Method Summary
static void append(File src, File dst)
           
static void append(File src, File dst, boolean appendNewLine)
           
static void append(InputStream in, File file)
           
static void append(InputStream in, File file, boolean appendNewLine)
           
static void close(InputStream in)
           
static void close(OutputStream out)
           
static void collectFiles(File root, FileNamePattern pattern, List<File> result)
           
static void collectFiles(File root, List<File> result)
           
static void copy(File[] src, File dst)
           
static void copy(File src, File dst)
          Copies source to destination.
static void copy(InputStream in, OutputStream out)
           
static void copyFile(File src, File dst)
           
static void copyToFile(InputStream in, File file)
           
static void copyTree(File src, File dst)
          Copies recursively source to destination.
static void copyTree(File src, File dst, PathFilter filter)
           
static void deleteTree(File dir)
           
static void download(URL url, File file)
           
static void emptyDirectory(File dir)
           
static File[] findFiles(File root, String pattern, boolean recurse)
           
static String getFileExtension(String path)
           
static File getFileFromURL(URL url)
           
static String getFileName(String path)
           
static String getFileNameNoExt(String path)
           
static String getFilePathFromUrl(URL url)
          Decodes an URL path so that is can be processed as a filename later.
static String getParentPath(String path)
           
static File getResourceFileFromContext(String resource)
           
static String getResourcePathFromContext(String resource)
          Retrieves the total path of a resource from the Thread Context.
static String read(InputStream in)
           
static byte[] readBytes(File file)
           
static byte[] readBytes(InputStream in)
           
static byte[] readBytes(URL url)
           
static String readFile(File file)
           
static List<String> readLines(File file)
           
static List<String> readLines(InputStream in)
           
static void safeClose(Closeable stream)
           
static File urlToFile(String url)
          Create a file handler (this doesn't create a real file) given a file URI.
static File urlToFile(URL url)
           
static void writeFile(File file, byte[] buf)
           
static void writeFile(File file, String buf)
           
static void writeLines(File file, List<String> lines)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

safeClose

public static void safeClose(Closeable stream)

copy

public static void copy(InputStream in,
                        OutputStream out)
                 throws IOException
Throws:
IOException

read

public static String read(InputStream in)
                   throws IOException
Throws:
IOException

readBytes

public static byte[] readBytes(URL url)
                        throws IOException
Throws:
IOException

readBytes

public static byte[] readBytes(InputStream in)
                        throws IOException
Throws:
IOException

readFile

public static String readFile(File file)
                       throws IOException
Throws:
IOException

readLines

public static List<String> readLines(File file)
                              throws IOException
Throws:
IOException

writeLines

public static void writeLines(File file,
                              List<String> lines)
                       throws IOException
Throws:
IOException

readBytes

public static byte[] readBytes(File file)
                        throws IOException
Throws:
IOException

writeFile

public static void writeFile(File file,
                             byte[] buf)
                      throws IOException
Throws:
IOException

writeFile

public static void writeFile(File file,
                             String buf)
                      throws IOException
Throws:
IOException

download

public static void download(URL url,
                            File file)
                     throws IOException
Throws:
IOException

deleteTree

public static void deleteTree(File dir)

emptyDirectory

public static void emptyDirectory(File dir)

copyToFile

public static void copyToFile(InputStream in,
                              File file)
                       throws IOException
Throws:
IOException

append

public static void append(File src,
                          File dst)
                   throws IOException
Throws:
IOException

append

public static void append(File src,
                          File dst,
                          boolean appendNewLine)
                   throws IOException
Throws:
IOException

append

public static void append(InputStream in,
                          File file)
                   throws IOException
Throws:
IOException

append

public static void append(InputStream in,
                          File file,
                          boolean appendNewLine)
                   throws IOException
Throws:
IOException

copy

public static void copy(File src,
                        File dst)
                 throws IOException
Copies source to destination. If source and destination are the same, does nothing. Both single files and directories are handled.

Parameters:
src - the source file or directory
dst - the destination file or directory
Throws:
IOException

copy

public static void copy(File[] src,
                        File dst)
                 throws IOException
Throws:
IOException

copyFile

public static void copyFile(File src,
                            File dst)
                     throws IOException
Throws:
IOException

copyTree

public static void copyTree(File src,
                            File dst)
                     throws IOException
Copies recursively source to destination.

The source file is assumed to be a directory.

Parameters:
src - the source directory
dst - the destination directory
Throws:
IOException

copyTree

public static void copyTree(File src,
                            File dst,
                            PathFilter filter)
                     throws IOException
Throws:
IOException

getFilePathFromUrl

public static String getFilePathFromUrl(URL url)
Decodes an URL path so that is can be processed as a filename later.

Parameters:
url - the Url to be processed.
Returns:
the decoded path.

getFileFromURL

public static File getFileFromURL(URL url)

getParentPath

public static String getParentPath(String path)

getFileName

public static String getFileName(String path)

getFileExtension

public static String getFileExtension(String path)

getFileNameNoExt

public static String getFileNameNoExt(String path)

getResourcePathFromContext

public static String getResourcePathFromContext(String resource)
Retrieves the total path of a resource from the Thread Context.

Parameters:
resource - the resource name to be retrieved.
Returns:
the decoded path.

getResourceFileFromContext

public static File getResourceFileFromContext(String resource)

findFiles

public static File[] findFiles(File root,
                               String pattern,
                               boolean recurse)

collectFiles

public static void collectFiles(File root,
                                FileNamePattern pattern,
                                List<File> result)

collectFiles

public static void collectFiles(File root,
                                List<File> result)

close

public static void close(InputStream in)

close

public static void close(OutputStream out)

urlToFile

public static File urlToFile(String url)
                      throws MalformedURLException
Create a file handler (this doesn't create a real file) given a file URI. This method can be used to create files from invalid URL strings (e.g. containing spaces ..)

Returns:
a file object
Throws:
MalformedURLException

urlToFile

public static File urlToFile(URL url)

readLines

public static List<String> readLines(InputStream in)
                              throws IOException
Throws:
IOException

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.