use of com.google.api.client.http.GenericUrl in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method downloadFile.
/**
* Download all owner files
*
* @param path
* Path where download files
*/
public java.io.File downloadFile(String path, File file, String format) {
if (file == null)
return null;
String mimetype = "";
if (com.localidata.generic.Constants.CSV.equals(format))
mimetype = "text/csv";
else if (com.localidata.generic.Constants.XLSX.equals(format)) {
mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
try {
String downloadUrl = file.getExportLinks().get(mimetype);
HttpResponse resp = drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
InputStream input = resp.getContent();
java.io.File f = null;
if (Utils.v(path)) {
f = new java.io.File(path + java.io.File.separator + file.getTitle() + "." + format);
} else {
f = new java.io.File(file.getTitle() + "." + format);
}
FileUtils.copyInputStreamToFile(input, f);
return f;
} catch (Exception e) {
log.error("Error decargando fichero en google drive", e);
}
return null;
}
use of com.google.api.client.http.GenericUrl in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method downloadFilesAfterDate.
/**
* Download files after a date
*
* @param path
* Path where download files
* @param stringDateLastChange
* String with a date
*/
public void downloadFilesAfterDate(String path, String stringDateLastChange) {
List<File> files = listOwnerFilesAfterDate(stringDateLastChange);
for (File file : files) {
try {
String downloadUrl = file.getExportLinks().get("text/csv");
HttpResponse resp = drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
InputStream input = resp.getContent();
java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + ".csv");
FileUtils.copyInputStreamToFile(input, f);
} catch (Exception e) {
log.error("Error decargando ficheros despues de una fecha en google drive", e);
}
}
}
use of com.google.api.client.http.GenericUrl in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method download.
private void download(String path, File file) throws IOException {
if (file.getShared()) {
String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
HttpResponse resp = drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
InputStream input = resp.getContent();
java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + "." + Prop.formatConfig);
FileUtils.copyInputStreamToFile(input, f);
}
}
Aggregations