Java Doc for FileTools.java in  » PDF » jPod » de » intarsys » tools » file » 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 » PDF » jPod » de.intarsys.tools.file 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   de.intarsys.tools.file.FileTools

FileTools
public class FileTools (Code)
Some utility methods to ease life with File's


Field Summary
final public static  intMAX_BUFFER
    
final static  String[]hex
    


Method Summary
public static  voidappendFile(File source, File destination)
     Concatenate the two files given in source and destination.
public static  FilecheckDirectory(File dir, boolean create, boolean checkCanRead, boolean checkCanWrite)
     Utility method for checking the availablity of a directory.
Parameters:
  dir - The directory to check.
Parameters:
  create - Flag if we should create if dir not already exists.
Parameters:
  checkCanRead - Flag if we should check read permission.
Parameters:
  checkCanWrite - Flag if we should check write permission.
public static  FilecheckDirectory(String path, boolean create, boolean checkCanRead, boolean checkCanWrite)
    
public static  voidcopyBinaryFile(File source, File destination)
     Copy the byte content of source to destination.
public static  voidcopyFile(File source, File destination)
    
public static  voidcopyFile(File source, String sourceEncoding, File destination, String destinationEncoding)
     Copy the character content of source to destination.
public static  voidcopyRecursively(File source, File destination)
    
public static  FilecopyRecursivelyInto(File source, File destinationParent, String newName)
    
public static  FilecreateTempFile(File file)
     Create a file object representing a temporary file in the user's temp dir with the same name as the given file.
public static  FilecreateTempFile(String fileName)
     Create a file object representing a temporary file in the user's temp dir with the given filename.
public static  voiddeleteAfter(File directory, long millis, boolean recursiveScan)
     Delete any file in directory that is older than millis milliseconds.
public static  booleandeleteRecursivly(File file)
     Deletes a file or directory, if necessary recursivly.

Returns true if file could be deleted inclusive its components, otherwise false.


Parameters:
  file - The file or directory to delete.
public static  booleandeleteRecursivly(File file, boolean deleteRoot)
     Deletes a file or directory, if necessary recursivly.

Returns true if file could be deleted inclusive its components, otherwise false.


Parameters:
  file - The file or directory to delete.
Parameters:
  deleteRoot - Flag if the root directory should be deleted itself.
public static  StringdumpArchive(File file, Filename root, String relativePath, int max, String sourceEncoding, String destinationEncoding, boolean deleteSource, boolean forceArchive)
     Archive a files content.

The method creates a copy in the archive directory with a unique name that is guaranteed to create a sortable representation so that newer files have a "greater" filename.

public static  StringdumpArchive(InputStream is, Filename root, String relativePath, int max, String sourceEncoding, String destinationEncoding, String name)
    
public static  voidemptyFile(File file)
     Create an empty file.
public static  booleanfileTheSame(File source, File destination)
     true when the two files represent the same physical file in the file system.
Parameters:
  source - The first file to be checked.
Parameters:
  destination - The second file to be checked.
public static  voidfromBytes(File file, byte[] bytes)
     Create a file from the byte content.
public static  voidfromString(File file, String text)
     Create a file from the string content.
public static  StringgetBaseName(File file)
     Get the local name of the file in its directory without the extension.
Parameters:
  file - The file whose base name is requested.
public static  StringgetBaseName(File file, String defaultName)
     Get the local name of the file in its directory without the extension.
Parameters:
  file - The file whose base name is requested.
public static  StringgetBaseName(String filename)
     Get the local name of the file in its directory without the extension.
Parameters:
  filename - The filename whose base name is requested.
public static  StringgetBaseName(String filename, String defaultName)
     Get the local name of the file in its directory without the extension.
public static  StringgetExtension(File file)
     Get the extension of the file name.
public static  StringgetExtension(String filename)
     Get the extension of the file name.
public static  StringgetExtension(String filename, String defaultName)
     Get the extension of the file name.
public static  ListgetFiles(String path)
     Return the list of all files in the directory specified by path.
Parameters:
  path - The name of the directory to lookup.
public static  ListgetFiles(String path, String pattern)
     Return the list of all files in the directory specified by path that match the pattern defined in pattern.
Parameters:
  path - The name of the directory to lookup.
Parameters:
  pattern - The pattern that should be matched.
public static  FilegetParentFile(File file)
     Try to get a valid parent for file.
public static  StringgetPathRelative(String root, String segment)
     Return segment as a path that is interpreted relative to root if it specifies a relative address, or a correct absolute path.
Parameters:
  root - The optional parent of segment.
Parameters:
  segment - The adress whose adress relative to root isrequested.
public static  StringgetRelativePath(File sourceFolder, File target)
    
public static  StringgetRootName(File file)
     Get the file system root of the file.

The root is defined here as a drive or UNC path specification.


Parameters:
  file - The file whose root is requested.
public static  StringgetWindowsStylePath(String osIndependentPath)
    
public static  longindexOf(File file, String searchstring)
     The first index of searchstring within file.

Use with care!


Parameters:
  file - The file where we search the string.
Parameters:
  searchstring - The string to be searched.
public static  ListlinesContaining(File file, String searchstring)
     Return a list of all lines in file that contain searchstring.
public static  voidlogToFile(File destination, String text)
     Append text to the file destination.
public static  voidrenameFile(File source, File destination)
    
public static  voidrenameFile(File source, String sourceEncoding, File destination, String destinationEncoding)
     "Rename" a file.
public static  StringreplaceAllChars(String source, String replace, char with)
    
public static  byte[]toBytes(File file)
     Create a byte array with the files content.
Parameters:
  file - The file to read.
public static  StringtoOSIndependentPath(String osPath)
    
public static  StringtoOSPath(String osIndependentPath)
    
public static  StringtoString(File file)
     Read a file's content at once and return as a string.

Use with care!


Parameters:
  file - The file to read.
public static  StringtoString(File file, String encoding)
     Read a file's content at once and return as a string in the correct encoding.

Use with care!


Parameters:
  file - The file to read.
Parameters:
  encoding - The encoding to use.
public static  StringtrimToFileConform(String param)
    
public static  StringtrimToFileConform(String param, String protectedChars)
    
public static  StringtrimToURLConform(String param)
    
public static  StringurlPathEscapeEncodeFILE(String s)
    
public static  StringurlPathEscapeEncodeHTTP(String s)
    
public static  StringurlQueryFormEncode(String s)
     Encode a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal.
public static  voidwait(File file, long timeout, long delay)
     Wait for a file to arrive.

The method waits at most timeout milliseconds for a file to arrive.


Field Detail
MAX_BUFFER
final public static int MAX_BUFFER(Code)



hex
final static String[] hex(Code)





Method Detail
appendFile
public static void appendFile(File source, File destination) throws IOException(Code)
Concatenate the two files given in source and destination.
Parameters:
  source - The file to be appended.
Parameters:
  destination - The file to append to.
throws:
  IOException -



checkDirectory
public static File checkDirectory(File dir, boolean create, boolean checkCanRead, boolean checkCanWrite) throws IOException(Code)
Utility method for checking the availablity of a directory.
Parameters:
  dir - The directory to check.
Parameters:
  create - Flag if we should create if dir not already exists.
Parameters:
  checkCanRead - Flag if we should check read permission.
Parameters:
  checkCanWrite - Flag if we should check write permission. The checked directory.
throws:
  IOException -



checkDirectory
public static File checkDirectory(String path, boolean create, boolean checkCanRead, boolean checkCanWrite) throws IOException(Code)

See Also:   FileTools.checkDirectory(File,boolean,boolean,boolean)



copyBinaryFile
public static void copyBinaryFile(File source, File destination) throws IOException(Code)
Copy the byte content of source to destination.
Parameters:
  source - The file whose contents we should copy.
Parameters:
  destination - The file where the contents are copied to.
throws:
  IOException -



copyFile
public static void copyFile(File source, File destination) throws IOException(Code)

See Also:   FileTools.copyBinaryFile(File,File)



copyFile
public static void copyFile(File source, String sourceEncoding, File destination, String destinationEncoding) throws IOException(Code)
Copy the character content of source to destination.
Parameters:
  source - The file whose contents we should copy.
Parameters:
  sourceEncoding - The encoding of the source byte stream.
Parameters:
  destination - The file where the contents are copied to.
Parameters:
  destinationEncoding - The encoding of the destination byte stream.
throws:
  IOException -



copyRecursively
public static void copyRecursively(File source, File destination) throws IOException(Code)



copyRecursivelyInto
public static File copyRecursivelyInto(File source, File destinationParent, String newName) throws IOException(Code)



createTempFile
public static File createTempFile(File file) throws IOException(Code)
Create a file object representing a temporary file in the user's temp dir with the same name as the given file.
Parameters:
  file - filename to use



createTempFile
public static File createTempFile(String fileName) throws IOException(Code)
Create a file object representing a temporary file in the user's temp dir with the given filename. Does not actually create a file in the file system.
Parameters:
  filename - filename to use



deleteAfter
public static void deleteAfter(File directory, long millis, boolean recursiveScan) throws IOException(Code)
Delete any file in directory that is older than millis milliseconds. When recursiveScan is true the directory lookup is made recursive.
Parameters:
  directory - The directory to scan.
Parameters:
  millis - The number of milliseconds a file is allowed to live.
Parameters:
  recursiveScan - Flag if we should handle directories recursive.
throws:
  IOException -



deleteRecursivly
public static boolean deleteRecursivly(File file)(Code)
Deletes a file or directory, if necessary recursivly.

Returns true if file could be deleted inclusive its components, otherwise false.


Parameters:
  file - The file or directory to delete. true if file could be deleted inclusive itscomponents, otherwise false.



deleteRecursivly
public static boolean deleteRecursivly(File file, boolean deleteRoot)(Code)
Deletes a file or directory, if necessary recursivly.

Returns true if file could be deleted inclusive its components, otherwise false.


Parameters:
  file - The file or directory to delete.
Parameters:
  deleteRoot - Flag if the root directory should be deleted itself. true if file could be deleted inclusive itscomponents, otherwise false.



dumpArchive
public static String dumpArchive(File file, Filename root, String relativePath, int max, String sourceEncoding, String destinationEncoding, boolean deleteSource, boolean forceArchive) throws IOException(Code)
Archive a files content.

The method creates a copy in the archive directory with a unique name that is guaranteed to create a sortable representation so that newer files have a "greater" filename. Creation of file names is thread safe. If more than max files are in the archive directory, the oldest files are deleted. max = 0 means never create archive, max = -1 means always create archive. If deleteSource is true, the file to be archived is deleted after the archive was created.


Parameters:
  file - The file to archive.
Parameters:
  root - The root for relative addressing.
Parameters:
  relativePath - The path relative to root where to create the archive.
Parameters:
  max - The maximum number of archive files allowed.han
Parameters:
  sourceEncoding - The encoding of the file to be archived.
Parameters:
  destinationEncoding - The encoding of the archived file.
Parameters:
  deleteSource - Flag if source should be deleted.
Parameters:
  forceArchive - Flag if we should archive even if file is already in thearchive directory. The name of the archived file.
throws:
  IOException -



dumpArchive
public static String dumpArchive(InputStream is, Filename root, String relativePath, int max, String sourceEncoding, String destinationEncoding, String name) throws IOException(Code)

See Also:   FileTools.dumpArchive(File,Filename,String,int,String,String,boolean,boolean)



emptyFile
public static void emptyFile(File file) throws IOException(Code)
Create an empty file.
Parameters:
  file -
throws:
  IOException -



fileTheSame
public static boolean fileTheSame(File source, File destination)(Code)
true when the two files represent the same physical file in the file system.
Parameters:
  source - The first file to be checked.
Parameters:
  destination - The second file to be checked. true when the two files represent the samephysical file in the file system.



fromBytes
public static void fromBytes(File file, byte[] bytes) throws IOException(Code)
Create a file from the byte content.
Parameters:
  file - The file to write/create
Parameters:
  text - The text to be written into the file.
throws:
  IOException -



fromString
public static void fromString(File file, String text) throws IOException(Code)
Create a file from the string content.
Parameters:
  file - The file to write/create
Parameters:
  text - The text to be written into the file.
throws:
  IOException -



getBaseName
public static String getBaseName(File file)(Code)
Get the local name of the file in its directory without the extension.
Parameters:
  file - The file whose base name is requested. The local name of the file in its directory without theextension.



getBaseName
public static String getBaseName(File file, String defaultName)(Code)
Get the local name of the file in its directory without the extension.
Parameters:
  file - The file whose base name is requested. The local name of the file in its directory without theextension.



getBaseName
public static String getBaseName(String filename)(Code)
Get the local name of the file in its directory without the extension.
Parameters:
  filename - The filename whose base name is requested. The local name of the file in its directory without theextension.



getBaseName
public static String getBaseName(String filename, String defaultName)(Code)
Get the local name of the file in its directory without the extension.
Parameters:
  filename - The filename whose base name is requested.
Parameters:
  defaultName - returned if filename is null or a empty String The local name of the file in its directory without theextension.



getExtension
public static String getExtension(File file)(Code)
Get the extension of the file name. If no extension is present, the empty string is returned.
Parameters:
  file - The file whose extension is requested. The extension of the file name. If no extension is present, theempty string is returned.



getExtension
public static String getExtension(String filename)(Code)
Get the extension of the file name. If no extension is present, the empty string is returned.
Parameters:
  filename - The filename whose extension is requested. The extension of the file name. If no extension is present, theempty string is returned.



getExtension
public static String getExtension(String filename, String defaultName)(Code)
Get the extension of the file name. If no extension is present, the defaultName is returned.
Parameters:
  filename - The filename whose extension is requested.
Parameters:
  defaultName - returned if the filename is empty or null or there is noextension The extension of the file name. If no extension is present, theempty string is returned.



getFiles
public static List getFiles(String path)(Code)
Return the list of all files in the directory specified by path.
Parameters:
  path - The name of the directory to lookup. The list of all files in the directory specified bypath.



getFiles
public static List getFiles(String path, String pattern)(Code)
Return the list of all files in the directory specified by path that match the pattern defined in pattern.
Parameters:
  path - The name of the directory to lookup.
Parameters:
  pattern - The pattern that should be matched. the list of all files in the directory specified bypath that match the pattern defined inpattern.



getParentFile
public static File getParentFile(File file)(Code)
Try to get a valid parent for file.
Parameters:
  file -



getPathRelative
public static String getPathRelative(String root, String segment)(Code)
Return segment as a path that is interpreted relative to root if it specifies a relative address, or a correct absolute path.
Parameters:
  root - The optional parent of segment.
Parameters:
  segment - The adress whose adress relative to root isrequested. segment as a path that is interpreted relative toroot if it specifies a relative address, or acorrect absolute path.



getRelativePath
public static String getRelativePath(File sourceFolder, File target) throws IOException(Code)



getRootName
public static String getRootName(File file)(Code)
Get the file system root of the file.

The root is defined here as a drive or UNC path specification.


Parameters:
  file - The file whose root is requested. The file system root of the file.



getWindowsStylePath
public static String getWindowsStylePath(String osIndependentPath)(Code)



indexOf
public static long indexOf(File file, String searchstring) throws IOException(Code)
The first index of searchstring within file.

Use with care!


Parameters:
  file - The file where we search the string.
Parameters:
  searchstring - The string to be searched. The first index of searchstring withinfile.
throws:
  IOException -



linesContaining
public static List linesContaining(File file, String searchstring) throws IOException(Code)
Return a list of all lines in file that contain searchstring. The lines returned contain every character of the line remaining after the end of the occurence of searchstring.

Use with care!


Parameters:
  file - The file where we search in.
Parameters:
  searchstring - The string to be searched. A list of all lines in file that containsearchstring.
throws:
  IOException -



logToFile
public static void logToFile(File destination, String text) throws IOException(Code)
Append text to the file destination.
Parameters:
  destination - The destination file.
Parameters:
  text - The text to be appended.
throws:
  IOException -



renameFile
public static void renameFile(File source, File destination) throws IOException(Code)

See Also:   FileTools.renameFile(File,String,File,String)



renameFile
public static void renameFile(File source, String sourceEncoding, File destination, String destinationEncoding) throws IOException(Code)
"Rename" a file.

The effect is that there is a new file destination, encoded in destinationEncoding, the old file source is deleted.


Parameters:
  source - The source name of the file.
Parameters:
  sourceEncoding - The encoding of the source file.
Parameters:
  destination - The destination name of the file.
Parameters:
  destinationEncoding - The encoding of the destination file.
throws:
  IOException - docme



replaceAllChars
public static String replaceAllChars(String source, String replace, char with)(Code)
docme
Parameters:
  source - docme
Parameters:
  replace - docme
Parameters:
  with - docme docme



toBytes
public static byte[] toBytes(File file) throws IOException(Code)
Create a byte array with the files content.
Parameters:
  file - The file to read. Create a byte array with the files content.
throws:
  IOException -



toOSIndependentPath
public static String toOSIndependentPath(String osPath)(Code)



toOSPath
public static String toOSPath(String osIndependentPath)(Code)



toString
public static String toString(File file) throws IOException(Code)
Read a file's content at once and return as a string.

Use with care!


Parameters:
  file - The file to read. The string content of the file.
throws:
  IOException -



toString
public static String toString(File file, String encoding) throws IOException(Code)
Read a file's content at once and return as a string in the correct encoding.

Use with care!


Parameters:
  file - The file to read.
Parameters:
  encoding - The encoding to use. The string content of the file.
throws:
  IOException -



trimToFileConform
public static String trimToFileConform(String param)(Code)

Parameters:
  param - java.lang.String Trims and replaces all characters which arenot allowed in filenames (for Win32) with spaces java.lang.String



trimToFileConform
public static String trimToFileConform(String param, String protectedChars)(Code)
docme
Parameters:
  param - docme
Parameters:
  protectedChars - docme docme



trimToURLConform
public static String trimToURLConform(String param)(Code)
docme
Parameters:
  param - docme docme



urlPathEscapeEncodeFILE
public static String urlPathEscapeEncodeFILE(String s)(Code)
DOCUMENT ME!
Parameters:
  s - The string to be encoded The encoded string



urlPathEscapeEncodeHTTP
public static String urlPathEscapeEncodeHTTP(String s)(Code)
DOCUMENT ME!
Parameters:
  s - The string to be encoded The encoded string



urlQueryFormEncode
public static String urlQueryFormEncode(String s)(Code)
Encode a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal. This is what happens:
  • The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same.

  • The space character ' ' is converted into a plus sign '+'.

  • All other ASCII characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the character code

  • All non-ASCII characters are encoded in two steps: first to a sequence of 2 or 3 bytes, using the UTF-8 algorithm; secondly each of these bytes is encoded as "%xx".


Parameters:
  s - The string to be encoded The encoded string



wait
public static void wait(File file, long timeout, long delay) throws IOException(Code)
Wait for a file to arrive.

The method waits at most timeout milliseconds for a file to arrive. When delay is != 0 the method checks the file's size for changes it reaches a stable size.


Parameters:
  file - The file to wait for.
Parameters:
  timeout - The maximum time in milliseconds to wait for first occurenceof file.
Parameters:
  delay - The number of milliseconds between two checks against thefiles size.
throws:
  IOException -



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.