Package com.android.repository.io
Class FileOp
- java.lang.Object
-
- com.android.repository.io.FileOp
-
- Direct Known Subclasses:
FileOpImpl
public abstract class FileOp extends java.lang.ObjectDeprecated.UsePaths,CancellableFileIoand (for testing)InMemoryFileSystemsdirectly.Wraps some commonFileoperations on files and folders.This makes it possible to override/mock/stub some file operations in unit tests. Uses
CancellableFileIoto check for cancellation before read I/O operations.
-
-
Constructor Summary
Constructors Constructor Description FileOp()Deprecated.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancanExecute(java.io.File file)Deprecated.booleancanWrite(java.io.File file)Deprecated.InvokesCancellableFileIo.isWritable(Path)on the givenfile.voidcopyFile(java.io.File source, java.io.File dest)Deprecated.booleancreateNewFile(java.io.File file)Deprecated.Creates a new file.booleandelete(java.io.File file)Deprecated.InvokesFiles.delete(Path)on the givenfile.voiddeleteFileOrFolder(java.io.File fileOrFolder)Deprecated.Helper to delete a file or a directory.abstract voiddeleteOnExit(java.io.File file)Deprecated.The application may not exit for a very long time.abstract java.io.FileensureRealFile(java.io.File in)Deprecated.Ifinis an in-memory file, write it out as a proper file and return it.booleanexists(java.io.File file)Deprecated.InvokesCancellableFileIo.exists(Path, LinkOption...)on the givenfile.abstract java.nio.file.FileSystemgetFileSystem()Deprecated.Returns theFileSystemthis is based on.booleanisDirectory(java.io.File file)Deprecated.InvokesCancellableFileIo.isDirectory(Path, LinkOption...)(Path, LinkOption...)} on the givenfile.booleanisFile(java.io.File file)Deprecated.InvokesCancellableFileIo.isRegularFile(Path, LinkOption...)on the givenfile.booleanisSameFile(java.io.File file1, java.io.File file2)Deprecated.Checks whether 2 binary files are the same.longlastModified(java.io.File file)Deprecated.Returns the lastModified attribute of the file.longlength(java.io.File file)Deprecated.InvokesCancellableFileIo.size(Path)on the givenfile.java.lang.String[]list(java.io.File folder, java.io.FilenameFilter filenameFilter)Deprecated.java.io.File[]listFiles(java.io.File file)Deprecated.InvokesCancellableFileIo.list(Path)on the givenfile.java.io.File[]listFiles(java.io.File folder, java.io.FilenameFilter filenameFilter)Deprecated.booleanmkdirs(java.io.File file)Deprecated.InvokesFiles.createDirectories(Path, FileAttribute[])on the givenfile.java.io.InputStreamnewFileInputStream(java.io.File file)Deprecated.Creates a newInputStreamfor the givenfile.java.io.InputStreamnewFileInputStream(java.nio.file.Path path)Deprecated.Creates a newInputStreamfor the givenpath.java.io.OutputStreamnewFileOutputStream(java.io.File file)Deprecated.Creates a newOutputStreamfor the givenfile.java.io.OutputStreamnewFileOutputStream(java.io.File file, boolean append)Deprecated.Creates a newOutputStreamfor the givenfile, either truncating an existing file or appending to it.java.lang.StringreadText(java.io.File f)Deprecated.booleanrenameTo(java.io.File oldFile, java.io.File newFile)Deprecated.UsesFiles.move(Path, Path, CopyOption...)to renameoldFileto {voidsetExecutablePermission(java.io.File file)Deprecated.Sets the executable Unix permission (+x) on a file or folder.booleansetLastModified(java.io.File file, long time)Deprecated.booleansetLastModified(java.nio.file.Path file, long time)Deprecated.voidsetReadOnly(java.io.File file)Deprecated.Sets the file or directory as read-only.abstract java.io.FiletoFile(java.nio.file.Path path)Deprecated.Temporary functionality to help with File-to-Path migration.java.nio.file.PathtoPath(java.io.File file)Deprecated.Convert the givenFileinto aPath, using some means appropriate to thisFileOp.java.nio.file.PathtoPath(java.lang.String path)Deprecated.Convert the givenStringinto aPath, using some means appropriate to thisFileOp.
-
-
-
Method Detail
-
getFileSystem
public abstract java.nio.file.FileSystem getFileSystem()
Deprecated.Returns theFileSystemthis is based on.
-
deleteFileOrFolder
public final void deleteFileOrFolder(@NonNull java.io.File fileOrFolder)Deprecated.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.
-
setExecutablePermission
public final void setExecutablePermission(@NonNull java.io.File file) throws java.io.IOExceptionDeprecated.Sets the executable Unix permission (+x) on a file or folder.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
public final void setReadOnly(@NonNull java.io.File file) throws java.io.IOExceptionDeprecated.Sets the file or directory as read-only.- Parameters:
file- The file or directory to set permissions on.- Throws:
java.io.IOException
-
copyFile
public void copyFile(@NonNull java.io.File source, @NonNull java.io.File dest) throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException
-
isSameFile
public final boolean isSameFile(@NonNull java.io.File file1, @NonNull java.io.File file2) throws java.io.IOExceptionDeprecated.Checks whether 2 binary files are the same.- Parameters:
file1- the source file to copyfile2- the destination file to write- Throws:
java.io.IOException- if there's a problem reading the files.
-
exists
public final boolean exists(@NonNull java.io.File file)Deprecated.InvokesCancellableFileIo.exists(Path, LinkOption...)on the givenfile.
-
isFile
public final boolean isFile(@NonNull java.io.File file)Deprecated.InvokesCancellableFileIo.isRegularFile(Path, LinkOption...)on the givenfile.
-
isDirectory
public final boolean isDirectory(@NonNull java.io.File file)Deprecated.InvokesCancellableFileIo.isDirectory(Path, LinkOption...)(Path, LinkOption...)} on the givenfile.
-
canWrite
public boolean canWrite(@NonNull java.io.File file)Deprecated.InvokesCancellableFileIo.isWritable(Path)on the givenfile.TODO: make this final so we can migrate from FileOp to using Paths directly
-
length
public final long length(@NonNull java.io.File file) throws java.io.IOExceptionDeprecated.InvokesCancellableFileIo.size(Path)on the givenfile.- Throws:
java.io.IOException
-
delete
public boolean delete(@NonNull java.io.File file)Deprecated.InvokesFiles.delete(Path)on the givenfile. Note: for a recursive folder version, considerdeleteFileOrFolder(File).TODO: make this final so we can migrate from FileOp to using Paths directly
-
mkdirs
public final boolean mkdirs(@NonNull java.io.File file)Deprecated.InvokesFiles.createDirectories(Path, FileAttribute[])on the givenfile.
-
listFiles
@NonNull public final java.io.File[] listFiles(@NonNull java.io.File file)Deprecated.InvokesCancellableFileIo.list(Path)on the givenfile. Contrary to the Java API, this returns an empty array instead of null when the directory does not exist.
-
renameTo
public boolean renameTo(@NonNull java.io.File oldFile, @NonNull java.io.File newFile)Deprecated.UsesFiles.move(Path, Path, CopyOption...)to renameoldFileto {
-
newFileOutputStream
@NonNull public java.io.OutputStream newFileOutputStream(@NonNull java.io.File file) throws java.io.IOExceptionDeprecated.Creates a newOutputStreamfor the givenfile.TODO: make this final so we can migrate from FileOp to using Paths directly
- Throws:
java.io.IOException
-
newFileOutputStream
@NonNull public java.io.OutputStream newFileOutputStream(@NonNull java.io.File file, boolean append) throws java.io.IOExceptionDeprecated.Creates a newOutputStreamfor the givenfile, either truncating an existing file or appending to it.TODO: make this final so we can migrate from FileOp to using Paths directly
- Throws:
java.io.IOException
-
newFileInputStream
@NonNull public final java.io.InputStream newFileInputStream(@NonNull java.io.File file) throws java.io.IOExceptionDeprecated.Creates a newInputStreamfor the givenfile.- Throws:
java.io.IOException
-
newFileInputStream
@NonNull public final java.io.InputStream newFileInputStream(@NonNull java.nio.file.Path path) throws java.io.IOExceptionDeprecated.Creates a newInputStreamfor the givenpath.- Throws:
java.io.IOException
-
lastModified
public final long lastModified(@NonNull java.io.File file)Deprecated.Returns the lastModified attribute of the file.- Parameters:
file- The non-null file of which to retrieve the lastModified attribute.- Returns:
- The last-modified attribute of the file, in milliseconds since The Epoch.
- See Also:
Files.getLastModifiedTime(Path, LinkOption...)
-
createNewFile
public final boolean createNewFile(@NonNull java.io.File file) throws java.io.IOExceptionDeprecated.Creates a new file. SeeFiles.createFile(Path, FileAttribute[]).- Throws:
java.io.IOException
-
canExecute
public final boolean canExecute(@NonNull java.io.File file)Deprecated.- See Also:
Files.isExecutable(Path)
-
ensureRealFile
public abstract java.io.File ensureRealFile(@NonNull java.io.File in) throws java.io.IOExceptionDeprecated.Ifinis an in-memory file, write it out as a proper file and return it. Otherwise just returnin.- Throws:
java.io.IOException
-
readText
@NonNull public final java.lang.String readText(@NonNull java.io.File f) throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException
-
list
public final java.lang.String[] list(@NonNull java.io.File folder, @Nullable java.io.FilenameFilter filenameFilter)Deprecated.- See Also:
File.list(FilenameFilter)
-
listFiles
public final java.io.File[] listFiles(@NonNull java.io.File folder, @Nullable java.io.FilenameFilter filenameFilter)Deprecated.- See Also:
File.listFiles(FilenameFilter)
-
deleteOnExit
@Deprecated public abstract void deleteOnExit(java.io.File file)
Deprecated.The application may not exit for a very long time. Prefer explicit cleanup.- See Also:
File.deleteOnExit()
-
setLastModified
public final boolean setLastModified(@NonNull java.io.File file, long time) throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException- if there is an error setting the modification time.- See Also:
Files.setLastModifiedTime(Path, FileTime)
-
setLastModified
public final boolean setLastModified(@NonNull java.nio.file.Path file, long time) throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException- if there is an error setting the modification time.- See Also:
Files.setLastModifiedTime(Path, FileTime)
-
toPath
@NonNull public java.nio.file.Path toPath(@NonNull java.io.File file)Deprecated.Convert the givenFileinto aPath, using some means appropriate to thisFileOp.TODO: make final once tests can work on windows without special-casing.
-
toPath
@NonNull public java.nio.file.Path toPath(@NonNull java.lang.String path)Deprecated.Convert the givenStringinto aPath, using some means appropriate to thisFileOp.
-
toFile
@NonNull public abstract java.io.File toFile(@NonNull java.nio.file.Path path)Deprecated.Temporary functionality to help with File-to-Path migration. Should only be called when a FileOp is not available and with a Path that is backed by the default FileSystem (notably not in the context of any tests that use MockFileOp or jimfs).- Throws:
java.lang.UnsupportedOperationException- if the Path is backed by a non-default FileSystem.
-
-