Java Doc for FileOps.java in  » IDE » DrJava » edu » rice » cs » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE » DrJava » edu.rice.cs.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   edu.rice.cs.util.FileOps

FileOps
abstract public class FileOps (Code)
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.
version:
   $Id: FileOps.java 4255 2007-08-28 19:17:37Z mgricken $

Inner Class :public interface FileSaver
Inner Class :abstract public static class DefaultFileSaver implements FileSaver

Field Summary
final public static  FileFilterJAVA_FILE_FILTER
     This filter checks for files with names that end in ".java".
final public static  FileNONEXISTENT_FILE
     Special File object corresponding to a dummy file.


Method Summary
public static  StringconvertToAbsolutePathEntries(String path)
     Convert all path entries in a path string to absolute paths.
public static  voidcopyFile(File source, File dest)
     Copies the text of one file into another.
public static  FilecreateTempDirectory(String name)
     Create a new temporary directory.
public static  FilecreateTempDirectory(String name, File parent)
     Create a new temporary directory.
public static  booleandeleteDirectory(File dir)
     Delete the given directory including any files and directories it contains.
Parameters:
  dir - File object representing directory to delete.
public static  voiddeleteDirectoryOnExit(File dir)
     Instructs Java to recursively delete the given directory and its contents when the JVM exits.
Parameters:
  dir - File object representing directory to delete.
public static  FilegetCanonicalFile(File f)
     the canonical file equivalent to f.
public static  StringgetCanonicalPath(File f)
     the canonical path for f.
public static  ArrayList<File>getFilesInDir(File d, boolean recur, FileFilter f)
     List all files (that is, File s for which isFile() is true ) matching the provided filter in the given directory.
Parameters:
  d - The directory to search.
Parameters:
  recur - Whether subdirectories accepted by f should be recursively searched.
public static  FilegetValidDirectory(File origFile)
     Return a valid directory for use, i.e.
public static  booleaninFileTree(File f, File root)
     Determines whether the specified file in within the specified file tree.
public static  FilemakeFile(String path)
    
public static  FilemakeFile(File parentDir, String child)
    
public static  FilemakeRelativeTo(File f, File b)
     Makes a file equivalent to the given file f that is relative to base file b.
public static  LinkedList<String>packageExplore(String prefix, File root)
    
public static  StringreadFileAsString(File file)
     Reads the entire contents of a file and return them as a String.
public static  StringreadFileAsSwingText(File file)
     Reads the entire contents of a file and return them as canonicalized Swing Document text.
public static  byte[]readStreamAsBytes(InputStream stream)
     Reads the stream until it reaches EOF, and then returns the read contents as a byte array.
public static  booleanrenameFile(File file, File dest)
     Renames the given file to the given destination.
public static  voidsaveFile(FileSaver fileSaver)
     This method writes files correctly; it takes care of catching errors and making backups and keeping an unsuccessful file save from destroying the old file (unless a backup is made).
public static  String[]splitFile(File fileToSplit)
     Splits a file into an array of strings representing each parent folder of the given file.
public static  URLtoURL(File f)
     Converts the abstract pathname for f into a URL.
public static  Filevalidate(File f)
     the file f unchanged if f exists; otherwise returns NULL_FILE.
public static  booleanwriteIfPossible(File file, String text, boolean append)
     Writes the text to the given file returning true if it happend and false if it could not.
public static  voidwriteStringToFile(File file, String text)
     Writes text to the file overwriting whatever was there.
public static  voidwriteStringToFile(File file, String text, boolean append)
     Writes text to the file.
Parameters:
  file - File to write to
Parameters:
  text - Text to write
Parameters:
  append - whether to append.
public static  FilewriteStringToNewTempFile(String prefix, String suffix, String text)
     Creates a new temporary file and writes the given text to it.

Field Detail
JAVA_FILE_FILTER
final public static FileFilter JAVA_FILE_FILTER(Code)
This filter checks for files with names that end in ".java". (Note that while this filter was intended to be a javax.swing.filechooser.FileFilter , it actually implements a java.io.FileFilter , because thats what FileFilter means in the context of this source file.) edu.rice.cs.plt.io.IOUtil.extensionFileFilter IOUtil.extensionFileFilter("java")



NONEXISTENT_FILE
final public static File NONEXISTENT_FILE(Code)
Special File object corresponding to a dummy file. Simliar to FileOption.NULL_FILE but exists() returns false.





Method Detail
convertToAbsolutePathEntries
public static String convertToAbsolutePathEntries(String path)(Code)
Convert all path entries in a path string to absolute paths. The delimiter in the path string is the "path.separator" property. Empty entries are equivalent to "." and will thus are converted to the "user.dir" (working directory). Example: ".:drjava::/home/foo/junit.jar" with "user.dir" set to "/home/foo/bar" will be converted to "/home/foo/bar:/home/foo/bar/drjava:/home/foo/bar:/home/foo/junit.jar".
Parameters:
  path - path string with entries to convert path string with all entries as absolute pathsedu.rice.cs.plt.io.IOUtil.parsePathedu.rice.cs.plt.io.IOUtil.getAbsoluteFilesedu.rice.cs.plt.io.IOUtil.attemptAbsoluteFilesedu.rice.cs.plt.io.IOUtil.pathToString



copyFile
public static void copyFile(File source, File dest) throws IOException(Code)
Copies the text of one file into another.
Parameters:
  source - the file to be copied
Parameters:
  dest - the file to be copied toedu.rice.cs.plt.io.IOUtil.copyFile



createTempDirectory
public static File createTempDirectory(String name) throws IOException(Code)
Create a new temporary directory. The directory will be deleted on exit, if empty. (To delete it recursively on exit, use deleteDirectoryOnExit.)
Parameters:
  name - Non-unique portion of the name of the directory to create. File representing the directory that was created.



createTempDirectory
public static File createTempDirectory(String name, File parent) throws IOException(Code)
Create a new temporary directory. The directory will be deleted on exit, if it only contains temp files and temp directories created after it. (To delete it on exit regardless of contents, call deleteDirectoryOnExit after constructing the file tree rooted at this directory. Note that createTempDirectory(..) is not much more helpful than mkdir() in this context (other than generating a new temp file name) because cleanup is a manual process.)
Parameters:
  name - Non-unique portion of the name of the directory to create.
Parameters:
  parent - Parent directory to contain the new directory File representing the directory that was created.



deleteDirectory
public static boolean deleteDirectory(File dir)(Code)
Delete the given directory including any files and directories it contains.
Parameters:
  dir - File object representing directory to delete. If, for some reason, this file object is not a directory, it will still be deleted. true if there were no problems in deleting. If it returns false, something failed and the directorycontents likely at least partially still exist.edu.rice.cs.plt.io.IOUtil.deleteRecursively



deleteDirectoryOnExit
public static void deleteDirectoryOnExit(File dir)(Code)
Instructs Java to recursively delete the given directory and its contents when the JVM exits.
Parameters:
  dir - File object representing directory to delete. If, for some reason, this file object is not a directory, it will still be deleted.edu.rice.cs.plt.io.IOUtil.deleteOnExitRecursively



getCanonicalFile
public static File getCanonicalFile(File f)(Code)
the canonical file equivalent to f. Identical to f.getCanonicalFile() except it does not throw an exception when the file path syntax is incorrect (or an IOException or SecurityException occurs for anyother reason). It returns the absolute File intead.edu.rice.cs.plt.io.IOUtil.attemptCanonicalFile



getCanonicalPath
public static String getCanonicalPath(File f)(Code)
the canonical path for f. Identical to f.getCanonicalPath() except it does not throw an exception when the file path syntax is incorrect; it returns the absolute path instead.edu.rice.cs.plt.io.IOUtil.attemptCanonicalFile File String



getFilesInDir
public static ArrayList<File> getFilesInDir(File d, boolean recur, FileFilter f)(Code)
List all files (that is, File s for which isFile() is true ) matching the provided filter in the given directory.
Parameters:
  d - The directory to search.
Parameters:
  recur - Whether subdirectories accepted by f should be recursively searched. Note that subdirectories that aren't accepted by f will be ignored.
Parameters:
  f - The filter to apply to contained File s. An array of Files in the directory specified; if the directory does not exist, returns an empty list.edu.rice.cs.plt.io.IOUtil.attemptListFilesAsIterableedu.rice.cs.plt.io.IOUtil.listFilesRecursively(FileFileFilterFileFilter)



getValidDirectory
public static File getValidDirectory(File origFile)(Code)
Return a valid directory for use, i.e. one that exists and is as "close" to the file specified. It is 1) file, if file is a directory and exists 2) the closest parent of file, if file is not a directory or does not exist 3) "user.home" a valid directory for use



inFileTree
public static boolean inFileTree(File f, File root)(Code)
Determines whether the specified file in within the specified file tree. edu.rice.cs.plt.io.IOUtil.isMember null



makeFile
public static File makeFile(String path)(Code)
edu.rice.cs.plt.io.IOUtil.attemptCanonicalFile IOUtil.attemptCanonicalFile(new File(path))



makeFile
public static File makeFile(File parentDir, String child)(Code)
edu.rice.cs.plt.io.IOUtil.attemptCanonicalFile IOUtil.attemptCanonicalFile(new File(parentDir, child))



makeRelativeTo
public static File makeRelativeTo(File f, File b) throws IOException, SecurityException(Code)
Makes a file equivalent to the given file f that is relative to base file b. In other words, 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: this method is inherently broken, because it assumes a relative path exists between all files. The Java file system model, however, supports multiple system roots (see File.listRoots ). Thus, two files from different "file systems" (in Windows, different drives) have no common parent.


Parameters:
  f - The path that is to be made relative to the base file
Parameters:
  b - The file to make the next file relative to A new file whose path is relative to the base file while the value of getCanonicalPath() for the returned file is the same as the result of getCanonicalPath() for the given file.



packageExplore
public static LinkedList<String> packageExplore(String prefix, File root)(Code)
This function starts from the given directory and finds all packages within that directory
Parameters:
  prefix - the package name of files in the given root
Parameters:
  root - the directory to start exploring from a list of valid packages, excluding the root ("") package



readFileAsString
public static String readFileAsString(File file) throws IOException(Code)
Reads the entire contents of a file and return them as a String. edu.rice.cs.plt.io.IOUtil.toString(File)



readFileAsSwingText
public static String readFileAsSwingText(File file) throws IOException(Code)
Reads the entire contents of a file and return them as canonicalized Swing Document text. All newLine sequences, including "\n", "\r", and "\r\n" are converted to "\n".



readStreamAsBytes
public static byte[] readStreamAsBytes(InputStream stream) throws IOException(Code)
Reads the stream until it reaches EOF, and then returns the read contents as a byte array. This call may block, since it will not return until EOF has been reached.
Parameters:
  stream - Input stream to read. Byte array consisting of all data read from stream.edu.rice.cs.plt.io.IOUtil.toByteArray IOUtil InputStream



renameFile
public static boolean renameFile(File file, File dest)(Code)
Renames the given file to the given destination. Needed since Windows will not allow a rename to overwrite an existing file.
Parameters:
  file - the file to rename
Parameters:
  dest - the destination file true iff the rename was successfuledu.rice.cs.plt.io.IOUtil.attemptMove



saveFile
public static void saveFile(FileSaver fileSaver) throws IOException(Code)
This method writes files correctly; it takes care of catching errors and making backups and keeping an unsuccessful file save from destroying the old file (unless a backup is made). It makes sure that the file to be saved is not read-only, throwing an IOException if it is. Note: if saving fails and a backup was being created, any existing backup will be destroyed (this is because the backup is written before saving begins, and then moved back over the original file when saving fails). As the old backup would have been destroyed anyways if saving had succeeded, I do not think that this is incorrect or unreasonable behavior.
Parameters:
  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
throws:
  IOException - if the saving or backing up of the file fails for any reason



splitFile
public static String[] splitFile(File fileToSplit)(Code)
Splits a file into an array of strings representing each parent folder of the given file. The file whose path is /home/username/txt.txt in linux would be split into the string array: {"","home","username","txt.txt"}. Delimeters are excluded.
Parameters:
  fileToSplit - the file to split into its directories.edu.rice.cs.plt.io.IOUtil.fullPath File



toURL
public static URL toURL(File f) throws MalformedURLException(Code)
Converts the abstract pathname for f into a URL. This method is included in class java.io.File as f.toURL(), but has been deprecated in Java 6.0 because escape characters on some systems are not handled correctly. The workaround, f.toURI().toURL(), is unsatisfactory because we rely on the old (broken) behavior: toURI() produces escape characters (for example, " " becomes "%20"), which remain in the name when we attempt to convert back to a filename. That is, f.toURI().toURL().getFile() may not be a valid path, even if f exists. (The correct solution is to avoid trying to convert from a URL to a File, because this conversion is not guaranteed to work.)



validate
public static File validate(File f)(Code)
the file f unchanged if f exists; otherwise returns NULL_FILE.



writeIfPossible
public static boolean writeIfPossible(File file, String text, boolean append)(Code)
Writes the text to the given file returning true if it happend and false if it could not. This is a simple wrapper for writeStringToFile that doesn't throw an IOException.
Parameters:
  file - File to write to
Parameters:
  text - Text to write
Parameters:
  append - whether to append. (false=overwrite)edu.rice.cs.plt.io.IOUtil.attemptWriteStringToFile(FileStringboolean)



writeStringToFile
public static void writeStringToFile(File file, String text) throws IOException(Code)
Writes text to the file overwriting whatever was there.
Parameters:
  file - File to write to
Parameters:
  text - Test to writeedu.rice.cs.plt.io.IOUtil.writeStringToFile(FileString)



writeStringToFile
public static void writeStringToFile(File file, String text, boolean append) throws IOException(Code)
Writes text to the file.
Parameters:
  file - File to write to
Parameters:
  text - Text to write
Parameters:
  append - whether to append. (false=overwrite)edu.rice.cs.plt.io.IOUtil.writeStringToFile(FileStringboolean)



writeStringToNewTempFile
public static File writeStringToNewTempFile(String prefix, String suffix, String text) throws IOException(Code)
Creates a new temporary file and writes the given text to it. The file will be deleted on exit.
Parameters:
  prefix - Beginning part of file name, before unique number
Parameters:
  suffix - Ending part of file name, after unique number
Parameters:
  text - Text to write to file name of the temporary file that was creatededu.rice.cs.plt.io.IOUtil.createAndMarkTempFile(StringString)edu.rice.cs.plt.io.IOUtil.writeStringToFile(FileString)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.