org.schmant.support.io
Class FileSupport

java.lang.Object
  extended by org.schmant.support.io.FileSupport

public final class FileSupport
extends Object

This class contains static utility methods for working with java.io.File:s.

Since:
0.6
Author:
Karl Gustafsson

Method Summary
static void copyFile(File from, File to)
          Copy the contents of the from file to the to file.
static String getFileNameExtension(File f)
          Get the file name extension for the supplied file.
static String getFileNameExtension(String fileName)
          Get the file name extension for the supplied file name.
static byte[] readBinaryFile(File f)
          Read the contents of the file into a byte array.
static String readTextFile(File f)
          Read the text file to a String.
static String readTextFile(File f, Charset cs)
          Read the text file to a String.
static String readTextFile(File f, String cs)
          Read the text file to a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFileNameExtension

public static String getFileNameExtension(String fileName)
Get the file name extension for the supplied file name.

Parameters:
fileName - The file name.
Returns:
The file name extension without a leading dot, or an empty string if the file name does not have an extension.
Since:
1.1

getFileNameExtension

public static String getFileNameExtension(File f)
Get the file name extension for the supplied file.

Parameters:
f - The file.
Returns:
The file name extension without a leading dot, or an empty string if the file name does not have an extension.
Since:
1.1

readBinaryFile

public static byte[] readBinaryFile(File f)
                             throws WrappedIOException
Read the contents of the file into a byte array.

The code here is borrowed from EntityFS Files.readTextFile() and adapted to work on java.io.File:s.

Parameters:
f - The file to read.
Returns:
The file contents.
Throws:
WrappedIOException - On I/O errors.

readTextFile

public static String readTextFile(File f)
Read the text file to a String.

The code here is borrowed from EntityFS Files.readTextFile() and adapted to work on java.io.File:s.

Parameters:
f - The file to read.
Returns:
The file contents, in a String.

readTextFile

public static String readTextFile(File f,
                                  String cs)
                           throws SchmantException
Read the text file to a String.

The code here is borrowed from EntityFS Files.readTextFile() and adapted to work on java.io.File:s.

Parameters:
f - The file to read.
cs - The name of the charset to use for decoding the file contents.
Returns:
The file contents, in a String.
Throws:
SchmantException - If cs is not the name of a character encoding that the running JVM knows about.
See Also:
readTextFile(File, Charset)

readTextFile

public static String readTextFile(File f,
                                  Charset cs)
Read the text file to a String.

Parameters:
f - The file to read.
cs - The name of the charset to use for decoding the file contents.
Returns:
The file contents, in a String.
See Also:
readTextFile(File, String)

copyFile

public static void copyFile(File from,
                            File to)
                     throws EntityNotFoundException,
                            WrongEntityTypeException,
                            WrappedIOException,
                            SchmantException
Copy the contents of the from file to the to file. Any existing contents of to will be overwritten.

Parameters:
from - The file to copy from.
to - The file to copy to.
Throws:
EntityNotFoundException - If from does not exist.
WrongEntityTypeException - If from is not a file.
WrappedIOException - On I/O errors.
SchmantException - On other errors.