|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dlese.dpc.util.Files
public final class Files
Contains methods for performing common operations on files and directories such as reading, moving, deleting and copying. Also contains methods used to encode and decode IDs from filenames.
Field Summary | |
---|---|
static char |
dirSep
The char used to separate files in the native file system. |
static String |
dirSepStr
The String used to separate files in the native file system. |
Constructor Summary | |
---|---|
Files()
|
Method Summary | |
---|---|
static boolean |
copy(File infile,
File outfile)
Copys the contents of one file to another, as bytes. |
static boolean |
copyDir(File sourceDir,
File destinationDir)
Recursively copies the contents of one directory to another. |
static String |
decode(String msg)
Decode a file name. |
static void |
deleteDirectory(File directory)
Deletes a directory or file and all files and directories within. |
static String |
encode(String msg)
Encode a file name for file system compatibility. |
static String |
escapeWindowsPath(String path)
Escapes a Windows directory path by removing the first colon so that it can be used as the end part of another directory path. |
static String |
fid(File f)
Appends a path into a string in such a way that lexicographic sorting gives the same results as a walk of the file hierarchy. |
static String |
fid2path(String fid)
Converts an fid back to a file path. |
static String |
fuid(File f)
Appends a path and date into a string in such a way that lexicographic sorting gives the same results as a walk of the file hierarchy. |
protected static String |
getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout: |
static char |
getFileSeparatorCh()
Gets the String used to separate files in the native file system. |
static String |
getFileSeparatorStr()
Gets the char used to separate files in the native file system. |
static String |
getIDFromFilename(File file)
Gets a record ID from its file name. |
static String |
getIDFromFilename(String filename)
Gets a record ID from its file name. |
static boolean |
move(File infile,
File outfile)
Moves a file from one location to another. |
protected void |
prtln(String s)
Output a line of text to standard out, with datestamp, if debug is set to true. |
protected static void |
prtlnErr(String s)
Output a line of text to error out, with datestamp. |
static StringBuffer |
readFile(File f)
Reads a file into a StringBuffer. |
static StringBuffer |
readFile(String filePath)
Reads a file into a StringBuffer. |
static StringBuffer |
readFileFromJarClasspath(String filePathInJarClasspath)
Reads a file from a JAR or location in the runtime classpath. |
static StringBuffer |
readFileToEncoding(File f,
String encoding)
Reads a file to a StringBuffer that will be in the given character encoding, for example UTF-8. |
static StringBuffer |
readInputStream(InputStream is)
Reads an InputStream into a StringBuffer and closes the stream when done. |
static void |
setDebug(boolean db)
Sets the debug attribute of the object |
static boolean |
touch(File file)
Resets the file mod time to the current time. |
static boolean |
touch(String filePath)
Resets the file mod time to the current time. |
static void |
writeFile(StringBuffer content,
File file)
Writes a file containing the given content using UTF-8 encoding. |
static void |
writeFile(StringBuffer content,
String filePath)
Writes a file containing the given content using UTF-8 encoding. |
static void |
writeFile(String content,
File file)
Writes a file containing the given content using UTF-8 encoding. |
static void |
writeFile(String content,
String filePath)
Writes a file containing the given content using UTF-8 encoding. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static char dirSep
public static String dirSepStr
Constructor Detail |
---|
public Files()
Method Detail |
---|
public static String getFileSeparatorStr()
public static char getFileSeparatorCh()
public static boolean touch(String filePath)
filePath
- A path to a file.
public static boolean touch(File file)
file
- A File.
public static final StringBuffer readFileFromJarClasspath(String filePathInJarClasspath)
filePathInJarClasspath
- The path to the file inside the JAR file or classpath
public static final StringBuffer readFile(String filePath) throws IOException
filePath
- The path to the file.
IOException
- If error.public static final StringBuffer readFile(File f) throws IOException
f
- The file.
IOException
- If error.public static final StringBuffer readFileToEncoding(File f, String encoding) throws IOException
f
- The File to readencoding
- The encoding to write to, or null to use the default system encoding
IOException
- If errorpublic static final StringBuffer readInputStream(InputStream is) throws IOException
is
- The InputStream.
IOException
- If error.public static final void writeFile(String content, File file) throws IOException
content
- The content to write.file
- The file to write to.
IOException
- If errorpublic static final void writeFile(String content, String filePath) throws IOException
content
- The content to write.filePath
- The file to write to.
IOException
- If errorpublic static final void writeFile(StringBuffer content, File file) throws IOException
content
- The content to write.file
- The file to write to.
IOException
- If error.public static final void writeFile(StringBuffer content, String filePath) throws IOException
content
- The content to write.filePath
- The file to write to.
IOException
- If error.public static final boolean copyDir(File sourceDir, File destinationDir) throws Exception
sourceDir
- The directory to copy.destinationDir
- The directory to copy to.
Exception
- If error.public static final boolean copy(File infile, File outfile) throws Exception
infile
- The file to copy.outfile
- The destination of the copied file.
Exception
- If error.public static boolean move(File infile, File outfile)
infile
- The file to move.outfile
- A file denoting the new location.
public static void deleteDirectory(File directory) throws SecurityException
directory
- The directory to delete.
Exception
- If error.
SecurityException
public static String escapeWindowsPath(String path)
path
- The original path.
public static String getIDFromFilename(File file)
file
- The file.
public static String getIDFromFilename(String filename)
filename
- The file.
public static String fid(File f)
fid2path(String fid)
.
f
- The file whoes path will be encoded.
public static String fuid(File f)
f
- The file whoes path will be encoded.
public static String fid2path(String fid)
fid(File f)
.
fid
- The fid.
public static String encode(String msg) throws Exception
msg
- A String to encode.
Exception
- If error.public static String decode(String msg) throws Exception
msg
- Message to decode
Exception
- If unable to decode.protected static final String getDateStamp()
protected static final void prtlnErr(String s)
s
- The text that will be output to error out.protected final void prtln(String s)
s
- The String that will be output.public static void setDebug(boolean db)
db
- The new debug value
|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |