| java.lang.Object de.intarsys.tools.file.FileTools
FileTools | public class FileTools (Code) | | Some utility methods to ease life with File's
|
Method Summary | |
public static void | appendFile(File source, File destination) Concatenate the two files given in source and
destination . | public static File | checkDirectory(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 File | checkDirectory(String path, boolean create, boolean checkCanRead, boolean checkCanWrite) | public static void | copyBinaryFile(File source, File destination) Copy the byte content of source to
destination . | public static void | copyFile(File source, File destination) | public static void | copyFile(File source, String sourceEncoding, File destination, String destinationEncoding) Copy the character content of source to
destination . | public static void | copyRecursively(File source, File destination) | public static File | copyRecursivelyInto(File source, File destinationParent, String newName) | public static File | createTempFile(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 File | createTempFile(String fileName) Create a file object representing a temporary file in the user's temp dir
with the given filename. | public static void | deleteAfter(File directory, long millis, boolean recursiveScan) Delete any file in directory that is older than
millis milliseconds. | public static boolean | deleteRecursivly(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 boolean | deleteRecursivly(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 String | dumpArchive(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 String | dumpArchive(InputStream is, Filename root, String relativePath, int max, String sourceEncoding, String destinationEncoding, String name) | public static void | emptyFile(File file) Create an empty file. | public static boolean | fileTheSame(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 void | fromBytes(File file, byte[] bytes) Create a file from the byte content. | public static void | fromString(File file, String text) Create a file from the string content. | public static String | getBaseName(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 String | getBaseName(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 String | getBaseName(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 String | getBaseName(String filename, String defaultName) Get the local name of the file in its directory without the extension. | public static String | getExtension(File file) Get the extension of the file name. | public static String | getExtension(String filename) Get the extension of the file name. | public static String | getExtension(String filename, String defaultName) Get the extension of the file name. | public static List | getFiles(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 List | getFiles(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 File | getParentFile(File file) Try to get a valid parent for file. | public static String | getPathRelative(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 String | getRelativePath(File sourceFolder, File target) | public static String | getRootName(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 String | getWindowsStylePath(String osIndependentPath) | public static long | indexOf(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 List | linesContaining(File file, String searchstring) Return a list of all lines in file that contain
searchstring . | public static void | logToFile(File destination, String text) Append text to the file destination . | public static void | renameFile(File source, File destination) | public static void | renameFile(File source, String sourceEncoding, File destination, String destinationEncoding) "Rename" a file. | public static String | replaceAllChars(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 String | toOSIndependentPath(String osPath) | public static String | toOSPath(String osIndependentPath) | public static String | toString(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 String | toString(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 String | trimToFileConform(String param) | public static String | trimToFileConform(String param, String protectedChars) | public static String | trimToURLConform(String param) | public static String | urlPathEscapeEncodeFILE(String s) | public static String | urlPathEscapeEncodeHTTP(String s) | public static String | urlQueryFormEncode(String s) Encode a string to the "x-www-form-urlencoded" form, enhanced with the
UTF-8-in-URL proposal. | public static void | wait(File file, long timeout, long delay) Wait for a file to arrive.
The method waits at most timeout milliseconds for a file
to arrive. |
MAX_BUFFER | final public static int MAX_BUFFER(Code) | | |
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 - |
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, 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 - |
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) |
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. |
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, 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 - |
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 - |
|
|