public InputStream downloadFile(SyncItem syncItem) { Drive drive = driveFactory.getDrive(this.credential); try { File remoteFile = syncItem.getRemoteFile().get(); GenericUrl genericUrl = null; if(isGoogleAppsDocumentforExport(remoteFile)){ Optional<String> exportMimeType = supportedGooglMimeType.get(remoteFile.getMimeType()); Export export = drive.files().export(remoteFile.getId(), exportMimeType.get()); genericUrl = export.buildHttpRequestUrl(); }else{ genericUrl = drive.files().get(remoteFile.getId()).set("alt", "media").buildHttpRequestUrl(); } if (genericUrl != null) { HttpRequest httpRequest = drive.getRequestFactory().buildGetRequest(genericUrl); LOGGER.log(Level.FINE, "Downloading file " + remoteFile.getId() + "."); if (!options.isDryRun()) { HttpResponse httpResponse = executeWithRetry(options, () -> httpRequest.execute()); return httpResponse.getContent(); } } else { LOGGER.log(Level.SEVERE, "No download URL for file " + remoteFile); } } catch (Exception e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to download file: " + e.getMessage(), e); } return new ByteArrayInputStream(new byte[0]); }