GCSFileDownloaderBase
public
class
GCSFileDownloaderBase
extends GCSCommon
File downloader to download file from google cloud storage (GCS).
Summary
Public methods |
static
File
|
createTempFileForRemote(String remoteFilePath, File rootDir)
Creates a unique file on temporary disk to house downloaded file with given path.
|
InputStream
|
downloadFile(String bucketName, String filename)
Download a file from a GCS bucket file.
|
void
|
downloadFile(String remotePath, File destFile)
|
File
|
downloadFile(String remoteFilePath)
|
StorageObject
|
getRemoteFileMetaData(String bucketName, String remoteFilename)
|
boolean
|
isRemoteFolder(String bucketName, String filename)
Check given filename is a folder or not.
|
String
|
sanitizeDirectoryName(String name)
|
Fields
GCS_APPROX_PREFIX
public static final String GCS_APPROX_PREFIX
GCS_PREFIX
public static final String GCS_PREFIX
mCreateEmptyFile
protected Boolean mCreateEmptyFile
Public constructors
GCSFileDownloaderBase
public GCSFileDownloaderBase (Boolean createEmptyFile)
Parameters |
createEmptyFile |
Boolean |
GCSFileDownloaderBase
public GCSFileDownloaderBase ()
Public methods
createTempFileForRemote
public static File createTempFileForRemote (String remoteFilePath,
File rootDir)
Creates a unique file on temporary disk to house downloaded file with given path.
Constructs the file name based on base file name from path
Parameters |
remoteFilePath |
String : the remote path to construct the name from |
rootDir |
File |
downloadFile
public InputStream downloadFile (String bucketName,
String filename)
Download a file from a GCS bucket file.
Parameters |
bucketName |
String : GCS bucket name |
filename |
String : the filename |
downloadFile
public void downloadFile (String remotePath,
File destFile)
Parameters |
remotePath |
String |
destFile |
File |
downloadFile
public File downloadFile (String remoteFilePath)
Parameters |
remoteFilePath |
String |
public StorageObject getRemoteFileMetaData (String bucketName,
String remoteFilename)
Parameters |
bucketName |
String |
remoteFilename |
String |
isRemoteFolder
public boolean isRemoteFolder (String bucketName,
String filename)
Check given filename is a folder or not.
There 2 types of folders in gcs: 1. Created explicitly from UI. The folder is a size 0
text file (it's an object). 2. When upload a file, all its parent folders will be created,
but these folders doesn't exist (not objects) in gcs. This function work for both cases. But
we should not try to download the size 0 folders.
Parameters |
bucketName |
String : is the gcs bucket name. |
filename |
String : is the relative path to the bucket. |
Returns |
boolean |
true if the filename is a folder, otherwise false. |
sanitizeDirectoryName
public String sanitizeDirectoryName (String name)
Protected methods
createTempFile
protected File createTempFile (String remoteFilePath,
File rootDir)
Parameters |
remoteFilePath |
String |
rootDir |
File |
downloadFile
protected void downloadFile (String bucketName,
String remoteFilename,
File localFile)
Parameters |
bucketName |
String |
remoteFilename |
String |
localFile |
File |
getStorage
protected Storage getStorage ()
listRemoteFilesUnderFolder
protected void listRemoteFilesUnderFolder (String bucketName,
String folder,
subFiles,
subFolders)
Parameters |
bucketName |
String |
folder |
String |
subFiles |
|
subFolders |
|
parseGcsPath
protected String[] parseGcsPath (String remotePath)
Parameters |
remotePath |
String |