setEncryptionHeaders(requestHeaders, ENCRYPTION_KEY_PREFIX, options); ByteArrayOutputStream output = new ByteArrayOutputStream(bytes); HttpResponse httpResponse = req.executeMedia();
@Override public byte[] load(StorageObject from, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LOAD); Scope scope = tracer.withSpan(span); try { Storage.Objects.Get getRequest = 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)); setEncryptionHeaders(getRequest.getRequestHeaders(), ENCRYPTION_KEY_PREFIX, options); ByteArrayOutputStream out = new ByteArrayOutputStream(); getRequest.executeMedia().download(out); return out.toByteArray(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
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());
HttpResponse response; try { response = getObject.executeMedia(); response = getObject.executeMedia();
setEncryptionHeaders(requestHeaders, ENCRYPTION_KEY_PREFIX, options); ByteArrayOutputStream output = new ByteArrayOutputStream(bytes); HttpResponse httpResponse = req.executeMedia();
HttpResponse response; try { response = get.executeMedia(); } catch (IOException e) { String msg = String.format("Error reading %s at position %d",
HttpResponse response; try { response = get.executeMedia(); } catch (IOException e) { String msg = String.format("Error reading %s at position %d",
getObject.setGeneration(null); try { return getObject.executeMedia(); } catch (IOException e1) { return handleExecuteMediaException(e1, getObject, /* retryWithLiveVersion= */ false);
@Override public byte[] load(StorageObject from, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LOAD); Scope scope = tracer.withSpan(span); try { Storage.Objects.Get getRequest = 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)); setEncryptionHeaders(getRequest.getRequestHeaders(), ENCRYPTION_KEY_PREFIX, options); ByteArrayOutputStream out = new ByteArrayOutputStream(); getRequest.executeMedia().download(out); return out.toByteArray(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, long position, int bytes) { try { Get req = storage.objects() .get(from.getBucket(), from.getName()) .setGeneration(from.getGeneration()) .setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options)) .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options)) .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options)); StringBuilder range = new StringBuilder(); range.append("bytes=").append(position).append("-").append(position + bytes - 1); req.getRequestHeaders().setRange(range.toString()); ByteArrayOutputStream output = new ByteArrayOutputStream(); req.executeMedia().download(output); String etag = req.getLastResponseHeaders().getETag(); return Tuple.of(etag, output.toByteArray()); } catch (IOException ex) { StorageException serviceException = translate(ex); if (serviceException.code() == SC_REQUESTED_RANGE_NOT_SATISFIABLE) { return Tuple.of(null, new byte[0]); } throw serviceException; } }