de.axelwernicke.mypod.util
Class FileUtils

java.lang.Object
  extended byde.axelwernicke.mypod.util.FileUtils

public class FileUtils
extends java.lang.Object

Class that provides some helpers related to file operations.

Author:
axel wernicke

Field Summary
static java.util.regex.Pattern mp3FilePattern
          Pattern to recognize mp3 files
 
Method Summary
static long bufferedCopy(java.io.File source, java.io.File destination, int streamBufferSize, int localBufferSize)
          Copies file using old io with custom buffered streams
static long copy(java.io.File source, java.io.File destination)
          Copies file using nio transfer method.
static boolean delete(java.io.File file)
          Deletes a file.
static int deleteEmptyDirectories(java.util.Vector dirs)
          Deletes empty directories recursively.
static java.util.Vector getAllDirectories(java.io.File dir)
          Gets all subdirectories recursively.
static java.util.Vector getAllFiles(java.io.File dir, java.util.regex.Pattern filter)
          Gets all files below the given directory.
 FileUtils getInstance()
          This is a singleton class, so use getInstance to get in instance :)
static long getSpaceLeft(java.lang.String path)
          Determines the space left on a disc The space is determined by executing a native command ( e.g. dir for windows, df for linux ) This is platform dependend, but ther's no solution provided by java :(
static long getTotalFilesize(java.io.File dir, java.util.regex.Pattern pattern)
          Gets the total filesize recursively
static boolean isWritable(java.io.File file, int maxWait)
          Checks if a file is writable.
static int makeFileAvailable(java.io.File file)
          Checks if a file is accessable.
static int makeFileRWAvailable(java.io.File file)
          Checks if a file is accessable and writable.
static boolean move(java.io.File source, java.io.File destination)
          Moves a file.
static java.lang.String validateDirectoryName(java.lang.String _filename)
          Validates a directory name by replacing invalid characters.
static java.lang.String validateFileName(java.lang.String _filename)
          Validates a filename by replacing invalid characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mp3FilePattern

public static final java.util.regex.Pattern mp3FilePattern
Pattern to recognize mp3 files

Method Detail

getInstance

public FileUtils getInstance()
This is a singleton class, so use getInstance to get in instance :)

Returns:
FileUtils instance

isWritable

public static boolean isWritable(java.io.File file,
                                 int maxWait)
Checks if a file is writable. If its not yet it waits a defined time

Parameters:
file -
maxWait -
Returns:

copy

public static long copy(java.io.File source,
                        java.io.File destination)
Copies file using nio transfer method. Since we get somtimes exceptions, lets try it up to ten times.

Parameters:
source - file
destination - file
Returns:
number of bytes copied

bufferedCopy

public static long bufferedCopy(java.io.File source,
                                java.io.File destination,
                                int streamBufferSize,
                                int localBufferSize)
Copies file using old io with custom buffered streams

Parameters:
streamBufferSize - in bytes
localBufferSize - in bytes
source - file
destination - file
Returns:
number of bytes copied

move

public static boolean move(java.io.File source,
                           java.io.File destination)
Moves a file.
- check parameter
- check if there is something to do
- try to rename file instead physically moving
- if renaming failed, copy using nio transfer method
- if copy succeded, delete source, else delete destination

Parameters:
source - file
destination - file
Returns:
true, if moving succeded

delete

public static boolean delete(java.io.File file)
Deletes a file. If file can not deleted now, its scheduled to be deleted on myPod exit

Parameters:
file - to be deleted
Returns:
true, if file was successfully deleted or scheduled to be deleted on exit.

validateFileName

public static java.lang.String validateFileName(java.lang.String _filename)
Validates a filename by replacing invalid characters. Up to now the validation is for win32 (ntfs)

Parameters:
_filename - to validate
Returns:
validated filename

validateDirectoryName

public static java.lang.String validateDirectoryName(java.lang.String _filename)
Validates a directory name by replacing invalid characters. Up to now the validation is for win32 (ntfs)

Parameters:
_filename - to validate
Returns:
validated directory name

getAllDirectories

public static java.util.Vector getAllDirectories(java.io.File dir)
Gets all subdirectories recursively.

Parameters:
dir - base directory
Returns:
all directories below the base directory

getAllFiles

public static java.util.Vector getAllFiles(java.io.File dir,
                                           java.util.regex.Pattern filter)
Gets all files below the given directory.

Parameters:
filter - file filter that determines the files to find
dir - base directory
Returns:
all files below the base directory as File objects

getTotalFilesize

public static long getTotalFilesize(java.io.File dir,
                                    java.util.regex.Pattern pattern)
Gets the total filesize recursively

Parameters:
dir - to get file size for
pattern - to select files
Returns:
total filesize

getSpaceLeft

public static long getSpaceLeft(java.lang.String path)
Determines the space left on a disc The space is determined by executing a native command ( e.g. dir for windows, df for linux ) This is platform dependend, but ther's no solution provided by java :(

Parameters:
path - path to the disc to get free space for
Returns:
space left on the disc, -1 if determination failed

deleteEmptyDirectories

public static int deleteEmptyDirectories(java.util.Vector dirs)
Deletes empty directories recursively.


makeFileAvailable

public static int makeFileAvailable(java.io.File file)
Checks if a file is accessable.

Parameters:
file - to check
Returns:
GuiUtils.ABORT_OPTION if user aborted

makeFileRWAvailable

public static int makeFileRWAvailable(java.io.File file)
Checks if a file is accessable and writable.

Parameters:
file - to check
Returns:
GuiUtils.ABORT_OPTION if user aborted