com.android.utils
Class FileUtils

java.lang.Object
  extended by com.android.utils.FileUtils

public final class FileUtils
extends java.lang.Object


Field Summary
static com.google.common.base.Function<java.io.File,java.lang.String> GET_NAME
           
static com.google.common.base.Function<java.io.File,java.lang.String> GET_PATH
           
 
Method Summary
static void copy(java.io.File from, java.io.File toDir)
           
static void createFile(java.io.File file, java.lang.String content)
           
static void delete(java.io.File file)
           
static void deleteFolder(java.io.File folder)
           
static void deleteIfExists(java.io.File file)
           
static void emptyFolder(java.io.File folder)
           
static java.util.List<java.io.File> find(java.io.File base, java.util.regex.Pattern pattern)
          Find a list of files in a directory, using a specified path pattern.
static com.google.common.base.Optional<java.io.File> find(java.io.File base, java.lang.String name)
          Find a file with the specified name in a given directory .
static com.google.common.collect.FluentIterable<java.io.File> getAllFiles(java.io.File dir)
           
static java.lang.String getDirectoryNameForJar(java.io.File inputFile)
          Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar.
static java.lang.String getNamesAsCommaSeparatedList(java.lang.Iterable<java.io.File> files)
           
static java.io.File join(java.io.File dir, java.lang.Iterable<java.lang.String> paths)
          Joins a list of path segments to a given File object.
static java.io.File join(java.io.File dir, java.lang.String... paths)
          Joins a list of path segments to a given File object.
static java.lang.String join(java.lang.Iterable<java.lang.String> paths)
          Joins a set of segment into a string, separating each segments with a host-specific path separator.
static java.lang.String join(java.lang.String... paths)
          Joins a set of segment into a string, separating each segments with a host-specific path separator.
static java.lang.String loadFileWithUnixLineSeparators(java.io.File file)
          Loads a text file forcing the line separator to be of Unix style '\n' rather than being Windows style '\r\n'.
static void mkdirs(java.io.File folder)
           
static byte[] readSegment(java.io.File file, long start, int length)
          Reads a portion of a file to memory.
static java.lang.String relativePath(java.io.File file, java.io.File dir)
          Computes the relative of a file or directory with respect to a directory.
static java.lang.String relativePossiblyNonExistingPath(java.io.File file, java.io.File dir)
          Computes the relative of a file or directory with respect to a directory.
static void renameTo(java.io.File file, java.io.File to)
           
static java.lang.String sha1(java.io.File file)
           
static java.lang.String toSystemDependentPath(java.lang.String path)
          Converts a /-based path into a path using the system dependent separator.
static java.lang.String toSystemIndependentPath(java.lang.String path)
          Converts a system-dependent path into a /-based path.
static com.google.common.base.Predicate<java.io.File> withExtension(java.lang.String extension)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET_NAME

public static final com.google.common.base.Function<java.io.File,java.lang.String> GET_NAME

GET_PATH

public static final com.google.common.base.Function<java.io.File,java.lang.String> GET_PATH
Method Detail

withExtension

@NonNull
public static com.google.common.base.Predicate<java.io.File> withExtension(@NonNull
                                                                                   java.lang.String extension)

deleteFolder

public static void deleteFolder(@NonNull
                                java.io.File folder)
                         throws java.io.IOException
Throws:
java.io.IOException

emptyFolder

public static void emptyFolder(@NonNull
                               java.io.File folder)
                        throws java.io.IOException
Throws:
java.io.IOException

copy

public static void copy(@NonNull
                        java.io.File from,
                        @NonNull
                        java.io.File toDir)
                 throws java.io.IOException
Throws:
java.io.IOException

mkdirs

public static void mkdirs(@NonNull
                          java.io.File folder)

delete

public static void delete(@NonNull
                          java.io.File file)
                   throws java.io.IOException
Throws:
java.io.IOException

deleteIfExists

public static void deleteIfExists(@NonNull
                                  java.io.File file)
                           throws java.io.IOException
Throws:
java.io.IOException

renameTo

public static void renameTo(@NonNull
                            java.io.File file,
                            @NonNull
                            java.io.File to)
                     throws java.io.IOException
Throws:
java.io.IOException

join

@NonNull
public static java.io.File join(@NonNull
                                        java.io.File dir,
                                        @NonNull
                                        java.lang.String... paths)
Joins a list of path segments to a given File object.

Parameters:
dir - the file object.
paths - the segments.
Returns:
a new File object.

join

@NonNull
public static java.io.File join(@NonNull
                                        java.io.File dir,
                                        @NonNull
                                        java.lang.Iterable<java.lang.String> paths)
Joins a list of path segments to a given File object.

Parameters:
dir - the file object.
paths - the segments.
Returns:
a new File object.

join

@NonNull
public static java.lang.String join(@NonNull
                                            java.lang.String... paths)
Joins a set of segment into a string, separating each segments with a host-specific path separator.

Parameters:
paths - the segments.
Returns:
a string with the segments.

join

@NonNull
public static java.lang.String join(@NonNull
                                            java.lang.Iterable<java.lang.String> paths)
Joins a set of segment into a string, separating each segments with a host-specific path separator.

Parameters:
paths - the segments.
Returns:
a string with the segments.

loadFileWithUnixLineSeparators

@NonNull
public static java.lang.String loadFileWithUnixLineSeparators(@NonNull
                                                                      java.io.File file)
                                                       throws java.io.IOException
Loads a text file forcing the line separator to be of Unix style '\n' rather than being Windows style '\r\n'.

Throws:
java.io.IOException

relativePath

@NonNull
public static java.lang.String relativePath(@NonNull
                                                    java.io.File file,
                                                    @NonNull
                                                    java.io.File dir)
Computes the relative of a file or directory with respect to a directory.

Parameters:
file - the file or directory, which must exist in the filesystem
dir - the directory to compute the path relative to
Returns:
the relative path from dir to file; if file is a directory the path comes appended with the file separator (see documentation on relativize on java's URI class)

relativePossiblyNonExistingPath

@NonNull
public static java.lang.String relativePossiblyNonExistingPath(@NonNull
                                                                       java.io.File file,
                                                                       @NonNull
                                                                       java.io.File dir)
Computes the relative of a file or directory with respect to a directory. For example, if the file's absolute path is /a/b/c and the directory is /a, this method returns b/c.

Parameters:
file - the path that may not correspond to any existing path in the filesystem
dir - the directory to compute the path relative to
Returns:
the relative path from dir to file; if file is a directory the path comes appended with the file separator (see documentation on relativize on java's URI class)

toSystemDependentPath

@NonNull
public static java.lang.String toSystemDependentPath(@NonNull
                                                             java.lang.String path)
Converts a /-based path into a path using the system dependent separator.

Parameters:
path - the system independent path to convert
Returns:
the system dependent path

toSystemIndependentPath

@NonNull
public static java.lang.String toSystemIndependentPath(@NonNull
                                                               java.lang.String path)
Converts a system-dependent path into a /-based path.

Parameters:
path - the system dependent path
Returns:
the system independent path

sha1

@NonNull
public static java.lang.String sha1(@NonNull
                                            java.io.File file)
                             throws java.io.IOException
Throws:
java.io.IOException

getAllFiles

@NonNull
public static com.google.common.collect.FluentIterable<java.io.File> getAllFiles(@NonNull
                                                                                         java.io.File dir)

getNamesAsCommaSeparatedList

@NonNull
public static java.lang.String getNamesAsCommaSeparatedList(@NonNull
                                                                    java.lang.Iterable<java.io.File> files)

getDirectoryNameForJar

@NonNull
public static java.lang.String getDirectoryNameForJar(@NonNull
                                                              java.io.File inputFile)
Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar.


createFile

public static void createFile(@NonNull
                              java.io.File file,
                              @NonNull
                              java.lang.String content)
                       throws java.io.IOException
Throws:
java.io.IOException

find

public static java.util.List<java.io.File> find(@NonNull
                                                java.io.File base,
                                                @NonNull
                                                java.util.regex.Pattern pattern)
Find a list of files in a directory, using a specified path pattern.


find

public static com.google.common.base.Optional<java.io.File> find(@NonNull
                                                                 java.io.File base,
                                                                 @NonNull
                                                                 java.lang.String name)
Find a file with the specified name in a given directory .


readSegment

@NonNull
public static byte[] readSegment(@NonNull
                                         java.io.File file,
                                         long start,
                                         int length)
                          throws java.lang.Exception
Reads a portion of a file to memory.

Parameters:
file - the file to read data from
start - the offset in the file to start reading
length - the number of bytes to read
Returns:
the bytes read
Throws:
java.lang.Exception - failed to read the file