InputStream is = get.executeMediaAsInputStream()) { IOUtils.copyLarge(is, os); } catch (IOException e) {
return getObject.executeMediaAsInputStream(); } catch (GoogleJsonResponseException e) { System.out.println("Error downloading: " + e.getContent());
public InputStream download(Artifact artifact) throws IOException { String reference = artifact.getReference(); Long generation = null; if (reference.startsWith("gs://")) { reference = reference.substring("gs://".length()); } int slash = reference.indexOf("/"); if (slash <= 0) { throw new IllegalArgumentException("GCS references must be of the format gs://<bucket>/<file-path>, got: " + artifact); } String bucketName = reference.substring(0, slash); String path = reference.substring(slash + 1); int pound = path.lastIndexOf("#"); if (pound >= 0) { generation = Long.valueOf(path.substring(pound + 1)); path = path.substring(0, pound); } Storage.Objects.Get get = storage.objects() .get(bucketName, path) .setGeneration(generation); return get.executeMediaAsInputStream(); } }
public InputStream openObjectStream(String bucketName, String path) throws IOException { Storage.Objects.Get get = storage_.objects().get(bucketName, path); return get.executeMediaAsInputStream(); }
@Override public boolean load(BuildCacheKey buildCacheKey, BuildCacheEntryReader buildCacheEntryReader) throws BuildCacheException { final String bucketPath = getBucketPath(buildCacheKey); try (InputStream is = storage.objects().get(bucketName, bucketPath).executeMediaAsInputStream()) { buildCacheEntryReader.readFrom(is); return true; } catch (IOException e) { logger.info("Did not find cache item '{}' in GCS bucket", bucketPath); return false; } }
/** * Retrieve the whole file (to memory). * * @throws IOException */ public InputStream getWholeObject(String bucket, String fname) throws IOException { Storage.Objects.Get getObject = storage.objects().get(bucket, fname); return getObject.executeMediaAsInputStream(); }
/** * Retrieve the whole file (to memory). * * @throws IOException */ public InputStream getWholeObject(String bucket, String fname) throws IOException { Storage.Objects.Get getObject = storage.objects().get(bucket, fname); return getObject.executeMediaAsInputStream(); }
public static InputStream download(Storage storage, String bucketName, String objectName) throws IOException { Storage.Objects.Get getObject = storage.objects().get(bucketName, objectName); getObject.getMediaHttpDownloader().setDirectDownloadEnabled(!IS_APP_ENGINE); return getObject.executeMediaAsInputStream(); }
public InputStream get(final String bucket, final String path, long start) throws IOException { final Get get = storage.objects().get(bucket, path); if (start > 0) { get.getMediaHttpDownloader().setBytesDownloaded(start); } get.getMediaHttpDownloader().setDirectDownloadEnabled(false); return get.executeMediaAsInputStream(); }