com.android.sdklib.io
Interface IFileOp

All Known Implementing Classes:
FileOp

public interface IFileOp

Wraps some common File operations on files and folders.

This makes it possible to override/mock/stub some file operations in unit tests.


Method Summary
 void copyFile(java.io.File source, java.io.File dest)
          Copies a binary file.
 boolean delete(java.io.File file)
          Invokes File.delete() on the given file.
 void deleteFileOrFolder(java.io.File fileOrFolder)
          Helper to delete a file or a directory.
 boolean exists(java.io.File file)
          Invokes File.exists() on the given file.
 boolean isDirectory(java.io.File file)
          Invokes File.isDirectory() on the given file.
 boolean isFile(java.io.File file)
          Invokes File.isFile() on the given file.
 boolean isSameFile(java.io.File source, java.io.File destination)
          Checks whether 2 binary files are the same.
 long length(java.io.File file)
          Invokes File.length() on the given file.
 java.io.File[] listFiles(java.io.File file)
          Invokes File.listFiles() on the given file.
 java.util.Properties loadProperties(java.io.File file)
          Load Properties from a file.
 boolean mkdirs(java.io.File file)
          Invokes File.mkdirs() on the given file.
 java.io.OutputStream newFileOutputStream(java.io.File file)
          Creates a new FileOutputStream for the given file.
 boolean renameTo(java.io.File oldDir, java.io.File newDir)
          Invokes File.renameTo(File) on the given files.
 boolean saveProperties(java.io.File file, java.util.Properties props, java.lang.String comments)
          Saves (write, store) the given Properties into the given File.
 void setExecutablePermission(java.io.File file)
          Sets the executable Unix permission (+x) on a file or folder.
 void setReadOnly(java.io.File file)
          Sets the file or directory as read-only.
 

Method Detail

deleteFileOrFolder

void deleteFileOrFolder(java.io.File fileOrFolder)
Helper to delete a file or a directory. For a directory, recursively deletes all of its content. Files that cannot be deleted right away are marked for deletion on exit. It's ok for the file or folder to not exist at all. The argument can be null.


setExecutablePermission

void setExecutablePermission(java.io.File file)
                             throws java.io.IOException
Sets the executable Unix permission (+x) on a file or folder.

This attempts to use File#setExecutable through reflection if it's available. If this is not available, this invokes a chmod exec instead, so there is no guarantee of it being fast.

Caller must make sure to not invoke this under Windows.

Parameters:
file - The file to set permissions on.
Throws:
java.io.IOException - If an I/O error occurs

setReadOnly

void setReadOnly(java.io.File file)
Sets the file or directory as read-only.

Parameters:
file - The file or directory to set permissions on.

copyFile

void copyFile(java.io.File source,
              java.io.File dest)
              throws java.io.IOException
Copies a binary file.

Parameters:
source - the source file to copy.
dest - the destination file to write.
Throws:
java.io.FileNotFoundException - if the source file doesn't exist.
java.io.IOException - if there's a problem reading or writing the file.

isSameFile

boolean isSameFile(java.io.File source,
                   java.io.File destination)
                   throws java.io.IOException
Checks whether 2 binary files are the same.

Parameters:
source - the source file to copy
destination - the destination file to write
Throws:
java.io.FileNotFoundException - if the source files don't exist.
java.io.IOException - if there's a problem reading the files.

exists

boolean exists(java.io.File file)
Invokes File.exists() on the given file.


isFile

boolean isFile(java.io.File file)
Invokes File.isFile() on the given file.


isDirectory

boolean isDirectory(java.io.File file)
Invokes File.isDirectory() on the given file.


length

long length(java.io.File file)
Invokes File.length() on the given file.


delete

boolean delete(java.io.File file)
Invokes File.delete() on the given file. Note: for a recursive folder version, consider deleteFileOrFolder(File).


mkdirs

boolean mkdirs(java.io.File file)
Invokes File.mkdirs() on the given file.


listFiles

java.io.File[] listFiles(java.io.File file)
Invokes File.listFiles() on the given file.


renameTo

boolean renameTo(java.io.File oldDir,
                 java.io.File newDir)
Invokes File.renameTo(File) on the given files.


newFileOutputStream

java.io.OutputStream newFileOutputStream(java.io.File file)
                                         throws java.io.FileNotFoundException
Creates a new FileOutputStream for the given file.

Throws:
java.io.FileNotFoundException

loadProperties

@NonNull
java.util.Properties loadProperties(@NonNull
                                            java.io.File file)
Load Properties from a file. Returns an empty property set on error.

Parameters:
file - A non-null file to load from. File may not exist.
Returns:
A new Properties with the properties loaded from the file, or an empty property set in case of error.

saveProperties

boolean saveProperties(@NonNull
                       java.io.File file,
                       @NonNull
                       java.util.Properties props,
                       @NonNull
                       java.lang.String comments)
Saves (write, store) the given Properties into the given File.

Parameters:
file - A non-null file to write to.
props - The properties to write.
comments - A non-null description of the properly list, written in the file.
Returns:
True if the properties could be saved, false otherwise.