|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Observable org.bibalex.daf.handlers.filehandler.FileHandlerObservable org.bibalex.daf.handlers.filehandler.FTPFileHandler
public class FTPFileHandler
This class is an FTP File Transfer Handler, handles all operations concerned with FTP transfer like file/folder copy, comparisons, delete It uses a multithreading technique in some of its operations This class is also the Facade for all the FTP classes in the system
Field Summary | |
---|---|
private java.lang.String |
hostName
|
private com.enterprisedt.net.ftp.FTPClient |
mainFTPClient
|
private static java.util.ArrayList<java.util.Observer> |
observerArrLst
Static Observers list array used to add a list of observers to the file handler before it initialization. |
private java.lang.String |
password
|
private int |
poolSize
|
private int |
port
|
private java.util.concurrent.ExecutorService |
threadExecutor
Private members |
private FTPThreadsPool |
threadsPool
|
private java.lang.String |
userName
|
Constructor Summary | |
---|---|
FTPFileHandler(java.lang.String hostName,
int port,
java.lang.String userName,
java.lang.String password,
int poolSize)
Creates a new instacne of FTPFileHandler. |
|
FTPFileHandler(java.lang.String hostName,
java.lang.String userName,
java.lang.String password,
int poolSize)
Creates a new instacne of FTPFileHandler. |
Method Summary | |
---|---|
static void |
AddObserver(java.util.Observer observer)
Static method allowing assigning some observers before object's initialization. |
private void |
addPreAssignedObservers()
Adds the pre-Assigned observers to the current object. |
int |
compareFolder(java.lang.String localFolderPath,
java.lang.String remoteFolderPath)
Compare 2 folders, one on the local machine and the other one is on the server, if they don't match the method returns the unmatched files count. |
private int |
countDelimeters(java.lang.String path)
Counts the path depth in regard with folders and subfolders. |
boolean |
createFolder(java.lang.String parentPath,
java.lang.String folderName,
boolean overwrite)
Creates a folder at the specified path. |
boolean |
createPath(java.lang.String path)
Creates the complete path. |
void |
deleteFile(java.lang.String remoteFilePath)
Deletes a file on the server |
void |
deleteFolder(java.lang.String remoteFolderPath)
Deletes a folder on the server |
private void |
deleteSingleFile(java.lang.String remoteFilePath)
Deletes a single file from the server, using a new FTP thread. |
private void |
deleteSubFolder(java.lang.String remoteFolderPath)
Deletes a SubFolder on the server, this method is recursive; it recurses on all the subfolders. |
protected void |
finalize()
Closes all FTP Threads connections still opened. |
boolean |
folderExists(java.lang.String folderPath)
Checks if a folder exits on the server or not. |
void |
getFile(java.lang.String localFilePath,
java.lang.String remoteFilePath)
Retrieves a file from the server to the Local Machine |
java.io.File[] |
getFiles(java.lang.String remoteFolderPath)
Gets the files included in a specific folder, this method is not recursive and folders are not counted as files. |
int |
getFilesCount(java.lang.String remoteFolderPath)
Counts the file included in a specific folder, this method is not recursive and folders are not counted as files |
int |
getFilesCountRecursively(java.lang.String folderPath)
Retreives the count of files in the given folderPath in a
recursive way. |
int |
getFilesCountWithExtension(java.lang.String remoteFolderPath,
java.lang.String fileExtension)
Counts the file included in a specific folder with a given extension, this method is not recursive and folders are not counted as files |
long |
getFileSize(java.lang.String filePath)
Gets the size of the file in bytes. |
java.lang.String[] |
getFilesNames(java.lang.String path)
Gets the names of files within the given folder. |
java.lang.String[] |
getFilesNamesWithExt(java.lang.String path,
java.lang.String extension)
Gets the names of the file with the specified extension within the given folder. |
java.io.File[] |
getFilesRecursively(java.lang.String remoteFolderPath)
Gets the files included in a specific folder, this method is recursive and folders are not counted as files. |
java.io.File[] |
getFilesWithExtension(java.lang.String remoteFolderPath,
java.lang.String fileExtension)
Gets the files included in a specific folder with a given extension, this method is not recursive and folders are not counted as files. |
void |
getFolder(java.lang.String localFolderPath,
java.lang.String remoteFolderPath)
Retrieves a folder from the server to the local Machine |
boolean |
getFolder(java.lang.String sourceParent,
java.lang.String folderName,
java.lang.String destinationParent,
java.lang.String newName,
boolean overwrite)
Adds a folder from the server to the local Machine |
long |
getFolderSize(java.lang.String folderPath)
Gets the size of the folder, recursively, in bytes. |
private long |
getFTPFileSize(com.enterprisedt.net.ftp.FTPFile ftpFile)
This method gets a more accurate value of the file size, as it iterates on the size() method until the size value is no longer
being modified |
private java.lang.String |
getLeafFromPath(java.lang.String fullPath)
|
private java.lang.String |
getParentPath(java.lang.String childPath)
Retreives the parent path for a given file or folder name In case it is a root , returned as it is In case it is a
root first child , the root once again is
returned In case it is a
subfolder |
private void |
getSingleFile(java.lang.String localFilePath,
java.lang.String remoteFilePath)
Gets a single file from the server, using a new FTP thread. |
private void |
getSubFolder(java.lang.String localFolderPath,
java.lang.String remoteFolderPath)
Retrieves a SubFolder from the server to the local machine, this method is recursive; it recurses on all the subfolders. |
java.lang.String[] |
getSubFolders(java.lang.String path)
Gets the names of subfolders. |
protected void |
initializeMainThread()
|
void |
putFile(java.lang.String localFilePath,
java.lang.String remoteFilePath)
Adds a file to the server |
void |
putFolder(java.lang.String localFolderPath,
java.lang.String remoteFolderPath)
Puts a folder from the local Machine to the server |
boolean |
putFolder(java.lang.String sourceParent,
java.lang.String folderName,
java.lang.String destinationParent,
java.lang.String newName,
boolean overwrite)
Puts a folder from the local Machine to the server |
private void |
putSingleFile(java.lang.String localFilePath,
java.lang.String remoteFilePath)
Puts a single file on the server, using a new FTP thread. |
private void |
putSubFolder(java.lang.String localFolderPath,
java.lang.String remoteFolderPath)
Adds a SubFolder from the local machine to the server, this method is recursive; it recurses on all the subfolders. |
static void |
RemoveObservers()
Static method responsible for removing all the previously assigned observers. |
boolean |
rename(java.lang.String name,
java.lang.String newName)
This method is used to rename files or folders on an FTP Host. |
private void |
restoreFTPDir(int numberOfDelimeters)
Restors an FTPClient to its original directory, given the delimeters. |
private java.lang.String[] |
tokenizePath(java.lang.String path)
Tokenizes the given path into folder names. |
Methods inherited from class org.bibalex.daf.handlers.filehandler.FileHandlerObservable |
---|
setChanged |
Methods inherited from class java.util.Observable |
---|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.util.ArrayList<java.util.Observer> observerArrLst
private java.util.concurrent.ExecutorService threadExecutor
private FTPThreadsPool threadsPool
private com.enterprisedt.net.ftp.FTPClient mainFTPClient
private int poolSize
private java.lang.String hostName
private int port
private java.lang.String userName
private java.lang.String password
Constructor Detail |
---|
public FTPFileHandler(java.lang.String hostName, java.lang.String userName, java.lang.String password, int poolSize) throws java.lang.Exception
hostName
- Host Network Name or IPuserName
- User Namepassword
- PasswordpoolSize
- The pool size, (Number of threads that could be initialized)
java.lang.Exception
- If the instacne couldn't be initialized.public FTPFileHandler(java.lang.String hostName, int port, java.lang.String userName, java.lang.String password, int poolSize) throws java.lang.Exception
hostName
- Host Network Name or IPport
- Port Number to Communicate on.userName
- User Namepassword
- PasswordpoolSize
- The pool size, (Number of threads that could be initialized)
java.lang.Exception
- If the instacne couldn't be initialized.Method Detail |
---|
public static void AddObserver(java.util.Observer observer)
observer
- the observer to be (pre-)added.public static void RemoveObservers()
protected void initializeMainThread() throws java.lang.Exception
java.lang.Exception
protected void finalize()
finalize
in class java.lang.Object
public void getFile(java.lang.String localFilePath, java.lang.String remoteFilePath) throws java.lang.Exception
localFilePath
- The destination path on the local machineremoteFilePath
- The source path on the server
java.lang.Exception
- Unable to get filepublic void putFile(java.lang.String localFilePath, java.lang.String remoteFilePath) throws java.lang.Exception
localFilePath
- The source file location on the local machineremoteFilePath
- The destination path on the server
java.lang.Exception
- Unable to put filepublic void getFolder(java.lang.String localFolderPath, java.lang.String remoteFolderPath) throws java.lang.Exception
localFolderPath
- The destination folder on the local MachineremoteFolderPath
- The source folder path on the server
java.lang.Exception
- Unable to get Folderpublic boolean getFolder(java.lang.String sourceParent, java.lang.String folderName, java.lang.String destinationParent, java.lang.String newName, boolean overwrite)
sourceParent
- The source Parent Path on the ServerfolderName
- The folder Name to be copieddestinationParent
- The destination Path on the local Machine (Non-Including the
folder Name)newName
- The new Folder Nameoverwrite
- indicates whether to overwrite the existing folder or not, if
set to false and the folder already exists then the method
returns false
public void putFolder(java.lang.String localFolderPath, java.lang.String remoteFolderPath) throws java.lang.Exception
localFolderPath
- The source folder on the local MachineremoteFolderPath
- The destination folder path on the server
java.lang.Exception
- Unable to put Folderpublic boolean putFolder(java.lang.String sourceParent, java.lang.String folderName, java.lang.String destinationParent, java.lang.String newName, boolean overwrite)
sourceParent
- The source Parent Path on the local machinefolderName
- The folder Name to be copieddestinationParent
- The destination Path on the server(Non-Including the folder
Name)newName
- The new Folder Nameoverwrite
- indicates whether to overwrite the existing folder or not, if
set to false and the folder already exists then the method
returns false
public void deleteFile(java.lang.String remoteFilePath) throws java.lang.Exception
remoteFilePath
- The file path on the server to be deleted
java.lang.Exception
- Unable to delete Filepublic void deleteFolder(java.lang.String remoteFolderPath) throws java.lang.Exception
remoteFolderPath
- The folder path on the server to be deleted
java.lang.Exception
- Unable to delete folderpublic int getFilesCount(java.lang.String remoteFolderPath) throws java.io.IOException, com.enterprisedt.net.ftp.FTPException, java.text.ParseException
remoteFolderPath
- The folder path we would like to count the files within
java.io.IOException
com.enterprisedt.net.ftp.FTPException
java.text.ParseException
public java.io.File[] getFiles(java.lang.String remoteFolderPath)
remoteFolderPath
- The folder path we would like to get the files within.
public java.io.File[] getFilesRecursively(java.lang.String remoteFolderPath)
remoteFolderPath
- The folder path we would like to get the files within.
public int getFilesCountWithExtension(java.lang.String remoteFolderPath, java.lang.String fileExtension) throws java.io.IOException, com.enterprisedt.net.ftp.FTPException, java.text.ParseException
remoteFolderPath
- The folder path we would like to count the files withinfileExtension
- The extension used to filter the files count, the extension is
added without the ".", ex: tif, frf
java.io.IOException
com.enterprisedt.net.ftp.FTPException
java.text.ParseException
public java.io.File[] getFilesWithExtension(java.lang.String remoteFolderPath, java.lang.String fileExtension)
remoteFolderPath
- The folder path we would like to get the files within.fileExtension
- The extension used to filter the files count, the extension is
added without the ".", ex: tif, frf
public int compareFolder(java.lang.String localFolderPath, java.lang.String remoteFolderPath) throws java.lang.Exception
localFolderPath
- The folder on the local machine.remoteFolderPath
- The folder on the server.
java.lang.Exception
- Unable to compare folderspublic java.lang.String[] getFilesNames(java.lang.String path)
path
- The path of the folder to get its files.
public java.lang.String[] getFilesNamesWithExt(java.lang.String path, java.lang.String extension)
path
- The path fo the foldders to get the names of the files within.extension
- The extension of the files to get their names. The extension
is the last 3 letters of the file name without the dot '.' .
public boolean folderExists(java.lang.String folderPath)
folderPath
- The folder path that we would like to check for its existance.
public boolean createFolder(java.lang.String parentPath, java.lang.String folderName, boolean overwrite)
parentPath
- The path of the folder at which the folder will be created.folderName
- The name of the folder to create.overwrite
- Whether to overwrite a folder with the same name at the parent
or not.
public java.lang.String[] getSubFolders(java.lang.String path)
path
- The path of the folder to get its sub-folders
public boolean createPath(java.lang.String path)
path
- The path to create
public long getFolderSize(java.lang.String folderPath)
folderPath
- The path of the folder.
public long getFileSize(java.lang.String filePath)
filePath
- The path of the file.
public int getFilesCountRecursively(java.lang.String folderPath)
folderPath
in a
recursive way. Only files are counted, folders are used to fetch
sub-folders.
folderPath
- the root folder path for the count.
int
displaying the count of files within this
fodler recusively.public boolean rename(java.lang.String name, java.lang.String newName)
name
- the old name to replace.newName
- the new Name to use.
true
if the rename was successfull,
false
otherwise.private void getSingleFile(java.lang.String localFilePath, java.lang.String remoteFilePath) throws java.lang.Exception
localFilePath
- The destination path on the local machine.remoteFilePath
- The source file path on the server
java.lang.Exception
- Unable to get the file.private void putSingleFile(java.lang.String localFilePath, java.lang.String remoteFilePath) throws java.lang.Exception
localFilePath
- The source path on the local machine.remoteFilePath
- The destination path on the server.
java.lang.Exception
- Unable to put file.private void deleteSingleFile(java.lang.String remoteFilePath) throws java.lang.Exception
remoteFilePath
- The file path on the server.
java.lang.Exception
- Unable to delete the file (might be because it doesn't
originally exists).private void getSubFolder(java.lang.String localFolderPath, java.lang.String remoteFolderPath) throws java.lang.Exception
localFolderPath
- The destination SubFolder path on the local machine.remoteFolderPath
- The source Subfolder path on the server.
java.lang.Exception
- Unable to get the SubFolderprivate void putSubFolder(java.lang.String localFolderPath, java.lang.String remoteFolderPath) throws java.lang.Exception
localFolderPath
- The source SubFolder path on the local machine.remoteFolderPath
- The destination Subfolder path on the server.
java.lang.Exception
- Unable to put the SubFolderprivate void deleteSubFolder(java.lang.String remoteFolderPath) throws java.lang.Exception
remoteFolderPath
- The Subfolder path on the server to be deleted.
java.lang.Exception
- Unable to delete the SubFolderprivate int countDelimeters(java.lang.String path)
path
- The Path to count the delimiters for.
private void restoreFTPDir(int numberOfDelimeters)
numberOfDelimeters
- the number of Jumps to go Up.private java.lang.String[] tokenizePath(java.lang.String path)
path
- the full path String to tokenize.
private void addPreAssignedObservers()
private java.lang.String getParentPath(java.lang.String childPath)
root
, returned as it is In case it is a
root first child
, the root
once again is
returned In case it is a
subfolder, or an inner file
, the parent folder
is returned
- Parameters:
childPath
- the child path, either file or folder to be fetched for the parent.
- Returns:
- a
string
representing the parent path according to the above mentioned rules.
private java.lang.String getLeafFromPath(java.lang.String fullPath)
private long getFTPFileSize(com.enterprisedt.net.ftp.FTPFile ftpFile)
size()
method until the size value is no longer
being modified
ftpFile
- The ftp
File to get the size for.
FTPFile.size()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |