|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jopendocument.util.FileUtils
public final class FileUtils
| Field Summary | |
|---|---|
static java.io.FileFilter |
DIR_FILTER
|
static StringUtils.Escaper |
FILENAME_ESCAPER
An escaper suitable for producing valid filenames. |
static java.util.Collection<java.lang.Character> |
INVALID_CHARS
Chars not valid in filenames. |
static java.io.FileFilter |
REGULAR_FILE_FILTER
|
static java.util.Set<java.lang.String> |
VersionControl
|
static java.lang.String |
XML_TYPE
|
| Method Summary | ||
|---|---|---|
static java.io.File |
addSuffix(java.io.File f,
java.lang.String suffix)
|
|
static void |
browseFile(java.io.File f)
|
|
static void |
copyDirectory(java.io.File in,
java.io.File out)
|
|
static void |
copyDirectory(java.io.File in,
java.io.File out,
java.util.Set<java.lang.String> toIgnore)
|
|
static void |
copyDirectory(java.io.File in,
java.io.File out,
java.util.Set<java.lang.String> toIgnore,
boolean useTime)
|
|
static void |
copyFile(java.io.File in,
java.io.File out)
|
|
static void |
copyFile(java.io.File in,
java.io.File out,
boolean useTime)
|
|
static void |
copyFile(java.io.File in,
java.io.File out,
long maxCount)
Copy a file. |
|
static java.io.FileFilter |
createEndFileFilter(java.lang.String ext)
Return a filter that select regular files ending in ext. |
|
static java.io.File |
createTempDir(java.lang.String prefix)
Atomically creates a new directory somewhere beneath the system's temporary directory (as defined by the java.io.tmpdir system property), and returns its name. |
|
static java.io.BufferedWriter |
createWriter(java.io.File f)
Create an UTF-8 buffered writer. |
|
static java.io.BufferedWriter |
createWriter(java.io.File f,
java.nio.charset.Charset cs)
|
|
static java.io.BufferedWriter |
createXMLWriter(java.io.File f)
Create a writer for the passed file, and write the XML declaration. |
|
static
|
doWithLock(java.io.File f,
ExnTransformer<java.io.RandomAccessFile,T,?> transf)
Execute the passed transformer with the lock on the passed file. |
|
static java.lang.String |
findMimeType(java.lang.String fname)
Try to guess the media type of the passed file name (see iana). |
|
static java.util.List<java.io.File> |
getAncestors(java.io.File f)
|
|
static java.lang.String |
getExtension(java.lang.String fname)
Return the string after the last dot. |
|
static java.io.File |
getFile(java.net.URL url)
|
|
static java.util.List<java.io.File> |
list(java.io.File root,
int depth)
|
|
static java.util.List<java.io.File> |
list(java.io.File root,
int depth,
java.io.FileFilter ff)
Finds all files at the specified depth below root. |
|
static java.util.List<java.io.File> |
list(java.io.File root,
int minDepth,
int maxDepth,
java.io.FileFilter ff)
|
|
static java.util.List<java.io.File> |
list(java.io.File root,
int minDepth,
int maxDepth,
java.io.FileFilter ff,
boolean sort)
|
|
static java.util.List<java.lang.String> |
listR(java.io.File dir)
All the files (see File.isFile()) contained in the passed dir. |
|
static java.util.List<java.lang.String> |
listR(java.io.File dir,
java.io.FileFilter ff)
|
|
static java.io.File |
ln(java.io.File target,
java.io.File link)
Create a symbolic link from link to target. |
|
static java.io.File |
mkdir_p(java.io.File dir)
|
|
static java.io.File |
mkParentDirs(java.io.File f)
Create all ancestors of f. |
|
static java.lang.String |
mv(java.io.File f,
java.io.File dest)
Behave like the 'mv' unix utility, ie handle cross filesystems mv and dest being
a directory. |
|
static java.io.File[] |
mvOut(java.io.File parent,
java.lang.String name,
java.lang.String suffix)
Rename a file if necessary by finding a free name. |
|
static void |
open(java.io.File f,
java.lang.String[] executables)
Tries to open the passed file as if it were graphically opened by the current user (respect user's "open with"). |
|
static void |
openFile(java.io.File f)
|
|
static java.io.File |
prependSuffix(java.io.File f,
java.lang.String toInsert,
java.lang.String suffix)
Prepend a string to a suffix. |
|
static java.lang.String |
read(java.io.File f)
Read a file line by line with the default encoding and returns the concatenation of these. |
|
static java.lang.String |
read(java.io.File f,
java.lang.String charset)
Read a file line by line and returns the concatenation of these. |
|
static java.lang.String |
read(java.io.InputStream ins,
java.lang.String charset)
|
|
static java.lang.String |
read(java.io.Reader reader)
|
|
static java.lang.String |
read(java.io.Reader reader,
int bufferSize)
|
|
static byte[] |
readBytes(java.io.File f)
Read the whole content of a file. |
|
static java.io.File |
readlink(java.io.File link)
Resolve a symbolic link or a windows shortcut. |
|
static java.lang.String |
relative(java.io.File fromDir,
java.io.File to)
Returns the relative path from one file to another in the same filesystem tree. |
|
static java.lang.String |
removeSuffix(java.lang.String name,
java.lang.String suffix)
|
|
static void |
rm_R(java.io.File dir)
|
|
static void |
rm(java.io.File f)
|
|
static boolean |
rmR(java.io.File dir)
Delete recursively the passed directory. |
|
static void |
walk(java.io.File dir,
IClosure<java.io.File> c)
|
|
static void |
walk(java.io.File dir,
IClosure<java.io.File> c,
RecursionType type)
|
|
static void |
write(java.lang.String s,
java.io.File f)
|
|
static void |
write(java.lang.String s,
java.io.File f,
java.lang.String charset,
boolean append)
|
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.util.Set<java.lang.String> VersionControl
public static final java.lang.String XML_TYPE
public static final java.util.Collection<java.lang.Character> INVALID_CHARS
public static final StringUtils.Escaper FILENAME_ESCAPER
public static final java.io.FileFilter DIR_FILTER
public static final java.io.FileFilter REGULAR_FILE_FILTER
| Method Detail |
|---|
public static void browseFile(java.io.File f)
public static void openFile(java.io.File f)
throws java.io.IOException
java.io.IOExceptionpublic static java.util.List<java.lang.String> listR(java.io.File dir)
File.isFile()) contained in the passed dir.
dir - the root directory to search.
public static java.util.List<java.lang.String> listR(java.io.File dir,
java.io.FileFilter ff)
public static void walk(java.io.File dir,
IClosure<java.io.File> c)
public static void walk(java.io.File dir,
IClosure<java.io.File> c,
RecursionType type)
public static final java.util.List<java.io.File> list(java.io.File root,
int depth)
public static final java.util.List<java.io.File> list(java.io.File root,
int depth,
java.io.FileFilter ff)
root.
root - the base directorydepth - the depth of the returned files.ff - a filter, can be null.
depth levels beneath root.
public static final java.util.List<java.io.File> list(java.io.File root,
int minDepth,
int maxDepth,
java.io.FileFilter ff)
public static final java.util.List<java.io.File> list(java.io.File root,
int minDepth,
int maxDepth,
java.io.FileFilter ff,
boolean sort)
public static final java.lang.String relative(java.io.File fromDir,
java.io.File to)
throws java.io.IOException
File.getCanonicalPath().
fromDir - the starting directory, eg /a/b/.to - the file to get to, eg /a/x/y.txt.
java.io.IOException - if an error occurs while canonicalizing the files.
java.lang.IllegalArgumentException - if fromDir exists and is not directory.public static final java.util.List<java.io.File> getAncestors(java.io.File f)
public static final java.io.File addSuffix(java.io.File f,
java.lang.String suffix)
public static final java.io.File prependSuffix(java.io.File f,
java.lang.String toInsert,
java.lang.String suffix)
f - the file, e.g. "sample.xml".toInsert - the string to insert in the filename, e.g. "-sql".suffix - the suffix of f, e.g. ".xml".
toInsert prepended to suffix, e.g.
"sample-sql.xml".
public static final java.lang.String removeSuffix(java.lang.String name,
java.lang.String suffix)
public static final java.io.File[] mvOut(java.io.File parent,
java.lang.String name,
java.lang.String suffix)
name + "_" + i + suffix.
parent - the directory.name - the base name of the file.suffix - the suffix of the file, e.g. ".ods".
new File(parent, name + suffix) (always non existing) and the new file,
(or null if no file was moved).
public static java.lang.String mv(java.io.File f,
java.io.File dest)
dest being
a directory.
f - the source file.dest - the destination file or directory.
null if there was none.
public static void copyFile(java.io.File in,
java.io.File out)
throws java.io.IOException
java.io.IOException
public static void copyFile(java.io.File in,
java.io.File out,
long maxCount)
throws java.io.IOException
maxCount since various
implementations have size limitations, see copyFile(File, File).
in - the source file.out - the destination file.maxCount - the number of bytes to copy at a time, 0 meaning size of in.
java.io.IOException - if an error occurs.
public static void copyFile(java.io.File in,
java.io.File out,
boolean useTime)
throws java.io.IOException
java.io.IOException
public static void copyDirectory(java.io.File in,
java.io.File out)
throws java.io.IOException
java.io.IOException
public static void copyDirectory(java.io.File in,
java.io.File out,
java.util.Set<java.lang.String> toIgnore)
throws java.io.IOException
java.io.IOException
public static void copyDirectory(java.io.File in,
java.io.File out,
java.util.Set<java.lang.String> toIgnore,
boolean useTime)
throws java.io.IOException
java.io.IOExceptionpublic static boolean rmR(java.io.File dir)
dir - the dir to be deleted.
true if all deletions were successful.
public static void rm_R(java.io.File dir)
throws java.io.IOException
java.io.IOException
public static void rm(java.io.File f)
throws java.io.IOException
java.io.IOException
public static final java.io.File mkdir_p(java.io.File dir)
throws java.io.IOException
java.io.IOException
public static final java.io.File mkParentDirs(java.io.File f)
throws java.io.IOException
f.
f - any file whose ancestors should be created.
f.
java.io.IOException - if ancestors cannot be created.
public static final java.lang.String read(java.io.File f)
throws java.io.IOException
f - the file to read.
java.io.IOException - if a pb occur while reading.
public static final java.lang.String read(java.io.File f,
java.lang.String charset)
throws java.io.IOException
f - the file to read.charset - the encoding of f, null means default encoding.
java.io.IOException - if a pb occur while reading.
public static final java.lang.String read(java.io.InputStream ins,
java.lang.String charset)
throws java.io.IOException
java.io.IOException
public static final java.lang.String read(java.io.Reader reader)
throws java.io.IOException
java.io.IOException
public static final java.lang.String read(java.io.Reader reader,
int bufferSize)
throws java.io.IOException
java.io.IOException
public static final byte[] readBytes(java.io.File f)
throws java.io.IOException
f - the file to read.
java.io.IOException - if a pb occur while reading.
java.lang.IllegalArgumentException - if f is longer than Integer.MAX_VALUE.
public static void write(java.lang.String s,
java.io.File f)
throws java.io.IOException
java.io.IOException
public static void write(java.lang.String s,
java.io.File f,
java.lang.String charset,
boolean append)
throws java.io.IOException
java.io.IOException
public static java.io.BufferedWriter createXMLWriter(java.io.File f)
throws java.io.IOException
f - a file
java.io.IOException - if an error occurs.StreamUtils.createXMLWriter(java.io.OutputStream)
public static java.io.BufferedWriter createWriter(java.io.File f)
throws java.io.FileNotFoundException
f - the file to write to.
java.io.FileNotFoundException - if the file cannot be opened.
public static java.io.BufferedWriter createWriter(java.io.File f,
java.nio.charset.Charset cs)
throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static final <T> T doWithLock(java.io.File f,
ExnTransformer<java.io.RandomAccessFile,T,?> transf)
throws java.lang.Exception
T - return type.f - the file to lock.transf - what to do on the file.
transf returns.
java.lang.Exception - if an error occurs.
public static final java.io.File getFile(java.net.URL url)
throws java.io.IOException
java.io.IOException
public static final java.io.File ln(java.io.File target,
java.io.File link)
throws java.io.IOException
link to target.
target - the target of the link, eg ".".link - the file to create or replace, eg "l".
null otherwise, eg "l.LNK".
java.io.IOException - if an error occurs.
public static final java.io.File readlink(java.io.File link)
throws java.io.IOException
link - the shortcut, e.g. shortcut.lnk.
link, null if not found, e.g. target.txt.
java.io.IOException - if an error occurs.public static java.io.File createTempDir(java.lang.String prefix)
java.io.tmpdir system property), and returns its name.
Use this method instead of File.createTempFile(String, String) when you wish to
create a directory, not a regular file. A common pitfall is to call createTempFile,
delete the file and create a directory in its place, but this leads a race condition which
can be exploited to create security vulnerabilities, especially when executable files are to
be written into the directory.
This method assumes that the temporary volume is writable, has free inodes and free blocks, and that it will not be called thousands of times per second.
prefix - the prefix string to be used in generating the directory's name.
java.lang.IllegalStateException - if the directory could not be created.
public static final void open(java.io.File f,
java.lang.String[] executables)
throws java.io.IOException
f - the file to open.executables - a list of executables to try, e.g. ["ooffice", "soffice"].
java.io.IOException - if the file can't be opened.public static final java.lang.String findMimeType(java.lang.String fname)
fname - a file name.
public static final java.lang.String getExtension(java.lang.String fname)
fname - a name, e.g. "test.odt" or "sans".
null.public static final java.io.FileFilter createEndFileFilter(java.lang.String ext)
ext.
ext - the end of the name, eg ".xml".
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||