public abstract class GDriver extends Object
class GDriveCrypter extends GDriver { // .... whatever public static void main(String[] args) { String fileNameToUpload = "someFile.txt"; GDriveCrypter instance = new GDriveCrypter(fileNameToUpload); // super is provided by GDriver //Authorize GDrive instance.initDrive(instance.authorize()); // provided by GDriver // Encrypt String encryptedFilename = instance.encrypt(instance.getloadFilePath()); if (encryptedFilename!=null && !encryptedFilename.equals("")) { // Send File to GDrive instance.setloadFilePath(encryptedFilename); // provided by GDriver File uploadedFile = instance.uploadFile(false); // provided by GDriver } } }
Modifier and Type | Field and Description |
---|---|
protected static String |
APPLICATION_NAME
Class constant holding an application name for use by logger or whatever.
|
protected static String |
CLASSNAME
A holder This classes name (used when logging).
|
static String |
CLASSPATH
The VM classpath (used in some methods)..
|
protected static com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets |
clientSecrets_
Classvar holding the GoogleClientSecrets for this and extended classes.
|
protected File |
dataStoreDir_
Directory to store user credentials.
|
protected com.google.api.client.util.store.FileDataStoreFactory |
dataStoreFactory_
Global instance of the
DataStoreFactory . |
protected static String |
DEFAULT_DATASTORE_DIR
Class constant holding a defaultdatastore directory.
|
protected static String |
DEFAULT_DOWNLOAD_DIR
Class constant holding a default location for downloading into.
|
protected static String |
DEFAULT_LOAD_FILENAME
Class constant holding a default filename to download into.
|
protected String |
dirForDownload_
Classvar holding the directory to download into.
|
protected Drive |
drive_
Class Drive API client.
|
protected com.google.api.client.http.HttpTransport |
httpTransport_
Class instance of the HTTP transport.
|
protected com.google.api.client.json.JsonFactory |
jsonFactory_
Class instance of the JSON factory.
|
protected File |
loadFile_ |
protected String |
loadFilePath_
Classvar holding the GDrive logine secrets specific to your login ID
|
static String |
SYSTEM_FILE_SEPERATOR
A holder for this clients System File Separator.
|
static String |
SYSTEM_LINE_SEPERATOR
A holder for this clients System line termination separator.
|
static String |
USERDIR
The users pwd ditrectory.
|
static String |
USERHOME
The users home ditrectory.
|
Constructor and Description |
---|
GDriver()
Default constructor that gets all the basic class settimgs setup and gives you a class instance to do the work.
|
GDriver(String filenameToLoad)
Constructor that gets all the basic class settimgs setup, setsup the filename to upload and gives you a class instance to do the work.
|
Modifier and Type | Method and Description |
---|---|
protected com.google.api.client.auth.oauth2.Credential |
authorize()
Authorizes the installed application to access user's protected data.
|
static long |
bzip2It(File fo)
Wrapper method to accept a dir or individual file in the passed in File
object AND then calls the method that writes the passed file/dir to this
MultiZip instances zip output stream.
|
private void |
downloadFile(boolean useDirectDownload,
File fileToDownload)
Downloads a file using either resumable or direct media download.
|
static void |
ensureFolderExists(File folder)
recursively creates parent dirs and the requested dir
|
protected String |
getloadFilePath()
get the filename path for the file that will be uploaded.
|
protected void |
initDrive(com.google.api.client.auth.oauth2.Credential cred)
Initializes, with the passed in credentials, the Drive class instance -drive_, that gets used for the target upload.
|
protected com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets |
initSecrets()
Loads the Google secrets / api usage authentication properties for this class.
|
protected void |
setloadFilePath(String path)
Set the filename path for the file that will be uploaded.
|
static long |
unBzip2It(File fo)
UnBzips the passed file (that must have a '.bz2' extension) to its same filename
in the same dir without the '.bz2' extension.
|
private File |
updateFileWithTestSuffix(String id)
Updates the name of the uploaded file to have a "drivetest-" prefix.
|
protected File |
uploadFile(boolean useDirectUpload)
Uploads a file using either resumable or direct media upload.
|
public static final String SYSTEM_FILE_SEPERATOR
public static final String SYSTEM_LINE_SEPERATOR
protected static final String APPLICATION_NAME
protected static final String DEFAULT_DOWNLOAD_DIR
protected static final String DEFAULT_LOAD_FILENAME
protected static final String DEFAULT_DATASTORE_DIR
protected static com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets clientSecrets_
protected String loadFilePath_
protected String dirForDownload_
protected File dataStoreDir_
protected com.google.api.client.util.store.FileDataStoreFactory dataStoreFactory_
DataStoreFactory
. The best practice is to make it a single
globally shared instance across your application.protected com.google.api.client.http.HttpTransport httpTransport_
protected com.google.api.client.json.JsonFactory jsonFactory_
public GDriver() throws GeneralSecurityException, IOException
GDriver instance = new GDriveCrypter(); // uses the DEFAULT_LOAD_FILENAME //Authorize GDrive instance.initDrive(instance.authorize()); // Encrypt String encryptedFilename = instance.encrypt(instance.getloadFilePath()); if (encryptedFilename!=null && !encryptedFilename.equals("")) { // Send File to GDrive instance.setloadFilePath(encryptedFilename); File uploadedFile = instance.uploadFile(false); }
GeneralSecurityException
IOException
public GDriver(String filenameToLoad) throws GeneralSecurityException, IOException
String fileNameToUpload = "someFile.txt"; GDriveCrypter instance = new GDriveCrypter(fileNameToUpload); //Authorize GDrive instance.initDrive(instance.authorize()); // Encrypt String encryptedFilename = instance.encrypt(instance.getloadFilePath()); if (encryptedFilename!=null && !encryptedFilename.equals("")) { // Send File to GDrive instance.setloadFilePath(encryptedFilename); File uploadedFile = instance.uploadFile(false); }
GeneralSecurityException
IOException
protected void setloadFilePath(String path)
protected String getloadFilePath()
protected void initDrive(com.google.api.client.auth.oauth2.Credential cred)
cred
- is the Credential to use for the upload.protected com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets initSecrets() throws IOException
IOException
protected com.google.api.client.auth.oauth2.Credential authorize() throws Exception
Exception
public static void ensureFolderExists(File folder)
public static long unBzip2It(File fo)
fo
- The File object to unzip - must have a '.bz2' extension.public static long bzip2It(File fo)
fo
- The File object to zip up (can be an actual file or dir).protected File uploadFile(boolean useDirectUpload) throws IOException
IOException
private File updateFileWithTestSuffix(String id) throws IOException
IOException
private void downloadFile(boolean useDirectDownload, File fileToDownload) throws IOException
IOException
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses