org.bibalex.daf.handlers.filehandler
Class FileHandler

java.lang.Object
  extended by org.bibalex.daf.handlers.filehandler.FileHandler
Direct Known Subclasses:
FileHandlerFTPImpl, FileHandlerLocalImpl, MockFileHandler

public abstract class FileHandler
extends java.lang.Object

Contains method to handle files and folders. This is an absract class that defines the functionality to be implemented by other classes.
Direct known subclasses are:
1) FileHandlerLocalImp to handle requests belonging to the local file system using java.io package.
2) FileHandlerFTPImp to handle requests regarding remote machine using FileTransferProtocol.

Author:
Shehab.Kamal

Field Summary
static char pathSeparator
          Holds the separator used between path elements.
 
Constructor Summary
FileHandler()
           
 
Method Summary
abstract  boolean createFolder(java.lang.String parentFolder, java.lang.String folderName)
          When ovevrridden in a derived class creates a folder at the specified location.
abstract  boolean createPath(java.lang.String path)
          When overridden in a derived class creates the complete path.
abstract  boolean deleteFolder(java.lang.String path, boolean recursive)
          When overridden in a derived class deletes the folder and its subfolders.
abstract  boolean downloadFile(java.lang.String sourcePath, java.lang.String fileName, java.lang.String destinationPath, java.lang.String newName)
          When overridden in a derived class downloads the file from source to destination.
abstract  boolean downloadFiles(java.lang.String source, java.lang.String extention, java.lang.String destination)
          When overridden in a derived class downloads the files with the given extention from source to destination.
abstract  boolean downloadFolder(java.lang.String source, java.lang.String folderName, java.lang.String destination, java.lang.String newName)
          When overridden in a derived class downloads a folder from source to destination.
abstract  boolean folderExists(java.lang.String folderPath)
          When overridden in a derived class determines whether the folder exists or not.
abstract  java.io.File[] getFiles(java.lang.String parentFolder)
          When overridden in a derived class gets the files within the given folder.
abstract  java.io.File[] getFiles(java.lang.String parentFolder, java.lang.String extention)
          When overridden in a derived class gets the files with a specific extention within the given folder.
abstract  int getFilesCount(java.lang.String parentFolder)
          When overridden in a derived class gets the count of files within the given folder.
abstract  int getFilesCount(java.lang.String parentFolder, java.lang.String extention)
          When overridden in a derived class gets the count of files with a specific extention within the given folder.
abstract  int getFilesCountRecursively(java.lang.String parentFolder)
          When overridden in a derived class gets the count of files within the given folder recursively.
abstract  long getFileSize(java.lang.String filePath)
          When ovevrridden in a derived class gets the size of the file.
abstract  java.lang.String[] getFilesNames(java.lang.String parentFolder)
          When overridden in a derived class gets the names of the files within the given folder.
abstract  java.lang.String[] getFilesNames(java.lang.String parentFolder, java.lang.String extention)
          When overridden in a derived class gets the names of the files with a specific extention within the given folder.
abstract  java.io.File[] getFilesRecursively(java.lang.String parentFolder)
          When overridden in a derived class gets the files within the given folder recursively
abstract  long getFolderSize(java.lang.String folderPath)
          When ovevrridden in a derived class gets the size of the size of the folder recursively.
abstract  java.lang.String[] getSubFolders(java.lang.String parentFolder)
          When overridden in a derived class gets a list of subfolders within the given folder.
abstract  boolean uploadFile(java.lang.String sourcePath, java.lang.String fileName, java.lang.String destinationPath, java.lang.String newName)
          When overridden in a derived class uploads the file from source to destination.
abstract  boolean uploadFiles(java.lang.String source, java.lang.String extention, java.lang.String destination)
          When overridden in a derived class uploads the files with the given extention from source to destination.
abstract  boolean uploadFolder(java.lang.String source, java.lang.String folderName, java.lang.String destination, java.lang.String newName)
          When overridden in a derived class uploads a folder from source to destination.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pathSeparator

public static final char pathSeparator
Holds the separator used between path elements.

See Also:
Constant Field Values
Constructor Detail

FileHandler

public FileHandler()
Method Detail

createFolder

public abstract boolean createFolder(java.lang.String parentFolder,
                                     java.lang.String folderName)
When ovevrridden in a derived class creates a folder at the specified location.

Parameters:
parentFolder - The parent folder path.
folderName - The name of the folder to create
Returns:
True if the folder has been created, otherwise false.

getFileSize

public abstract long getFileSize(java.lang.String filePath)
When ovevrridden in a derived class gets the size of the file.

Parameters:
filePath - The complete path of the the file, that is: parent folder + file name + extension.
Returns:
The size of the file in byte.

getFolderSize

public abstract long getFolderSize(java.lang.String folderPath)
When ovevrridden in a derived class gets the size of the size of the folder recursively.

Parameters:
folderPath - The complete path of the the folder, that is: parent folder + folder name.
Returns:
The size of the folder in bytes.

downloadFolder

public abstract boolean downloadFolder(java.lang.String source,
                                       java.lang.String folderName,
                                       java.lang.String destination,
                                       java.lang.String newName)
When overridden in a derived class downloads a folder from source to destination.

Parameters:
source - The source parent folder.
folderName - The name of the folder to copy.
destination - The destination parent folder.
newName - The new name of the folder after copying.
Returns:
True if the folder has been copied, otherwise false.

uploadFolder

public abstract boolean uploadFolder(java.lang.String source,
                                     java.lang.String folderName,
                                     java.lang.String destination,
                                     java.lang.String newName)
When overridden in a derived class uploads a folder from source to destination.

Parameters:
source - The source parent folder.
folderName - The name of the folder to copy.
destination - The destination parent folder.
newName - The new name of the folder after copying.
Returns:
True if the folder has been copied, otherwise false.

downloadFiles

public abstract boolean downloadFiles(java.lang.String source,
                                      java.lang.String extention,
                                      java.lang.String destination)
When overridden in a derived class downloads the files with the given extention from source to destination.

Parameters:
source - The source folder that contain the files.
extention - The extension of the files to be copied.;
destination - The destination folder to which the files will be copied.
Returns:
True if the files have been copied successfully, otherwise false.

downloadFile

public abstract boolean downloadFile(java.lang.String sourcePath,
                                     java.lang.String fileName,
                                     java.lang.String destinationPath,
                                     java.lang.String newName)
When overridden in a derived class downloads the file from source to destination.

Parameters:
sourcePath - The path of the source folder containg the file.
fileName - The name of the file within the source folder to copy.
destinationPath - The path of the destination folder.
newName - The new name of the file at the destination folder.
Returns:
True if the file has been uploaded otherwise false.

uploadFiles

public abstract boolean uploadFiles(java.lang.String source,
                                    java.lang.String extention,
                                    java.lang.String destination)
When overridden in a derived class uploads the files with the given extention from source to destination.

Parameters:
source - The source folder that contain the files.
extention - The extension of the files to be copied.;
destination - The destination folder to which the files will be copied.
Returns:
True if the files have been copied successfully, otherwise false.

uploadFile

public abstract boolean uploadFile(java.lang.String sourcePath,
                                   java.lang.String fileName,
                                   java.lang.String destinationPath,
                                   java.lang.String newName)
When overridden in a derived class uploads the file from source to destination.

Parameters:
sourcePath - The path of the source folder containg the file.
fileName - The name of the file within the source folder to copy.
destinationPath - The path of the destination folder.
newName - The new name of the file at the destination folder.
Returns:
True if the file has been uploaded otherwise false.

deleteFolder

public abstract boolean deleteFolder(java.lang.String path,
                                     boolean recursive)
When overridden in a derived class deletes the folder and its subfolders.

Parameters:
path - The path of the folder.
recursive - Whether to delete subfiles and subfolders or not.
Returns:
True if the folder has been deleted, otherwise false.

getSubFolders

public abstract java.lang.String[] getSubFolders(java.lang.String parentFolder)
When overridden in a derived class gets a list of subfolders within the given folder.

Parameters:
parentFolder - The folder to get its subfolders.
Returns:
A list of folder within the given folder. If there is not any folders an empty array is returned.

getFiles

public abstract java.io.File[] getFiles(java.lang.String parentFolder)
When overridden in a derived class gets the files within the given folder.

Parameters:
parentFolder - The folder to get the files within it.
Returns:
The files within the folder.

getFilesRecursively

public abstract java.io.File[] getFilesRecursively(java.lang.String parentFolder)
When overridden in a derived class gets the files within the given folder recursively

Parameters:
parentFolder - The folder to get the files within it.
Returns:
The files within the folder.

getFiles

public abstract java.io.File[] getFiles(java.lang.String parentFolder,
                                        java.lang.String extention)
When overridden in a derived class gets the files with a specific extention within the given folder.

Parameters:
parentFolder - The folder to get the files within it.
extention - The extention of the files to get.
Returns:
The files within the folder.

getFilesNames

public abstract java.lang.String[] getFilesNames(java.lang.String parentFolder)
When overridden in a derived class gets the names of the files within the given folder.

Parameters:
parentFolder - The folder to get the names of the files within it.
Returns:
The names of the files within the folder.

getFilesNames

public abstract java.lang.String[] getFilesNames(java.lang.String parentFolder,
                                                 java.lang.String extention)
When overridden in a derived class gets the names of the files with a specific extention within the given folder.

Parameters:
parentFolder - The folder to get the names of the files within it.
extention - The extention of the files to get its name.
Returns:
The names of the files within the folder.

getFilesCount

public abstract int getFilesCount(java.lang.String parentFolder)
When overridden in a derived class gets the count of files within the given folder.

Parameters:
parentFolder - The folder to get the count of files within it.
Returns:
The number of files within the folder.

getFilesCount

public abstract int getFilesCount(java.lang.String parentFolder,
                                  java.lang.String extention)
When overridden in a derived class gets the count of files with a specific extention within the given folder.

Parameters:
parentFolder - The folder to get the count of files within it.
extention - The extention of the files to count.
Returns:
The number of files within the folder.

getFilesCountRecursively

public abstract int getFilesCountRecursively(java.lang.String parentFolder)
When overridden in a derived class gets the count of files within the given folder recursively.

Parameters:
parentFolder - The folder to get the count of files within it.
Returns:
The number of files within the folder.

folderExists

public abstract boolean folderExists(java.lang.String folderPath)
When overridden in a derived class determines whether the folder exists or not.

Parameters:
folderPath - The folder path.
Returns:
True if the folder exists otherwise false.

createPath

public abstract boolean createPath(java.lang.String path)
When overridden in a derived class creates the complete path.

Parameters:
path - The path to create.
Returns:
True if the path has been created or already exists otherwise false.