
public final class FileUtilities extends Object
| Modifier and Type | Field and Description |
|---|---|
private static String |
BACKUP_EXTENSION |
| Modifier | Constructor and Description |
|---|---|
private |
FileUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Serializable> |
cloneObject(T x)
This method provides a shortcut to deep clone Serializable objects.
|
static <T extends Serializable> |
deserializeObject(byte[] b)
Serializes an object in memory.
|
static long |
fileCRC32sum(File f)
Computes the CRC32 sum for a given file.
|
static Serializable |
fileToObject(File f)
This method tries to resemble an Object from a file.
|
static Object |
fileToObject(String path)
This method tries to resemble an Object from a file.
|
static String |
fileToString(File f)
Deprecated.
Developers should use
FileUtils.readFileToString(File, String) from Apache
Commons IO |
static String |
fileToString(String path)
Deprecated.
Use
fileUTF8ToString(String) instead, or specify a Charset. |
static String |
fileToString(String path,
Charset c)
This method tries to read a file and to instance it as a String.
|
static String |
fileUTF8ToString(String path)
This method tries to read a file and to instance it as a String.
|
static boolean |
isInHiddenPath(File file)
Tests whether or not any parent of the given file is hidden.
|
static Image |
loadImage(String path)
This method loads an Image from the file system.
|
static void |
objectToFile(Object s,
File f,
boolean backup)
This method serializes an Object into a File.
|
static void |
objectToFile(Serializable s,
String path,
boolean backup)
This method serializes an Object into a File.
|
static byte[] |
serializeObject(Serializable x)
Serializes an object in memory.
|
static void |
stringToFile(String s,
File f,
boolean append)
Deprecated.
use
FileUtils.writeStringToFile(File, String, Charset) instead |
static void |
stringToFile(String string,
String path)
Deprecated.
use
FileUtils.writeStringToFile(File, String, Charset) instead |
static void |
stringToFile(String string,
String path,
boolean append)
Deprecated.
use
FileUtils.writeStringToFile(File, String, Charset, boolean) instead |
private static final String BACKUP_EXTENSION
public static <T extends Serializable> T cloneObject(T x) throws IOException, ClassNotFoundException
T - the Object typex - the object to cloneIOException - If your memory failsClassNotFoundException - it never shouldpublic static <T extends Serializable> T deserializeObject(byte[] b)
T - the Object typeb - the byte array representation of object to serializepublic static long fileCRC32sum(File f) throws IOException
f - the fileIOException - if an I/O error occurspublic static Serializable fileToObject(File f) throws IOException, ClassNotFoundException
f - the file to loadIOException - in case of I/O errorsClassNotFoundException - in case there is no compatible Class in Classpath for the
Object to be loadedpublic static Object fileToObject(String path) throws IOException, ClassNotFoundException
path - the path of the file to loadIOException - in case of I/O errorsClassNotFoundException - in case there is no compatible Class in Classpath for the
Object to be loaded@Deprecated public static String fileToString(File f) throws IOException
FileUtils.readFileToString(File, String) from Apache
Commons IOf - the file to readIOException - in case of I/O errors@Deprecated public static String fileToString(String path) throws IOException
fileUTF8ToString(String) instead, or specify a Charset.path - the path of the file to readIOException - in case of I/O errorspublic static String fileUTF8ToString(String path) throws IOException
path - the path of the file to readIOException - in case of I/O errorspublic static String fileToString(String path, Charset c) throws IOException
path - the path of the file to readc - the Charset to useIOException - in case of I/O errorspublic static boolean isInHiddenPath(File file)
file - the file to testpublic static Image loadImage(String path)
path - the path of the file to readpublic static void objectToFile(Object s, File f, boolean backup) throws IOException
s - the Object to serializef - the File which will contain the serialized Objectbackup - If true and the file already exists, the ".bak" extension will
be added to the existing file, preventing overwritingIOException - in case of I/O errorspublic static void objectToFile(Serializable s, String path, boolean backup) throws IOException
s - the Object to serializepath - the path of the File which will contain the serialized Objectbackup - If true and the file already exists, the ".bak" extension will
be added to the existing file, preventing overwritingIOException - in case of I/O errorspublic static byte[] serializeObject(Serializable x)
x - the object to serialize@Deprecated public static void stringToFile(String s, File f, boolean append) throws IOException
FileUtils.writeStringToFile(File, String, Charset) insteads - the String to savef - the File to write toappend - decides whether to append or overwrite the fileIOException - in case of I/O errorspublic static void stringToFile(String string, String path) throws IOException
FileUtils.writeStringToFile(File, String, Charset) insteadstring - the String to savepath - the path of the File to write toIOException - in case of I/O errorspublic static void stringToFile(String string, String path, boolean append) throws IOException
FileUtils.writeStringToFile(File, String, Charset, boolean) insteadstring - the String to savepath - the File to write toappend - decides whether to append or overwrite the fileIOException - in case of I/O errors