Nuxeo Enterprise Platform 5.4

org.nuxeo.common.utils
Class FileUtils

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

public final class FileUtils
extends java.lang.Object

Author:
Bogdan Stefanescu

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

copy

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

read

public static java.lang.String read(java.io.InputStream in)
                             throws java.io.IOException
Throws:
java.io.IOException

readBytes

public static byte[] readBytes(java.net.URL url)
                        throws java.io.IOException
Throws:
java.io.IOException

readBytes

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

readFile

public static java.lang.String readFile(java.io.File file)
                                 throws java.io.IOException
Throws:
java.io.IOException

readLines

public static java.util.List<java.lang.String> readLines(java.io.File file)
                                                  throws java.io.IOException
Throws:
java.io.IOException

writeLines

public static void writeLines(java.io.File file,
                              java.util.List<java.lang.String> lines)
                       throws java.io.IOException
Throws:
java.io.IOException

readBytes

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

writeFile

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

writeFile

public static void writeFile(java.io.File file,
                             java.lang.String buf)
                      throws java.io.IOException
Throws:
java.io.IOException

download

public static void download(java.net.URL url,
                            java.io.File file)
                     throws java.io.IOException
Throws:
java.io.IOException

deleteTree

public static void deleteTree(java.io.File dir)

emptyDirectory

public static void emptyDirectory(java.io.File dir)

copyToFile

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

append

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

append

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

append

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

append

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

copy

public static void copy(java.io.File src,
                        java.io.File dst)
                 throws java.io.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:
java.io.IOException

copy

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

copyFile

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

copyTree

public static void copyTree(java.io.File src,
                            java.io.File dst)
                     throws java.io.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:
java.io.IOException

copyTree

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

getFilePathFromUrl

public static java.lang.String getFilePathFromUrl(java.net.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 java.io.File getFileFromURL(java.net.URL url)

getParentPath

public static java.lang.String getParentPath(java.lang.String path)

getFileName

public static java.lang.String getFileName(java.lang.String path)

getFileExtension

public static java.lang.String getFileExtension(java.lang.String path)

getFileNameNoExt

public static java.lang.String getFileNameNoExt(java.lang.String path)

getResourcePathFromContext

public static java.lang.String getResourcePathFromContext(java.lang.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 java.io.File getResourceFileFromContext(java.lang.String resource)

findFiles

public static java.io.File[] findFiles(java.io.File root,
                                       java.lang.String pattern,
                                       boolean recurse)

collectFiles

public static void collectFiles(java.io.File root,
                                FileNamePattern pattern,
                                java.util.List<java.io.File> result)

collectFiles

public static void collectFiles(java.io.File root,
                                java.util.List<java.io.File> result)

close

public static void close(java.io.InputStream in)

close

public static void close(java.io.OutputStream out)

urlToFile

public static java.io.File urlToFile(java.lang.String url)
                              throws java.net.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:
java.net.MalformedURLException

urlToFile

public static java.io.File urlToFile(java.net.URL url)

readLines

public static java.util.List<java.lang.String> readLines(java.io.InputStream in)
                                                  throws java.io.IOException
Throws:
java.io.IOException

Nuxeo Enterprise Platform 5.4

Copyright © 2010 Nuxeo SAS. All Rights Reserved.