Refine search
get = constructObjectResourceHandle().get(this.srcBucketName, remotePath.toString()); } catch (IOException e) { throw new BackupRestoreException( get.getMediaHttpDownloader().setDirectDownloadEnabled(true); try (OutputStream os = new FileOutputStream(localPath.toFile()); InputStream is = get.executeMediaAsInputStream()) { IOUtils.copyLarge(is, os); } catch (IOException e) { backupMetrics.recordDownloadRate(get.getLastResponseHeaders().getContentLength());
@Override public StorageObject get(StorageObject object, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_OBJECT); Scope scope = tracer.withSpan(span); try { return getCall(object, options).execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); StorageException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } finally { scope.close(); span.end(); } }
private Get createDataRequest(String rangeHeader) throws IOException { Get getObject = createRequest(); getObject.setGeneration(generation); // Set the headers on the existing request headers that may have // been initialized with things like user-agent already. HttpHeaders requestHeaders = clientRequestHelper.getRequestHeaders(getObject); // Disable GCS decompressive transcoding. requestHeaders.setAcceptEncoding("gzip"); requestHeaders.setRange(rangeHeader); return getObject; }
@Override public StorageObject get(StorageObject object, Map<Option, ?> options) { try { return getRequest(object, options).execute(); } catch (IOException ex) { StorageException serviceException = translate(ex); if (serviceException.code() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
private static void checkGcsUrlExists(String url) throws IOException { // Ensure data is accessible. // If we can read the size, then surely we can read the file. GcsPath fn = GcsPath.fromUri(url); Storage.Objects storageClient = GCSOptions.Methods.createStorageClient(pipelineOptions, auth); Storage.Objects.Get getter = storageClient.get(fn.getBucket(), fn.getObject()); StorageObject object = getter.execute(); BigInteger size = object.getSize(); }
Storage.Objects.Get getObject = storage.objects().get("bucket", "object"); OutputStream out = new FileOutputStream("/tmp/object"); // If you're not in AppEngine, download the whole thing in one request, if possible. getObject.getMediaHttpDownloader().setDirectDownloadEnabled(true); getObject.executeMediaAndDownloadTo(out);
private static boolean GCSURLExists(String url) { // ensure data is accessible try { // if we can read the size, then surely we can read the file GcsPath fn = GcsPath.fromUri(url); Storage.Objects storageClient = GCSOptions.Methods.createStorageClient(pipelineOptions, auth); Storage.Objects.Get getter = storageClient.get(fn.getBucket(), fn.getObject()); StorageObject object = getter.execute(); BigInteger size = object.getSize(); return true; } catch (Exception x) { return false; } }
private static boolean GCSURLExists(String url) { // ensure data is accessible try { // if we can read the size, then surely we can read the file GcsPath fn = GcsPath.fromUri(url); Storage.Objects storageClient = GCSOptions.Methods.createStorageClient(pipelineOptions, auth); Storage.Objects.Get getter = storageClient.get(fn.getBucket(), fn.getObject()); StorageObject object = getter.execute(); BigInteger size = object.getSize(); return true; } catch (Exception x) { return false; } }
Storage.Objects.Get get = storage.objects().get(BUCKET_NAME_APP_DATA, fileName); HttpResponse httpResponse = get.executeMedia(); String x_goog_hash = httpResponse.getHeaders().get("x-goog-hash").toString().replaceAll("\\s+",""); if (TextUtils.isEmpty(x_goog_hash)) throw new IOException("Response x-goog-hash was null"); final int start = x_goog_hash.indexOf("md5="); final int end = x_goog_hash.indexOf("==", start); if (start == -1 || end == -1 || end <= start) throw new IOException("Response x-goog-hash of unexpected type " + x_goog_hash); serverHash = x_goog_hash.substring(start + 4, end + 2); if (TextUtils.isEmpty(serverHash)) throw new IOException("Response md5 was null"); Log.i("Ayush", "Md5 hash = ? " + serverHash); bufferedInputStream = new BufferedInputStream(httpResponse.getContent());
Storage.Objects.Get getObject = client.objects().get(bucketName, objectname); StorageObject object = getObject.execute(); System.out.println("Size is: " + object.getSize().longValue());
Storage.Objects.Get getObject = client.objects().get(bucketName, objectname); getObject.getMediaHttpDownloader().setDirectDownloadEnabled(true); getObject.executeMediaAndDownloadTo(System.out);
@Override public StorageObject get(StorageObject object, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_OBJECT); Scope scope = tracer.withSpan(span); try { return getCall(object, options).execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); StorageException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } finally { scope.close(); span.end(); } }
generation = null; footerContent = null; getObject.setGeneration(null); try { return getObject.executeMedia(); } catch (IOException e1) { return handleExecuteMediaException(e1, getObject, /* retryWithLiveVersion= */ false);
get.getRequestHeaders() .setRange(String.format("bytes=%d-", position)); HttpResponse response; try { response = get.executeMedia(); } catch (IOException e) { String msg = String.format("Error reading %s at position %d",
get.getRequestHeaders() .setRange(String.format("bytes=%d-", position)); HttpResponse response; try { response = get.executeMedia(); } catch (IOException e) { String msg = String.format("Error reading %s at position %d",
HttpResponse response; try { response = getObject.executeMedia(); response = getObject.executeMedia();
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(); }
Get req = storage .objects() .get(from.getBucket(), from.getName()) .setGeneration(from.getGeneration()) .setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(options)) .setIfGenerationMatch(Option.IF_GENERATION_MATCH.getLong(options)) .setIfGenerationNotMatch(Option.IF_GENERATION_NOT_MATCH.getLong(options)) .setUserProject(Option.USER_PROJECT.getString(options)); checkArgument(position >= 0, "Position should be non-negative, is %d", position); StringBuilder range = new StringBuilder(); range.append("bytes=").append(position).append("-").append(position + bytes - 1); HttpHeaders requestHeaders = req.getRequestHeaders(); requestHeaders.setRange(range.toString()); setEncryptionHeaders(requestHeaders, ENCRYPTION_KEY_PREFIX, options); ByteArrayOutputStream output = new ByteArrayOutputStream(bytes); HttpResponse httpResponse = req.executeMedia(); httpResponse.download(output); String etag = req.getLastResponseHeaders().getETag(); return Tuple.of(etag, output.toByteArray()); } catch (IOException ex) {