|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rice.cs.util.FileOps
public abstract class FileOps
A class to provide some convenient file operations as static methods. It's abstract to prevent (useless) instantiation, though it can be subclassed to provide convenient namespace importation of its methods.
Nested Class Summary | |
---|---|
static class |
FileOps.DefaultFileSaver
This class is a default implementation of FileSaver that makes only one backup of each file per instantiation of the program (following the Emacs convention). |
static interface |
FileOps.FileSaver
|
static class |
FileOps.NullFile
A singleton null file class. |
Field Summary | |
---|---|
static FileFilter |
JAVA_FILE_FILTER
Deprecated. Use IOUtil.extensionFilePredicate(java.lang.String) instead. Example:
IOUtil.extensionFileFilter("java") . |
static File |
NULL_FILE
Special sentinal file used in FileOption and test classes among others. |
Constructor Summary | |
---|---|
FileOps()
|
Method Summary | |
---|---|
static String |
convertToAbsolutePathEntries(String path)
Deprecated. Use IOUtil.parsePath(java.lang.String) , IOUtil.getAbsoluteFiles(java.lang.Iterable extends java.io.File>) ,
IOUtil.attemptAbsoluteFiles(java.lang.Iterable extends java.io.File>) , and IOUtil.pathToString(java.lang.Iterable extends java.io.File>) ,
as needed, instead. |
static void |
copyFile(File source,
File dest)
Deprecated. Use IOUtil.copyFile(java.io.File, java.io.File) instead; it scales in a much more efficiently. |
static File |
createTempDirectory(String name)
Create a new temporary directory. |
static File |
createTempDirectory(String name,
File parent)
Create a new temporary directory. |
static boolean |
deleteDirectory(File dir)
Deprecated. Use IOUtil.deleteRecursively(java.io.File) instead |
static void |
deleteDirectoryOnExit(File dir)
Deprecated. Use IOUtil.deleteOnExitRecursively(java.io.File) instead |
static File |
getCanonicalFile(File f)
Deprecated. Use IOUtil.attemptCanonicalFile(java.io.File) instead. |
static String |
getCanonicalPath(File f)
Deprecated. Use IOUtil.attemptCanonicalFile(java.io.File) instead. (The result will be a
File instead of a String .) |
static ArrayList<File> |
getFilesInDir(File d,
boolean recur,
FileFilter f)
Deprecated. Use IOUtil.attemptListFilesAsIterable(java.io.File) or
IOUtil.listFilesRecursively(File, FileFilter, FileFilter) instead. |
static File |
getValidDirectory(File origFile)
Return a valid directory for use, i.e. |
static boolean |
inFileTree(File f,
File root)
Deprecated. Use IOUtil.isMember(java.io.File, java.io.File) instead. Note that the new method does not test for
null values and does not convert to canonical paths -- if these things are necessary, they
should be done before invoking the method. |
static boolean |
isAncestorOf(File ancestor,
File f)
Return true if the directory ancestor is an ancestor of the file f, i.e. |
static File |
makeFile(File parentDir,
String child)
Deprecated. For a best-attempt canonical file, use IOUtil.attemptCanonicalFile(java.io.File) instead.
(for example, IOUtil.attemptCanonicalFile(new File(path)) ) |
static File |
makeFile(String path)
Deprecated. For a best-attempt canonical file, use IOUtil.attemptCanonicalFile(java.io.File) instead.
(for example, IOUtil.attemptCanonicalFile(new File(path)) ) |
static File |
makeRelativeTo(File f,
File b)
Makes a file equivalent to the given file f that is relative to base file b. |
static boolean |
makeWritable(File roFile)
|
static boolean |
moveRecursively(File f,
File n)
Move f to n, recursively if necessary. |
static LinkedList<String> |
packageExplore(String prefix,
File root)
This function starts from the given directory and finds all packages within that directory |
static String |
readFileAsString(File file)
Deprecated. Use IOUtil.toString(File) instead, which provides the same functionality. |
static String |
readFileAsSwingText(File file)
Reads the entire contents of a file and return them as canonicalized Swing Document text. |
static byte[] |
readStreamAsBytes(InputStream stream)
Deprecated. Use IOUtil.toByteArray(java.io.File) instead. Note that the IOUtil method will
not close the InputStream , while this method does. |
static boolean |
renameFile(File file,
File dest)
Deprecated. Use IOUtil.attemptMove(java.io.File, java.io.File) , which is equally Windows-friendly, instead. |
static void |
saveFile(FileOps.FileSaver fileSaver)
This method writes files correctly; it takes care of catching errors, making backups, and keeping an unsuccessful file save from destroying the old file (unless a backup is made). |
static String[] |
splitFile(File fileToSplit)
Deprecated. Use IOUtil.fullPath(java.io.File) instead. It returns a list of File
objects rather than strings, but they appear in the same order. |
static String |
stringMakeRelativeTo(File f,
File b)
Makes a file equivalent to the given file f that is relative to base file b. |
static URL |
toURL(File f)
Converts the abstract pathname for f into a URL. |
static File |
validate(File f)
|
static boolean |
writeIfPossible(File file,
String text,
boolean append)
Deprecated. Use IOUtil.attemptWriteStringToFile(File, String, boolean) instead. |
static void |
writeStringToFile(File file,
String text)
Deprecated. Use the equivalent IOUtil.writeStringToFile(File, String) instead |
static void |
writeStringToFile(File file,
String text,
boolean append)
Deprecated. Use the equivalent IOUtil.writeStringToFile(File, String, boolean) instead |
static File |
writeStringToNewTempFile(String prefix,
String suffix,
String text)
Deprecated. Instead, create a temp file with IOUtil.createAndMarkTempFile(String, String) ,
then write to it with IOUtil.writeStringToFile(File, String) . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final File NULL_FILE
@Deprecated public static final FileFilter JAVA_FILE_FILTER
IOUtil.extensionFilePredicate(java.lang.String)
instead. Example:
IOUtil.extensionFileFilter("java")
.javax.swing.filechooser.FileFilter
, it actually implements a java.io.FileFilter
, because
that is what FileFilter
means in the context of this source file.)
Constructor Detail |
---|
public FileOps()
Method Detail |
---|
@Deprecated public static File makeFile(String path)
IOUtil.attemptCanonicalFile(java.io.File)
instead.
(for example, IOUtil.attemptCanonicalFile(new File(path))
)
@Deprecated public static File makeFile(File parentDir, String child)
IOUtil.attemptCanonicalFile(java.io.File)
instead.
(for example, IOUtil.attemptCanonicalFile(new File(path))
)
@Deprecated public static boolean inFileTree(File f, File root)
IOUtil.isMember(java.io.File, java.io.File)
instead. Note that the new method does not test for
null
values and does not convert to canonical paths -- if these things are necessary, they
should be done before invoking the method.
public static boolean isAncestorOf(File ancestor, File f)
ancestor
- the ancestorf
- the file to test
public static File makeRelativeTo(File f, File b) throws IOException, SecurityException
new File(b,makeRelativeTo(base,abs)).getCanonicalPath()
equals
f.getCanonicalPath()
In Linux/Unix, if the file f is /home/username/folder/file.java
and the file b is
/home/username/folder/sublevel/file2.java
, then the resulting File path from this method would be
../file.java
while its canoncial path would be /home/username/folder/file.java
.
Warning: making paths relative is inherently broken on some file systems, because a relative path
requires that both the file and the base have the same root. The Windows file system, and therefore also
the Java file system model, however, support multiple system roots (see File.listRoots()
).
Thus, two files with different roots cannot have a relative path. In that case the absolute path of
the file will be returned
f
- The path that is to be made relative to the base fileb
- The file to make the next file relative to
getCanonicalPath()
for the returned file is the same as the result of getCanonicalPath()
for the given file.
IOException
SecurityException
public static String stringMakeRelativeTo(File f, File b) throws IOException, SecurityException
new File(b,makeRelativeTo(base,abs)).getCanonicalPath()
equals
f.getCanonicalPath()
In Linux/Unix, if the file f is /home/username/folder/file.java
and the file b is
/home/username/folder/sublevel/file2.java
, then the resulting File path from this method would be
../file.java
while its canoncial path would be /home/username/folder/file.java
.
Warning: making paths relative is inherently broken on some file systems, because a relative path
requires that both the file and the base have the same root. The Windows file system, and therefore also
the Java file system model, however, support multiple system roots (see File.listRoots()
).
Thus, two files with different roots cannot have a relative path. In that case the absolute path of
the file will be returned
f
- The path that is to be made relative to the base fileb
- The file to make the next file relative to
getCanonicalPath()
for the returned file is the same as the result of getCanonicalPath()
for the given file.
IOException
SecurityException
@Deprecated public static String[] splitFile(File fileToSplit)
IOUtil.fullPath(java.io.File)
instead. It returns a list of File
objects rather than strings, but they appear in the same order.
/home/username/txt.txt
in linux would be split into the string array:
{"","home","username","txt.txt"}. Delimeters are excluded.
fileToSplit
- the file to split into its directories.@Deprecated public static ArrayList<File> getFilesInDir(File d, boolean recur, FileFilter f)
IOUtil.attemptListFilesAsIterable(java.io.File)
or
IOUtil.listFilesRecursively(File, FileFilter, FileFilter)
instead.
File
s for which isFile()
is true
) matching the provided filter in
the given directory.
d
- The directory to search.recur
- Whether subdirectories accepted by f
should be recursively searched. Note that
subdirectories that aren't accepted by f
will be ignored.f
- The filter to apply to contained File
s.
@Deprecated public static File getCanonicalFile(File f)
IOUtil.attemptCanonicalFile(java.io.File)
instead.
@Deprecated public static String getCanonicalPath(File f)
IOUtil.attemptCanonicalFile(java.io.File)
instead. (The result will be a
File
instead of a String
.)
public static File validate(File f)
@Deprecated public static byte[] readStreamAsBytes(InputStream stream) throws IOException
IOUtil.toByteArray(java.io.File)
instead. Note that the IOUtil
method will
not close the InputStream
, while this method does.
stream
- Input stream to read.
IOException
public static String readFileAsSwingText(File file) throws IOException
IOException
@Deprecated public static String readFileAsString(File file) throws IOException
IOUtil.toString(File)
instead, which provides the same functionality.
IOException
@Deprecated public static void copyFile(File source, File dest) throws IOException
IOUtil.copyFile(java.io.File, java.io.File)
instead; it scales in a much more efficiently.
source
- the file to be copieddest
- the file to be copied to
IOException
@Deprecated public static File writeStringToNewTempFile(String prefix, String suffix, String text) throws IOException
IOUtil.createAndMarkTempFile(String, String)
,
then write to it with IOUtil.writeStringToFile(File, String)
.
prefix
- Beginning part of file name, before unique numbersuffix
- Ending part of file name, after unique numbertext
- Text to write to file
IOException
@Deprecated public static void writeStringToFile(File file, String text) throws IOException
IOUtil.writeStringToFile(File, String)
instead
file
- File to write totext
- Test to write
IOException
@Deprecated public static void writeStringToFile(File file, String text, boolean append) throws IOException
IOUtil.writeStringToFile(File, String, boolean)
instead
file
- File to write totext
- Text to writeappend
- whether to append. (false=overwrite)
IOException
@Deprecated public static boolean writeIfPossible(File file, String text, boolean append)
IOUtil.attemptWriteStringToFile(File, String, boolean)
instead.
file
- File to write totext
- Text to writeappend
- Whether to append. (false=overwrite)public static File createTempDirectory(String name) throws IOException
name
- Non-unique portion of the name of the directory to create.
IOException
public static File createTempDirectory(String name, File parent) throws IOException
name
- Non-unique portion of the name of the directory to create.parent
- Parent directory to contain the new directory
IOException
@Deprecated public static boolean deleteDirectory(File dir)
IOUtil.deleteRecursively(java.io.File)
instead
dir
- File object representing directory to delete. If, for some reason, this file object is not a
directory, it will still be deleted.
@Deprecated public static void deleteDirectoryOnExit(File dir)
IOUtil.deleteOnExitRecursively(java.io.File)
instead
dir
- File object representing directory to delete. If, for some reason, this file object is not a
directory, it will still be deleted.public static LinkedList<String> packageExplore(String prefix, File root)
prefix
- the package name of files in the given rootroot
- the directory to start exploring from
@Deprecated public static boolean renameFile(File file, File dest)
IOUtil.attemptMove(java.io.File, java.io.File)
, which is equally Windows-friendly, instead.
file
- the file to renamedest
- the destination file
public static void saveFile(FileOps.FileSaver fileSaver) throws IOException
fileSaver
- Keeps track of the name of the file to write, whether to back up the file, and has
a method that actually performs the writing of the file
IOException
- if the saving or backing up of the file fails for any reason@Deprecated public static String convertToAbsolutePathEntries(String path)
IOUtil.parsePath(java.lang.String)
, IOUtil.getAbsoluteFiles(java.lang.Iterable extends java.io.File>)
,
IOUtil.attemptAbsoluteFiles(java.lang.Iterable extends java.io.File>)
, and IOUtil.pathToString(java.lang.Iterable extends java.io.File>)
,
as needed, instead.
path
- path string with entries to convert
public static File getValidDirectory(File origFile)
public static URL toURL(File f) throws MalformedURLException
MalformedURLException
public static boolean makeWritable(File roFile) throws IOException
IOException
public static boolean moveRecursively(File f, File n)
f
- file or directory to moven
- new location and name for the file or directory
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |