public abstract class FileSystemFileOp extends java.lang.Object implements FileOp
FileOp implementations based on a FileSystem.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
mIsWindows |
EMPTY_FILE_ARRAY| Constructor and Description |
|---|
FileSystemFileOp() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canExecute(java.io.File file) |
boolean |
canWrite(java.io.File file)
Invokes
File.canWrite() on the given file. |
void |
copyFile(java.io.File source,
java.io.File dest)
Copies a binary file.
|
boolean |
createNewFile(java.io.File file)
Creates a new 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. |
abstract java.nio.file.FileSystem |
getFileSystem()
Gets the
FileSystem this is based on. |
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 file1,
java.io.File file2)
Checks whether 2 binary files are the same.
|
boolean |
isWindows()
Returns
true if we're on windows, false otherwise. |
long |
lastModified(java.io.File file)
Returns the lastModified attribute of the file.
|
long |
length(java.io.File file)
Invokes
File.length() on the given file. |
java.lang.String[] |
list(java.io.File folder,
java.io.FilenameFilter filenameFilter) |
java.io.File[] |
listFiles(java.io.File file)
Invokes
File.listFiles() on the given file. |
java.io.File[] |
listFiles(java.io.File folder,
java.io.FilenameFilter filenameFilter) |
boolean |
mkdirs(java.io.File file)
Invokes
File.mkdirs() on the given file. |
java.io.InputStream |
newFileInputStream(java.io.File file)
Creates a new
InputStream for the given file. |
java.io.OutputStream |
newFileOutputStream(java.io.File file)
Creates a new
OutputStream for the given file. |
java.io.OutputStream |
newFileOutputStream(java.io.File file,
boolean append)
Creates a new
OutputStream for the given file. |
boolean |
renameTo(java.io.File oldFile,
java.io.File newFile)
Invokes
File.renameTo(File) on the given files. |
void |
setExecutablePermission(java.io.File file)
Sets the executable Unix permission (+x) on a file or folder.
|
boolean |
setLastModified(java.io.File file,
long time) |
void |
setReadOnly(java.io.File file)
Sets the file or directory as read-only.
|
java.nio.file.Path |
toPath(java.io.File file)
Convert the given
File into a Path, using some means appropriate to this
FileOp. |
java.lang.String |
toString(java.io.File f,
java.nio.charset.Charset c) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdeleteOnExit, ensureRealFilepublic abstract java.nio.file.FileSystem getFileSystem()
FileSystem this is based on.public final boolean isWindows()
FileOptrue if we're on windows, false otherwise.@NonNull
public final java.lang.String toString(@NonNull
java.io.File f,
@NonNull
java.nio.charset.Charset c)
throws java.io.IOException
@Nullable
public final java.lang.String[] list(@NonNull
java.io.File folder,
@Nullable
java.io.FilenameFilter filenameFilter)
@Nullable
public final java.io.File[] listFiles(@NonNull
java.io.File folder,
@Nullable
java.io.FilenameFilter filenameFilter)
public final boolean setLastModified(@NonNull
java.io.File file,
long time)
throws java.io.IOException
setLastModified in interface FileOpjava.io.IOException - if there is an error setting the modification time.File.setLastModified(long)public final void deleteFileOrFolder(@NonNull
java.io.File fileOrFolder)
FileOpdeleteFileOrFolder in interface FileOppublic final void setExecutablePermission(@NonNull
java.io.File file)
throws java.io.IOException
FileOpThis 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.
setExecutablePermission in interface FileOpfile - The file to set permissions on.java.io.IOException - If an I/O error occurspublic final boolean canExecute(@NonNull
java.io.File file)
canExecute in interface FileOpFile.canExecute()public void setReadOnly(@NonNull
java.io.File file)
throws java.io.IOException
FileOpsetReadOnly in interface FileOpfile - The file or directory to set permissions on.java.io.IOExceptionpublic void copyFile(@NonNull
java.io.File source,
@NonNull
java.io.File dest)
throws java.io.IOException
FileOppublic final boolean isSameFile(@NonNull
java.io.File file1,
@NonNull
java.io.File file2)
throws java.io.IOException
FileOpisSameFile in interface FileOpfile1 - the source file to copyfile2 - the destination file to writejava.io.FileNotFoundException - if the source files don't exist.java.io.IOException - if there's a problem reading the files.public final boolean isFile(@NonNull
java.io.File file)
FileOpFile.isFile() on the given file.public final boolean isDirectory(@NonNull
java.io.File file)
FileOpFile.isDirectory() on the given file.isDirectory in interface FileOppublic boolean canWrite(@NonNull
java.io.File file)
FileOpFile.canWrite() on the given file.public final boolean exists(@NonNull
java.io.File file)
FileOpFile.exists() on the given file.public final long length(@NonNull
java.io.File file)
throws java.io.IOException
FileOpFile.length() on the given file.public boolean delete(@NonNull
java.io.File file)
FileOpFile.delete() on the given file.
Note: for a recursive folder version, consider FileOp.deleteFileOrFolder(File).public final boolean mkdirs(@NonNull
java.io.File file)
FileOpFile.mkdirs() on the given file.@NonNull
public final java.io.File[] listFiles(@NonNull
java.io.File file)
FileOpFile.listFiles() on the given file.
Contrary to the Java API, this returns an empty array instead of null when the
directory does not exist.public boolean renameTo(@NonNull
java.io.File oldFile,
@NonNull
java.io.File newFile)
FileOpFile.renameTo(File) on the given files.@NonNull
public java.io.OutputStream newFileOutputStream(@NonNull
java.io.File file)
throws java.io.IOException
FileOpOutputStream for the given file.newFileOutputStream in interface FileOpjava.io.IOException@NonNull
public java.io.OutputStream newFileOutputStream(@NonNull
java.io.File file,
boolean append)
throws java.io.IOException
FileOpOutputStream for the given file.newFileOutputStream in interface FileOpjava.io.IOException@NonNull
public final java.io.InputStream newFileInputStream(@NonNull
java.io.File file)
throws java.io.IOException
FileOpInputStream for the given file.newFileInputStream in interface FileOpjava.io.IOExceptionpublic final long lastModified(@NonNull
java.io.File file)
FileOplastModified in interface FileOpfile - The non-null file of which to retrieve the lastModified attribute.File.lastModified()public final boolean createNewFile(@NonNull
java.io.File file)
throws java.io.IOException
FileOpFile.createNewFile().createNewFile in interface FileOpjava.io.IOException