|
||||||||||
| 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 | |
|---|---|
private static Log |
_log
|
static java.io.FileFilter |
JAVA_FILE_FILTER
Deprecated. |
static java.io.File |
NULL_FILE
Special sentinal file used in FileOption and test classes among others. |
| Constructor Summary | |
|---|---|
FileOps()
|
|
| Method Summary | |
|---|---|
static java.lang.String |
convertToAbsolutePathEntries(java.lang.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(java.io.File source,
java.io.File dest)
Deprecated. Use IOUtil.copyFile(java.io.File, java.io.File) instead; it scales in a much more efficiently. |
static java.io.File |
createTempDirectory(java.lang.String name)
Create a new temporary directory. |
static java.io.File |
createTempDirectory(java.lang.String name,
java.io.File parent)
Create a new temporary directory. |
static boolean |
deleteDirectory(java.io.File dir)
Deprecated. Use IOUtil.deleteRecursively(java.io.File) instead |
static void |
deleteDirectoryOnExit(java.io.File dir)
Deprecated. Use IOUtil.deleteOnExitRecursively(java.io.File) instead |
static java.io.File |
generateNewFileName(java.io.File base)
Generate a new file name that does not yet exist. |
static java.io.File |
generateNewFileName(java.io.File dir,
java.lang.String name)
Generate a new file name that does not yet exist. |
static java.io.File |
generateNewFileName(java.io.File dir,
java.lang.String prefix,
java.lang.String suffix)
Generate a new file name that does not yet exist. |
static java.io.File |
generateNewFileName(java.io.File dir,
java.lang.String prefix,
java.lang.String suffix,
int max)
Generate a new file name that does not yet exist. |
static java.io.File |
getCanonicalFile(java.io.File f)
Deprecated. Use IOUtil.attemptCanonicalFile(java.io.File) instead. |
static java.lang.String |
getCanonicalPath(java.io.File f)
Deprecated. Use IOUtil.attemptCanonicalFile(java.io.File) instead. (The result will be a
File instead of a String.) |
static java.io.File |
getDrJavaApplicationFile()
Returns the current DrJava application, i.e. |
static java.io.File |
getDrJavaFile()
Returns the drjava.jar file. |
static java.util.ArrayList<java.io.File> |
getFilesInDir(java.io.File d,
boolean recur,
java.io.FileFilter f)
Deprecated. Use IOUtil.attemptListFilesAsIterable(java.io.File) or
IOUtil.listFilesRecursively(File, FileFilter, FileFilter) instead. |
private static void |
getFilesInDir(java.io.File d,
java.util.List<java.io.File> acc,
boolean recur,
java.io.FileFilter filter)
Helper fuction for getFilesInDir(File d, boolean recur). |
static java.io.File |
getShortFile(java.io.File f)
On Windows, return an 8.3 file name for the specified file. |
static java.io.File |
getValidDirectory(java.io.File origFile)
Return a valid directory for use, i.e. |
static boolean |
inFileTree(java.io.File f,
java.io.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(java.io.File ancestor,
java.io.File f)
Return true if the directory ancestor is an ancestor of the file f, i.e. |
static java.io.File |
makeFile(java.io.File parentDir,
java.lang.String child)
Deprecated. For a best-attempt canonical file, use IOUtil.attemptCanonicalFile(java.io.File) instead.
(for example, IOUtil.attemptCanonicalFile(new File(path))) |
static java.io.File |
makeFile(java.lang.String path)
Deprecated. For a best-attempt canonical file, use IOUtil.attemptCanonicalFile(java.io.File) instead.
(for example, IOUtil.attemptCanonicalFile(new File(path))) |
static java.io.File |
makeRelativeTo(java.io.File f,
java.io.File b)
Makes a file equivalent to the given file f that is relative to base file b. |
static boolean |
makeWritable(java.io.File roFile)
|
static boolean |
moveRecursively(java.io.File f,
java.io.File n)
Move f to n, recursively if necessary. |
static java.util.LinkedList<java.lang.String> |
packageExplore(java.lang.String prefix,
java.io.File root)
This function starts from the given directory and finds all packages within that directory |
static java.lang.String |
readFileAsString(java.io.File file)
Deprecated. Use IOUtil.toString(File) instead, which provides the same functionality. |
static java.lang.String |
readFileAsSwingText(java.io.File file)
Reads the entire contents of a file and return them as canonicalized Swing Document text. |
static byte[] |
readStreamAsBytes(java.io.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(java.io.File file,
java.io.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 java.lang.String[] |
splitFile(java.io.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 java.lang.String |
stringMakeRelativeTo(java.io.File f,
java.io.File b)
Makes a file equivalent to the given file f that is relative to base file b. |
static java.net.URL |
toURL(java.io.File f)
Converts the abstract pathname for f into a URL. |
static java.io.File |
validate(java.io.File f)
|
static boolean |
writeIfPossible(java.io.File file,
java.lang.String text,
boolean append)
Deprecated. Use IOUtil.attemptWriteStringToFile(File, String, boolean) instead. |
static void |
writeStringToFile(java.io.File file,
java.lang.String text)
Deprecated. Use the equivalent IOUtil.writeStringToFile(File, String) instead |
static void |
writeStringToFile(java.io.File file,
java.lang.String text,
boolean append)
Deprecated. Use the equivalent IOUtil.writeStringToFile(File, String, boolean) instead |
static java.io.File |
writeStringToNewTempFile(java.lang.String prefix,
java.lang.String suffix,
java.lang.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 |
|---|
private static Log _log
public static final java.io.File NULL_FILE
@Deprecated public static final java.io.FileFilter JAVA_FILE_FILTER
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 java.io.File makeFile(java.lang.String path)
IOUtil.attemptCanonicalFile(java.io.File) instead.
(for example, IOUtil.attemptCanonicalFile(new File(path)))
@Deprecated
public static java.io.File makeFile(java.io.File parentDir,
java.lang.String child)
IOUtil.attemptCanonicalFile(java.io.File) instead.
(for example, IOUtil.attemptCanonicalFile(new File(path)))
@Deprecated
public static boolean inFileTree(java.io.File f,
java.io.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(java.io.File ancestor,
java.io.File f)
ancestor - the ancestorf - the file to test
public static java.io.File makeRelativeTo(java.io.File f,
java.io.File b)
throws java.io.IOException,
java.lang.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.
java.io.IOException
java.lang.SecurityException
public static java.lang.String stringMakeRelativeTo(java.io.File f,
java.io.File b)
throws java.io.IOException
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.
java.io.IOException@Deprecated public static java.lang.String[] splitFile(java.io.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 java.util.ArrayList<java.io.File> getFilesInDir(java.io.File d,
boolean recur,
java.io.FileFilter f)
IOUtil.attemptListFilesAsIterable(java.io.File) or
IOUtil.listFilesRecursively(File, FileFilter, FileFilter) instead.
Files 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 Files.
private static void getFilesInDir(java.io.File d,
java.util.List<java.io.File> acc,
boolean recur,
java.io.FileFilter filter)
acc is mutated to contain
a list of
@Deprecated public static java.io.File getCanonicalFile(java.io.File f)
IOUtil.attemptCanonicalFile(java.io.File) instead.
@Deprecated public static java.lang.String getCanonicalPath(java.io.File f)
IOUtil.attemptCanonicalFile(java.io.File) instead. (The result will be a
File instead of a String.)
public static java.io.File validate(java.io.File f)
@Deprecated
public static byte[] readStreamAsBytes(java.io.InputStream stream)
throws java.io.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.
java.io.IOException
public static java.lang.String readFileAsSwingText(java.io.File file)
throws java.io.IOException
java.io.IOException
@Deprecated
public static java.lang.String readFileAsString(java.io.File file)
throws java.io.IOException
IOUtil.toString(File) instead, which provides the same functionality.
java.io.IOException
@Deprecated
public static void copyFile(java.io.File source,
java.io.File dest)
throws java.io.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
java.io.IOException
@Deprecated
public static java.io.File writeStringToNewTempFile(java.lang.String prefix,
java.lang.String suffix,
java.lang.String text)
throws java.io.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
java.io.IOException
@Deprecated
public static void writeStringToFile(java.io.File file,
java.lang.String text)
throws java.io.IOException
IOUtil.writeStringToFile(File, String) instead
file - File to write totext - Test to write
java.io.IOException
@Deprecated
public static void writeStringToFile(java.io.File file,
java.lang.String text,
boolean append)
throws java.io.IOException
IOUtil.writeStringToFile(File, String, boolean) instead
file - File to write totext - Text to writeappend - whether to append. (false=overwrite)
java.io.IOException
@Deprecated
public static boolean writeIfPossible(java.io.File file,
java.lang.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 java.io.File createTempDirectory(java.lang.String name)
throws java.io.IOException
name - Non-unique portion of the name of the directory to create.
java.io.IOException
public static java.io.File createTempDirectory(java.lang.String name,
java.io.File parent)
throws java.io.IOException
name - Non-unique portion of the name of the directory to create.parent - Parent directory to contain the new directory
java.io.IOException@Deprecated public static boolean deleteDirectory(java.io.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(java.io.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 java.util.LinkedList<java.lang.String> packageExplore(java.lang.String prefix,
java.io.File root)
prefix - the package name of files in the given rootroot - the directory to start exploring from
@Deprecated
public static boolean renameFile(java.io.File file,
java.io.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 java.io.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
java.io.IOException - if the saving or backing up of the file fails for any reason@Deprecated public static java.lang.String convertToAbsolutePathEntries(java.lang.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 java.io.File getValidDirectory(java.io.File origFile)
public static java.net.URL toURL(java.io.File f)
throws java.net.MalformedURLException
java.net.MalformedURLException
public static boolean makeWritable(java.io.File roFile)
throws java.io.IOException
java.io.IOException
public static boolean moveRecursively(java.io.File f,
java.io.File n)
f - file or directory to moven - new location and name for the file or directory
public static java.io.File generateNewFileName(java.io.File base)
throws java.io.IOException
base - base name of the file
java.io.IOException - if file name cannot be generated within 100 attempts
public static java.io.File generateNewFileName(java.io.File dir,
java.lang.String name)
throws java.io.IOException
dir - directory of the filename - the base file name
java.io.IOException - if file name cannot be generated within 100 attempts
public static java.io.File generateNewFileName(java.io.File dir,
java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
dir - directory of the fileprefix - the beginning of the file namesuffix - the end of the file name
java.io.IOException - if file name cannot be generated within 100 attempts
public static java.io.File generateNewFileName(java.io.File dir,
java.lang.String prefix,
java.lang.String suffix,
int max)
throws java.io.IOException
dir - directory of the fileprefix - the beginning of the file namesuffix - the end of the file namemax - maximum number of attempts
java.io.IOException - if file name cannot be generated within max attempts
public static java.io.File getShortFile(java.io.File f)
throws java.io.IOException
f - file for which to find an 8.3 file name
java.io.IOException - if an 8.3 file name could not be foundpublic static java.io.File getDrJavaFile()
public static java.io.File getDrJavaApplicationFile()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||