Package org.jboss.util.file
Class Files
- java.lang.Object
-
- org.jboss.util.file.Files
-
public final class Files extends java.lang.ObjectA collection of file utilities.- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEThe default size of the copy buffer.private static char[]hexDigitsfor byte-to-hex conversionsprivate static org.jboss.logging.LoggerlogThe Logger instance
-
Constructor Summary
Constructors Constructor Description Files()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopy(java.io.File source, java.io.File target)Copy a file.static voidcopy(java.io.File source, java.io.File target, byte[] buff)Copy a file.static voidcopy(java.io.File source, java.io.File target, int size)Copy a file.static voidcopy(java.net.URL src, java.io.File dest)Copy a remote/local URL to a local filestatic java.lang.StringdecodeFileName(java.lang.String name)Used to decode a file system friendly filename produced by encodeFileName() method, above.static java.lang.StringdecodeFileName(java.lang.String name, char escape)See decodeFileName(String) above.static booleandelete(java.io.File dir)Delete a file, or a directory and all of its contents.static booleandelete(java.lang.String dirname)Delete a file or directory and all of its contents.static booleandeleteContaining(java.lang.String filename)Delete a directory contaning the given file and all its contents.static java.lang.StringencodeFileName(java.lang.String name)Used to encode any string into a string that is safe to use as a file name on most operating systems.static java.lang.StringencodeFileName(java.lang.String name, char escape)See encodeFileName(String) above.static java.lang.StringfindRelativePath(java.lang.String base, java.lang.String path)Build a relative path to the given base path.
-
-
-
Field Detail
-
log
private static final org.jboss.logging.Logger log
The Logger instance
-
hexDigits
private static final char[] hexDigits
for byte-to-hex conversions
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
The default size of the copy buffer.- See Also:
- Constant Field Values
-
-
Method Detail
-
delete
public static boolean delete(java.io.File dir)
Delete a file, or a directory and all of its contents.- Parameters:
dir- The directory or file to delete.- Returns:
- True if all delete operations were successfull.
-
delete
public static boolean delete(java.lang.String dirname)
Delete a file or directory and all of its contents.- Parameters:
dirname- The name of the file or directory to delete.- Returns:
- True if all delete operations were successfull.
-
deleteContaining
public static boolean deleteContaining(java.lang.String filename)
Delete a directory contaning the given file and all its contents.- Parameters:
filename- a file or directory in the containing directory to delete- Returns:
- true if all delete operations were successfull, false if any delete failed.
-
copy
public static void copy(java.io.File source, java.io.File target, byte[] buff) throws java.io.IOExceptionCopy a file.- Parameters:
source- Source file to copy.target- Destination target file.buff- The copy buffer.- Throws:
java.io.IOException- Failed to copy file.
-
copy
public static void copy(java.io.File source, java.io.File target, int size) throws java.io.IOExceptionCopy a file.- Parameters:
source- Source file to copy.target- Destination target file.size- The size of the copy buffer.- Throws:
java.io.IOException- Failed to copy file.
-
copy
public static void copy(java.io.File source, java.io.File target) throws java.io.IOExceptionCopy a file.- Parameters:
source- Source file to copy.target- Destination target file.- Throws:
java.io.IOException- Failed to copy file.
-
copy
public static void copy(java.net.URL src, java.io.File dest) throws java.io.IOExceptionCopy a remote/local URL to a local file- Parameters:
src- the remote or local URLdest- the local file- Throws:
java.io.IOException- upon error
-
encodeFileName
public static java.lang.String encodeFileName(java.lang.String name)
Used to encode any string into a string that is safe to use as a file name on most operating systems. Use decodeFileName() to get back the original string. Copied by Adrian's org.jboss.mq.pm.file.PersistenceManager and adapted to use hex instead of decimal digits- Parameters:
name- the filename to encode- Returns:
- a filesystem-friendly filename
-
decodeFileName
public static java.lang.String decodeFileName(java.lang.String name)
Used to decode a file system friendly filename produced by encodeFileName() method, above. Copied by Adrian's org.jboss.mq.pm.file.PersistenceManager and adapted to use hex instead of decimal digits Note: Decoding will not work if encoding produced multi-byte encoded characters. If this is truly needed we'll have to revise the encoding.- Parameters:
name- the filename to decode- Returns:
- the original name
-
encodeFileName
public static java.lang.String encodeFileName(java.lang.String name, char escape)See encodeFileName(String) above.- Parameters:
name- the filename to encodeescape- the escape character to use- Returns:
- a filesystem-friendly filename
-
decodeFileName
public static java.lang.String decodeFileName(java.lang.String name, char escape)See decodeFileName(String) above.- Parameters:
name- the filename to decodeescape- the escape character to use- Returns:
- the original name
-
findRelativePath
public static java.lang.String findRelativePath(java.lang.String base, java.lang.String path) throws java.io.IOExceptionBuild a relative path to the given base path.- Parameters:
base- - the path used as the basepath- - the path to compute relative to the base path- Returns:
- A relative path from base to path
- Throws:
java.io.IOException
-
-