public class FileHelper extends Object
Title: File Helper
Description: File-related helper functions
Copyright: Copyright (c) 2006-2009
Modifier and Type | Class | Description |
---|---|---|
static class |
FileHelper.LockRecord |
Modifier and Type | Method | Description |
---|---|---|
static String |
cat(File f) |
|
static String |
cat(InputStream is) |
|
static String |
cat(Reader reader) |
|
static String |
cat(Reader reader,
int sizeEstimate) |
|
static String |
cat(String filename) |
|
static String |
cat(URL u) |
|
static boolean |
chmod(File f,
int permissions) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), replacing the permissions using octal
|
static boolean |
chmod(File f,
File copyOf) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), replacing the permissions on
f with
the permissions on copyOf |
static boolean |
chmod(File f,
Set<ChmodBit> set) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), altering the permissions using symbols (ie.
|
static boolean |
chmod(File f,
Set<ChmodBit> set,
Set<ChmodBit> clear) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), altering the permissions using symbols (ie.
|
static boolean |
chmod(String as,
File f,
int permissions) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), replacing the permissions using octal
|
static boolean |
chmod(String as,
File f,
File copyOf) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), replacing the permissions on
f with
the permissions on copyOf |
static boolean |
chmod(String as,
File f,
Set<ChmodBit> set) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), altering the permissions using symbols (ie.
|
static boolean |
chmod(String as,
File f,
Set<ChmodBit> set,
Set<ChmodBit> clear) |
Performs a chmod (which assumes this system is Linux/UNIX/Solaris/etc), altering the permissions using symbols (ie.
|
static boolean |
chown(File f,
String owner,
String group,
boolean recursive) |
|
static void |
copy(File src,
File dest) |
|
static boolean |
couldWrite(File f) |
|
static File |
createTempFile(String prefix,
String suffix) |
Creates a temporary file name
|
static boolean |
delete(File f) |
Deletes a local file or directory from the filesystem
|
static String |
enforceSafeFilename(String filename) |
Ensures that a file is "safe" (this is done by whitelisting a small number of characters)
This method is mainly designed for producing a filename which bears some resemblance to a user-supplied String while removing the risk of being tricked |
static boolean |
isAbsoluteFile(File f) |
|
static boolean |
isAbsoluteFile(String filename) |
|
static boolean |
isAncestor(File root,
File f) |
|
static FileHelper.LockRecord |
lockFile(File f) |
Obtains an exclusive lock on the specified file.
|
static void |
mkdirs(File f) |
Create a directory and any necessary parent directories, throwing a
RuntimeException on failure |
static void |
move(File src,
File dest) |
|
static long |
readPID(File f) |
Reads a PID (Process Id) file
|
static long |
readPID(File f,
boolean carefulProcessing) |
Reads a PID (Process Id) file
|
static boolean |
safeMove(File src,
File dest) |
Deprecated.
use commons file utils FileUtils.moveDirectoryToDirectory instead
|
static boolean |
smartEquals(File one,
File two,
boolean checkName) |
Determines if 2 files or directories are equivalent by looking inside them
|
static void |
symlink(File from,
File to) |
|
static void |
touch(File f) |
Creates/updates a file with the modify date set to now
|
static boolean |
trySymlink(File from,
File to) |
|
static void |
write(File f,
Reader fr) |
|
static void |
write(File f,
String contents) |
|
static void |
write(File f,
StringBuilder sb) |
|
static void |
writePID(File f,
long pid) |
|
static void |
writePID(File f,
String pid) |
public static File createTempFile(String prefix, String suffix)
public static String enforceSafeFilename(String filename)
filename
- public static boolean isAbsoluteFile(File f)
public static boolean isAbsoluteFile(String filename)
public static boolean couldWrite(File f)
public static void copy(File src, File dest) throws IOException
IOException
public static void move(File src, File dest) throws IOException
IOException
public static void symlink(File from, File to) throws IOException
IOException
@Deprecated public static boolean safeMove(File src, File dest) throws SecurityException
src
- File The source filedest
- File The destination fileSecurityException
- MAY BE THROWN if permission is denied to src or destpublic static boolean delete(File f) throws IOException
f
- File The file/directory to deleteIOException
public static boolean smartEquals(File one, File two, boolean checkName) throws IOException
one
- File The first file/directorytwo
- File The second file/directorycheckName
- boolean Whether names should be identical alsoIOException
- On an unhandleable error or a non-file, non-directory inputpublic static long readPID(File f) throws IOException
f
- File The process Id file (must exist!)IOException
- On filesystem-level errorspublic static long readPID(File f, boolean carefulProcessing) throws IOException
f
- File The process Id file (must exist!)carefulProcessing
- boolean If true, non-numeric chars are stripped from the PID before it is parsedIOException
- On filesystem-level errorspublic static void writePID(File f, long pid) throws IOException
IOException
public static void writePID(File f, String pid) throws IOException
IOException
public static void write(File f, String contents) throws IOException
IOException
public static void write(File f, StringBuilder sb) throws IOException
IOException
public static void write(File f, Reader fr) throws IOException
IOException
public static String cat(String filename) throws IOException
IOException
public static String cat(InputStream is) throws IOException
IOException
public static String cat(URL u) throws IOException
IOException
public static String cat(Reader reader) throws IOException
IOException
public static String cat(File f) throws IOException
IOException
public static String cat(Reader reader, int sizeEstimate) throws IOException
IOException
public static boolean chown(File f, String owner, String group, boolean recursive) throws IOException
IOException
public static boolean chmod(File f, int permissions)
f
- permissions
- REMEMBER TO SPECIFY THIS VALUE IN OCTAL (ie. with a leading zero) IF YOU ARE USING NUMBERS IDENTICAL TO THE
CHMOD
COMMAND-LINE REPRESENTATION (eg. 755)IOException
public static boolean chmod(String as, File f, int permissions)
f
- permissions
- REMEMBER TO SPECIFY THIS VALUE IN OCTAL (ie. with a leading zero)IOException
public static boolean chmod(File f, File copyOf)
f
with
the permissions on copyOf
f
- copyOf
- the file to use the permissions fromIOException
public static boolean chmod(String as, File f, File copyOf)
f
with
the permissions on copyOf
f
- copyOf
- the file to use the permissions fromIOException
public static boolean chmod(String as, File f, Set<ChmodBit> set)
f
- set
- The permissions to set on the fileIOException
public static boolean chmod(File f, Set<ChmodBit> set)
f
- set
- The permissions to set on the fileIOException
public static boolean chmod(File f, Set<ChmodBit> set, Set<ChmodBit> clear)
f
- set
- The permissions to set on the fileclear
- The permissions to modify on the fileIOException
public static boolean chmod(String as, File f, Set<ChmodBit> set, Set<ChmodBit> clear)
f
- set
- The permissions to set on the fileclear
- The permissions to modify on the fileIOException
public static FileHelper.LockRecord lockFile(File f)
f
- File The file to lockpublic static void touch(File f) throws IOException
f
- IOException
public static void mkdirs(File f)
RuntimeException
on failuref
- the directory to createRuntimeException
- wrapping the inner IOException if the filesystem cannot create a directoryCopyright © 2018. All rights reserved.