com.flexive.shared
Class FxFileUtils

java.lang.Object
  extended by com.flexive.shared.FxFileUtils

public class FxFileUtils
extends java.lang.Object

Utilities for file system access

Since:
3.1
Author:
Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)

Constructor Summary
FxFileUtils()
           
 
Method Summary
static boolean copyFile(java.io.File source, java.io.File destination)
          Copy a file
static long copyNIOChannel(java.nio.channels.ReadableByteChannel source, java.nio.channels.WritableByteChannel destination)
          Copy data from source to destination nio channel
static boolean copyStream2File(long expectedSize, java.io.InputStream sourceStream, java.io.File destinationFile)
          Copy the content of an InputStream to a file
static java.lang.String expandPath(java.lang.String path)
          Expand the path by replacing '~' with the user home directory and fix file separator chars
static boolean fileCompare(java.io.File file1, java.io.File file2)
          Compare if two files match.
static byte[] getBytes(java.io.File file)
          Load a file into a byte array
static java.util.List<java.io.File> listRecursive(java.io.File root)
          List the contents of the given directory recursively.
static java.lang.String loadBase64Encoded(java.io.File file)
          Load a file and base64 encode it
static boolean moveFile(java.io.File source, java.io.File destination)
          Move a file if possible, fallback to normal copy/delete if it fails.
static void removeDirectory(java.io.File dir)
          Remove a directory and all its sub directories and files
static void removeDirectory(java.lang.String dir)
          Remove a directory and all its sub directories and files
static void removeFile(java.io.File file)
          Remove the given file
static void removeFile(java.lang.String fileName)
          Remove the given file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FxFileUtils

public FxFileUtils()
Method Detail

expandPath

public static java.lang.String expandPath(java.lang.String path)
Expand the path by replacing '~' with the user home directory and fix file separator chars

Parameters:
path - the path to expand
Returns:
expanded path

removeFile

public static void removeFile(java.lang.String fileName)
Remove the given file

Parameters:
fileName - file to remove

removeFile

public static void removeFile(java.io.File file)
Remove the given file

Parameters:
file - file to remove

copyNIOChannel

public static long copyNIOChannel(java.nio.channels.ReadableByteChannel source,
                                  java.nio.channels.WritableByteChannel destination)
                           throws java.io.IOException
Copy data from source to destination nio channel

Parameters:
source - source channel
destination - destination channel
Returns:
total number of bytes copied
Throws:
java.io.IOException - on errors

copyFile

public static boolean copyFile(java.io.File source,
                               java.io.File destination)
Copy a file

Parameters:
source - source file
destination - destination file
Returns:
success

copyStream2File

public static boolean copyStream2File(long expectedSize,
                                      java.io.InputStream sourceStream,
                                      java.io.File destinationFile)
Copy the content of an InputStream to a file

Parameters:
expectedSize - expected size of the stream
sourceStream - source
destinationFile - destination
Returns:
copy was successful and sizes match

moveFile

public static boolean moveFile(java.io.File source,
                               java.io.File destination)
Move a file if possible, fallback to normal copy/delete if it fails.

Parameters:
source - the source file
destination - the target file
Returns:
true on success
Since:
3.2.0

removeDirectory

public static void removeDirectory(java.lang.String dir)
Remove a directory and all its sub directories and files

Parameters:
dir - directory to remove recursively

removeDirectory

public static void removeDirectory(java.io.File dir)
Remove a directory and all its sub directories and files

Parameters:
dir - directory to remove recursively

fileCompare

public static boolean fileCompare(java.io.File file1,
                                  java.io.File file2)
Compare if two files match. Currently this method loads both files into memory and compares them, so don't use this on arbitrarily large files.

Parameters:
file1 - first file to compare
file2 - second file to compare
Returns:
match

getBytes

public static byte[] getBytes(java.io.File file)
                       throws java.io.IOException
Load a file into a byte array

Parameters:
file - the file to load
Returns:
byte[]
Throws:
java.io.IOException - on errors

loadBase64Encoded

public static java.lang.String loadBase64Encoded(java.io.File file)
                                          throws java.io.IOException
Load a file and base64 encode it

Parameters:
file - the file to load
Returns:
base64 encoded file content
Throws:
java.io.IOException - on errors

listRecursive

public static java.util.List<java.io.File> listRecursive(java.io.File root)
List the contents of the given directory recursively.

Parameters:
root - the root directory
Returns:
the contents of the directory