org.bibalex.daf.handlers.filehandler
Class FileHandlerLocalImpl

java.lang.Object
  extended by org.bibalex.daf.handlers.filehandler.FileHandler
      extended by org.bibalex.daf.handlers.filehandler.FileHandlerLocalImpl

public class FileHandlerLocalImpl
extends FileHandler

Extends FileHandler to provide local file handling.

Author:
Shehab.Kamal

Field Summary
private  LocalFileHandler handler
          A LocalFileHandler to create files and folders.
 
Fields inherited from class org.bibalex.daf.handlers.filehandler.FileHandler
pathSeparator
 
Constructor Summary
FileHandlerLocalImpl()
          Creates a new instance of FileHandlerLocalImp.
 
Method Summary
private  boolean copyFile(java.lang.String sourcePath, java.lang.String fileName, java.lang.String destinationPath, java.lang.String newName)
          Copies the file from source to destination.
private  boolean copyFiles(java.lang.String source, java.lang.String extention, java.lang.String destination)
          Copies the files withe given extention from source to destination.
private  boolean copyFolder(java.lang.String parentSource, java.lang.String folderName, java.lang.String parentDestination, java.lang.String newName)
          Copies a folder from source to destination.
 boolean createFolder(java.lang.String parentFolder, java.lang.String folderName)
          Creates the given folder within the specified path.
 boolean createPath(java.lang.String path)
          Creates the complete path.
 boolean deleteFolder(java.lang.String path, boolean recursive)
          Deletes the folder and its subfolders.
 boolean downloadFile(java.lang.String sourcePath, java.lang.String fileName, java.lang.String destinationPath, java.lang.String newName)
          Downloads the file from source to destination.
 boolean downloadFiles(java.lang.String source, java.lang.String extention, java.lang.String destination)
          Downloads the files with the given extention from source to destination.
 boolean downloadFolder(java.lang.String parentSource, java.lang.String folderName, java.lang.String parentDestination, java.lang.String newName)
          Downloads a folder from source to destination.
 boolean folderExists(java.lang.String folderPath)
          Determines whether the given folder exists or not.
 java.io.File[] getFiles(java.lang.String parentFolder)
          Gets the files within the given folder.
 java.io.File[] getFiles(java.lang.String parentFolder, java.lang.String extention)
          Gets the files with a specific extention within the given folder.
 int getFilesCount(java.lang.String parentFolder)
          Gets the count of files within the given folder.
 int getFilesCount(java.lang.String parentFolder, java.lang.String extention)
          Gets the count of files with a specific extention within the given folder.
 int getFilesCountRecursively(java.lang.String folderPath)
          Gets the total number of files within the folder.
Note: The folder is visited recursively.
 long getFileSize(java.lang.String filePath)
          Gets the size of the file in bytes.
 java.lang.String[] getFilesNames(java.lang.String parentFolder)
          Gets the names of the files within the given folder.
 java.lang.String[] getFilesNames(java.lang.String parentFolder, java.lang.String extention)
          Gets the names of the files with a specific extention within the given folder.
 java.io.File[] getFilesRecursively(java.lang.String parentFolder)
          Gets the files within the given folder recursively.
 long getFolderSize(java.lang.String folderPath)
          Gets the size of the folder, recursively, in bytes.
 java.lang.String[] getSubFolders(java.lang.String parentFolder)
          Gets a list of subfolders within the given folder.
 boolean uploadFile(java.lang.String sourcePath, java.lang.String fileName, java.lang.String destinationPath, java.lang.String newName)
          Downloads the file from source to destination.
 boolean uploadFiles(java.lang.String source, java.lang.String extention, java.lang.String destination)
          Uploads the files with the given extention from source to destination.
 boolean uploadFolder(java.lang.String parentSource, java.lang.String folderName, java.lang.String parentDestination, java.lang.String newName)
          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

handler

private LocalFileHandler handler
A LocalFileHandler to create files and folders.

Constructor Detail

FileHandlerLocalImpl

public FileHandlerLocalImpl()
Creates a new instance of FileHandlerLocalImp.

Method Detail

createFolder

public boolean createFolder(java.lang.String parentFolder,
                            java.lang.String folderName)
Creates the given folder within the specified path.

Specified by:
createFolder in class FileHandler
Parameters:
parentFolder - The parnet folder at which the folder will be created.
folderName - the name of the folder.
Returns:
True if the folder has been created otherwise false.

downloadFolder

public boolean downloadFolder(java.lang.String parentSource,
                              java.lang.String folderName,
                              java.lang.String parentDestination,
                              java.lang.String newName)
Downloads a folder from source to destination. Since there is no server and client in local implementation, the download is merely a copy operation.

Specified by:
downloadFolder in class FileHandler
Parameters:
parentSource - The source parent folder.
folderName - The name of the folder to copy.
parentDestination - 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 boolean uploadFolder(java.lang.String parentSource,
                            java.lang.String folderName,
                            java.lang.String parentDestination,
                            java.lang.String newName)
Uploads a folder from source to destination. Since there is no server and client in local implementation, the upload is merely a copy operation.

Specified by:
uploadFolder in class FileHandler
Parameters:
parentSource - The source parent folder.
folderName - The name of the folder to copy.
parentDestination - The destination parent folder.
newName - The new name of the folder after copying.
Returns:
True if the folder has been copied, otherwise false.

copyFolder

private boolean copyFolder(java.lang.String parentSource,
                           java.lang.String folderName,
                           java.lang.String parentDestination,
                           java.lang.String newName)
Copies a folder from source to destination.

Parameters:
parentSource - The source parent folder.
folderName - The name of the folder to copy.
parentDestination - 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 boolean downloadFiles(java.lang.String source,
                             java.lang.String extention,
                             java.lang.String destination)
Downloads the files with the given extention from source to destination. Since there is no server and client in local implementation, the download is merely a copy operation.

Specified by:
downloadFiles in class FileHandler
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.

uploadFiles

public boolean uploadFiles(java.lang.String source,
                           java.lang.String extention,
                           java.lang.String destination)
Uploads the files with the given extention from source to destination. Since there is no server and client in local implementation, the upload is merely a copy operation.

Specified by:
uploadFiles in class FileHandler
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.

copyFiles

private boolean copyFiles(java.lang.String source,
                          java.lang.String extention,
                          java.lang.String destination)
Copies the files withe given extention from source to destination.

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

downloadFile

public boolean downloadFile(java.lang.String sourcePath,
                            java.lang.String fileName,
                            java.lang.String destinationPath,
                            java.lang.String newName)
Downloads the file from source to destination.

Specified by:
downloadFile in class FileHandler
Parameters:
sourcePath - The source folder taht contain the file.
fileName - The name of the file to download.
destinationPath - The destination folder to which the files will be copied.
newName - The new name of the file.
Returns:
True if the file has been downloaded successfully, otherwise false.

uploadFile

public boolean uploadFile(java.lang.String sourcePath,
                          java.lang.String fileName,
                          java.lang.String destinationPath,
                          java.lang.String newName)
Downloads the file from source to destination.

Specified by:
uploadFile in class FileHandler
Parameters:
sourcePath - The source folder taht contain the file.
fileName - The name of the file to download.
destinationPath - The destination folder to which the files will be copied.
newName - The new name of the file.
Returns:
True if the file has been uploaded successfully, otherwise false.

copyFile

private boolean copyFile(java.lang.String sourcePath,
                         java.lang.String fileName,
                         java.lang.String destinationPath,
                         java.lang.String newName)
Copies the file from source to destination.

Parameters:
sourcePath - The source path.
fileName - The name of the file.
destinationPath - The destination path.
newName - The new name of the file.
Returns:
True if the file has been copied and renamed, if necessary, otherwise false.

deleteFolder

public boolean deleteFolder(java.lang.String path,
                            boolean recursive)
Deletes the folder and its subfolders.

Specified by:
deleteFolder in class FileHandler
Parameters:
path - The path of the folder.
recursive - Whether to delete subfiles and subfolders or not. This parameter is not used.
Returns:
True if the folder has been deleted, otherwise false.

getFolderSize

public long getFolderSize(java.lang.String folderPath)
Gets the size of the folder, recursively, in bytes.

Specified by:
getFolderSize in class FileHandler
Parameters:
folderPath - The full path of the folder; that is folder path + folder name.
Returns:
The size of the folder in bytes. If the folder doesn't exist -1 is returned.

getFileSize

public long getFileSize(java.lang.String filePath)
Gets the size of the file in bytes.

Specified by:
getFileSize in class FileHandler
Parameters:
filePath - The full path of the file; that is folder path + file name + extension.
Returns:
The size of the file in bytes. If the file doesn't exist -1 is returned.

getSubFolders

public java.lang.String[] getSubFolders(java.lang.String parentFolder)
Gets a list of subfolders within the given folder.

Specified by:
getSubFolders in class FileHandler
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. If any exception occurs or the given path doesn't designate an existing folder, null is returned.

getFiles

public java.io.File[] getFiles(java.lang.String parentFolder)
Gets the files within the given folder.

Specified by:
getFiles in class FileHandler
Parameters:
parentFolder - The folder to get the files within it.
Returns:
The files within the folder. null if an exception occurs.

getFilesRecursively

public java.io.File[] getFilesRecursively(java.lang.String parentFolder)
Gets the files within the given folder recursively.

Specified by:
getFilesRecursively in class FileHandler
Parameters:
parentFolder - The folder to get the files within it.
Returns:
The files within the folder. null if an exception occurs.

getFiles

public java.io.File[] getFiles(java.lang.String parentFolder,
                               java.lang.String extention)
Gets the files with a specific extention within the given folder.

Specified by:
getFiles in class FileHandler
Parameters:
parentFolder - The folder to get the files within it.
extention - The extention of the files to get.
Returns:
The files within the folder. null if an exception occurs.

getFilesNames

public java.lang.String[] getFilesNames(java.lang.String parentFolder)
Gets the names of the files within the given folder.

Specified by:
getFilesNames in class FileHandler
Parameters:
parentFolder - The folder to get the names of files within it.
Returns:
The names of the files within the folder. null if an exception occurs.

getFilesNames

public java.lang.String[] getFilesNames(java.lang.String parentFolder,
                                        java.lang.String extention)
Gets the names of the files with a specific extention within the given folder.

Specified by:
getFilesNames in class FileHandler
Parameters:
parentFolder - The folder to get the names of the files within it.
extention - The extention of the files to get.
Returns:
The names of the files within the folder. null if an exception occurs.

getFilesCount

public int getFilesCount(java.lang.String parentFolder)
Gets the count of files within the given folder.

Specified by:
getFilesCount in class FileHandler
Parameters:
parentFolder - The folder to get the count of files within it.
Returns:
The number of files within the folder. -1 if an exception occurs.

getFilesCount

public int getFilesCount(java.lang.String parentFolder,
                         java.lang.String extention)
Gets the count of files with a specific extention within the given folder.

Specified by:
getFilesCount in class FileHandler
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. -1 if an exception occurs.

getFilesCountRecursively

public int getFilesCountRecursively(java.lang.String folderPath)
Gets the total number of files within the folder.
Note: The folder is visited recursively.

Specified by:
getFilesCountRecursively in class FileHandler
Parameters:
folderPath - The path of the folder to count its files.
Returns:
The number of files within the folder or -1 if an exception occurs.

folderExists

public boolean folderExists(java.lang.String folderPath)
Determines whether the given folder exists or not.

Specified by:
folderExists in class FileHandler
Parameters:
folderPath - The path to the folder.
Returns:
True if the folder exists, otherwise false.

createPath

public boolean createPath(java.lang.String path)
Creates the complete path.

Specified by:
createPath in class FileHandler
Parameters:
path - The path to create.
Returns:
True if the path has been created or already exists otherwise false.