public class FileOperation extends Object
filesystem
API. The consequences of using this class directly in
client code is not guaranteed and maybe undesirable.
This is the base class from which the classes 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 into which the source files for any
operation (upload or download) will be written.
|
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 List<String> |
multiPartList
List of file names that are multi part uploads/downloads
|
protected List<String> |
multiPartRemoteFileNames |
protected Set<String> |
namesOfFilesUploaded
The list of files uploaded, used by the
FileIngestor to insert
records from the uploaded files into the database. |
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)
Constructs a new file operation instance, managing the transfer of a set
of files to a target directory.
|
Modifier and Type | Method and Description |
---|---|
protected void |
decideMultiPart()
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 path)
This method gets the file stats for the files residing on the KIFS.
|
static String |
getKifsPathSeparator()
Deprecated.
|
Set<String> |
getNamesOfFilesUploaded()
This method returns the list of file names uploaded without the path
information.
|
static boolean |
localDirExists(String localDirName)
This is a utility method that checks if a local directory exists or not.
|
static boolean |
localFileExists(String localFileName)
This method checks if a local file exists or not.
|
static List<org.apache.commons.lang3.tuple.Triple<String,String,String>> |
parseFileNames(List<String> fileNamesToParse)
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
GPUdbFileHandler.Options.getFileSizeToSplit() . |
protected org.apache.commons.lang3.tuple.Pair<List<String>,List<String>> |
traverseLocalDirectories(String startingDirName,
List<String> localFileNames)
This method traverses the local directory hierarchy starting with the
directory given by the argument
startingDirName and the list of file
names. |
protected final OpMode opMode
protected final GPUdb db
protected final boolean recursive
protected List<String> fileNames
protected Set<String> namesOfFilesUploaded
FileIngestor
to insert
records from the uploaded files into the database.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
instance used to access KiFS.opMode
- Indicates whether this is an upload or download operation.fileNames
- List of source file names.dirName
- Name of the local/remote target directory depending upon
whether it is a download/upload operation.recursive
- Indicates whether any directories given in
fileNames
should be searched for files recursively.fileHandlerOptions
- Options for setting up the files for transfer.GPUdbException
- 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() throws GPUdbException
traverseLocalDirectories(String, List)
and
gets the file names properly resolved in a list.GPUdbException
protected void sortFilesIntoFullAndMultipartLists(List<String> fileList, List<String> remoteFileList)
multiPartList
or
fullFileList
depending on the file size threshold returned by
GPUdbFileHandler.Options.getFileSizeToSplit()
.fileList
- A list of source file names to triage by size.remoteFileList
- A list of target file names for the given sources.protected List<KifsFileInfo> getFileInfoFromServer(String path) throws GPUdbException
path
- Name of the KIFS file or directory of files to retrieve info on.KifsFileInfo
objects for the KiFS file(s) found.GPUdbException
- If the '/show/files' endpoint call fails.protected org.apache.commons.lang3.tuple.Pair<List<String>,List<String>> traverseLocalDirectories(String startingDirName, List<String> localFileNames) throws IOException
startingDirName
and the list of file
names. The method takes care of recursive searches based on a pattern
like (*|**|?) and returns the list of all files found with their fully
normalized and absolute paths for the other methods to work with.
This method is internal and is only invoked when the input file names
have a wildcard pattern.startingDirName
- Local directory to start searching fromlocalFileNames
- Local file names & wildcard patterns to search forIOException
public static boolean localDirExists(String localDirName)
localDirName
- Name of the local directory to check for.localDirName
is null or empty.public static boolean localFileExists(String localFileName)
localFileName
- Name of the file.public static String getKifsPathSeparator()
GPUdbFileHandler.KIFS_PATH_SEPARATOR
directly instead.public static List<org.apache.commons.lang3.tuple.Triple<String,String,String>> parseFileNames(List<String> fileNamesToParse)
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 by the methods of
this class.fileNamesToParse
- 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 © 2025. All rights reserved.