public class FileOperation extends Object
FileUploader
and FileDownloader
are derived.
The purpose of this class is to model certain basic functions like
searching directories for specific file patterns, retrieving file attributes
like size, creation time etc. for both files on the KIFS and local directories
and also determining which files to be uploaded/downloaded either in one go
or in parts based on the size and a threshold which is given by the method
getFileSizeToSplit() of the GPUdbFileHandler.Options class.Modifier and Type | Field and Description |
---|---|
protected GPUdb |
db |
protected String |
dirName
This stores the directory name from which the source files for any
operation (upload or download) is to be searched in.
|
protected GPUdbFileHandler.Options |
fileHandlerOptions |
protected List<String> |
fileNames
The list of file names to be either uploaded or downloaded.
|
protected FullFileBatchManager |
fullFileBatchManager |
protected List<String> |
fullFileList
List of file names that can be downloaded in full
|
protected List<String> |
fullRemoteFileNames |
protected static String |
KIFS_PATH_SEPARATOR |
protected List<String> |
multiPartList
List of file names that are multi part uploads/downloads
|
protected List<String> |
multiPartRemoteFileNames |
protected Set<String> |
namesOfFilesUploaded |
protected OpMode |
opMode |
protected boolean |
recursive
Indicates whether the search for files is to be recursive through a
directory hierarchy or not.
|
Constructor and Description |
---|
FileOperation(GPUdb db,
OpMode opMode,
List<String> fileNames,
String dirName,
boolean recursive,
GPUdbFileHandler.Options fileHandlerOptions) |
Modifier and Type | Method and Description |
---|---|
protected void |
decideMultiPart(OpMode opMode)
This method resolves the file names passed in and decides on which could
be downloaded in one go and which ones are large enough to be downloaded
in parts.
|
protected List<KifsFileInfo> |
getFileInfoFromServer(String dirName)
This method gets the file stats for the files residing on the KIFS.
|
protected List<KifsFileInfo> |
getFileInfoFromServer(String dirName,
String fileName)
This method gets the file stats for the files residing on the KIFS.
|
static String |
getKifsPathSeparator() |
Set<String> |
getNamesOfFilesUploaded()
This method returns the list of file names uploaded without the path
information.
|
static boolean |
localDirExists(String dirName)
This is an utility method that checks if a local directory exists or not
|
static boolean |
localFileExists(String fileName)
This method checks if a local file exists or not.
|
static List<org.apache.commons.lang3.tuple.Triple<String,String,String>> |
parseFileNames(List<String> fileNames)
This method parses the list of file names passed in to the constructor
of the classes
FileUploader ,
FileDownloader which are derivatives
of this class. |
protected void |
sortFilesIntoFullAndMultipartLists(List<String> fileList,
List<String> remoteFileList)
This method takes a list of completely resolved file paths and
puts each file into either the
multiPartList or
fullFileList depending on the file size threshold returned by
the method getFileSizeToSplit() of the GPUdbFileHandler.Options class. |
protected org.apache.commons.lang3.tuple.Pair<List<String>,List<String>> |
traverseLocalDirectories(String startingDirName,
List<String> fileNames)
This method traverses the local directory hierarchy starting with the
directory given by the argument 'startingDirName' and the list of file
names.
|
protected static final String KIFS_PATH_SEPARATOR
protected final OpMode opMode
protected final GPUdb db
protected final boolean recursive
protected List<String> fileNames
protected String dirName
protected List<String> multiPartList
protected FullFileBatchManager fullFileBatchManager
protected final GPUdbFileHandler.Options fileHandlerOptions
public FileOperation(GPUdb db, OpMode opMode, List<String> fileNames, String dirName, boolean recursive, GPUdbFileHandler.Options fileHandlerOptions) throws GPUdbException
db
- - The GPUdb
instanceopMode
- - Indicates whether this is an upload or download operationfileNames
- - ListdirName
- - Name of the local/remote directory depending upon
whether it is a download/upload operation.recursive
- - boolean - Indicates whether the path resolution needsfileHandlerOptions
- - a GPUdbFileHandler.Options type objectGPUdbException
- - propagates exceptions raised from various argument
validations.public Set<String> getNamesOfFilesUploaded()
FileIngestor.ingestFromFiles()
method to prepare the list of file names to be passed on to the
GPUdb.insertRecordsFromFiles(InsertRecordsFromFilesRequest)
endpoint.protected void decideMultiPart(OpMode opMode) throws GPUdbException
traverseLocalDirectories(String, List)
and gets the file names properly resolved in a list.opMode
- - OpMode
GPUdbException
protected void sortFilesIntoFullAndMultipartLists(List<String> fileList, List<String> remoteFileList)
multiPartList
or
fullFileList
depending on the file size threshold returned by
the method getFileSizeToSplit() of the GPUdbFileHandler.Options class.fileList
- - a list of file namesprotected List<KifsFileInfo> getFileInfoFromServer(String dirName, String fileName) throws GPUdbException
dirName
- - Name of the KIFS directory root.KifsFileInfo
objectsGPUdbException
- if 'show/files' endpoint failsprotected List<KifsFileInfo> getFileInfoFromServer(String dirName) throws GPUdbException
dirName
- - Name of the KIFS directory root.KifsFileInfo
objectsGPUdbException
- in case 'show/files' endpoint failsprotected org.apache.commons.lang3.tuple.Pair<List<String>,List<String>> traverseLocalDirectories(String startingDirName, List<String> fileNames) throws IOException
startingDirName
- - Directory to start searching fromfileNames
- - Wildcard pattern to search forIOException
public static boolean localDirExists(String dirName)
dirName
- - Name of the directorypublic static boolean localFileExists(String fileName)
fileName
- - String - Name of the filepublic static String getKifsPathSeparator()
public static List<org.apache.commons.lang3.tuple.Triple<String,String,String>> parseFileNames(List<String> fileNames)
FileUploader
,
FileDownloader
which are derivatives
of this class. It resolves the file names, normalizes them and returns
a corresponding list of absolute paths which are used ny the methods of
this class.fileNames
- - List of file names passed in to the
constructor of the derivatives of this class.Triple
objects where the first element is the root of the file
path, the second the full path without the file name and the third just
the file name itself.Copyright © 2024. All rights reserved.