org.jclouds.blobstore.options.GetOptions Java Examples
The following examples show how to use
org.jclouds.blobstore.options.GetOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AliOSSBlobStore.java From multiapps-controller with Apache License 2.0 | 6 votes |
private GetObjectRequest toGetObjectRequest(String container, String name, GetOptions options) { GetObjectRequest request = new GetObjectRequest(container, name); if (options.getIfModifiedSince() != null) { request.setModifiedSinceConstraint(options.getIfModifiedSince()); } if (!options.getRanges() .isEmpty()) { String[] ranges = options.getRanges() .get(0) .split("-"); long start = Integer.parseInt(ranges[0]); long end = Integer.parseInt(ranges[1]); request.setRange(start, end); } return request; }
Example #2
Source File: NullBlobStore.java From s3proxy with Apache License 2.0 | 6 votes |
@Override @Nullable public Blob getBlob(String container, String name, GetOptions options) { Blob blob = super.getBlob(container, name, options); if (blob == null) { return null; } byte[] array; try (InputStream is = blob.getPayload().openStream()) { array = ByteStreams.toByteArray(is); } catch (IOException ioe) { throw new RuntimeException(ioe); } long length = Longs.fromByteArray(array); ByteSourcePayload payload = new ByteSourcePayload( new NullByteSource().slice(0, length)); payload.setContentMetadata(blob.getPayload().getContentMetadata()); payload.getContentMetadata().setContentLength(length); payload.getContentMetadata().setContentMD5((HashCode) null); blob.setPayload(payload); blob.getMetadata().setSize(length); return blob; }
Example #3
Source File: AliOSSBlobStore.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Override public Blob getBlob(String container, String name, GetOptions options) { return doOssOperation(oss -> { GetObjectRequest req = toGetObjectRequest(container, name, options); OSSObject object = oss.getObject(req); return convertToBlob(object); }, false); }
Example #4
Source File: BlobStoreBackedInputStreamImpl.java From pulsar with Apache License 2.0 | 5 votes |
/** * Refill the buffered input if it is empty. * @return true if there are bytes to read, false otherwise */ private boolean refillBufferIfNeeded() throws IOException { if (buffer.readableBytes() == 0) { if (cursor >= objectLen) { return false; } long startRange = cursor; long endRange = Math.min(cursor + bufferSize - 1, objectLen - 1); try { Blob blob = blobStore.getBlob(bucket, key, new GetOptions().range(startRange, endRange)); versionCheck.check(key, blob); try (InputStream stream = blob.getPayload().openStream()) { buffer.clear(); bufferOffsetStart = startRange; bufferOffsetEnd = endRange; long bytesRead = endRange - startRange + 1; int bytesToCopy = (int) bytesRead; while (bytesToCopy > 0) { bytesToCopy -= buffer.writeBytes(stream, bytesToCopy); } cursor += buffer.readableBytes(); } } catch (Throwable e) { throw new IOException("Error reading from BlobStore", e); } } return true; }
Example #5
Source File: S3ProxyHandler.java From s3proxy with Apache License 2.0 | 4 votes |
private void handleGetBlob(HttpServletRequest request, HttpServletResponse response, BlobStore blobStore, String containerName, String blobName) throws IOException, S3Exception { int status = HttpServletResponse.SC_OK; GetOptions options = new GetOptions(); String ifMatch = request.getHeader(HttpHeaders.IF_MATCH); if (ifMatch != null) { options.ifETagMatches(ifMatch); } String ifNoneMatch = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (ifNoneMatch != null) { options.ifETagDoesntMatch(ifNoneMatch); } long ifModifiedSince = request.getDateHeader( HttpHeaders.IF_MODIFIED_SINCE); if (ifModifiedSince != -1) { options.ifModifiedSince(new Date(ifModifiedSince)); } long ifUnmodifiedSince = request.getDateHeader( HttpHeaders.IF_UNMODIFIED_SINCE); if (ifUnmodifiedSince != -1) { options.ifUnmodifiedSince(new Date(ifUnmodifiedSince)); } String range = request.getHeader(HttpHeaders.RANGE); if (range != null && range.startsWith("bytes=") && // ignore multiple ranges range.indexOf(',') == -1) { range = range.substring("bytes=".length()); String[] ranges = range.split("-", 2); if (ranges[0].isEmpty()) { options.tail(Long.parseLong(ranges[1])); } else if (ranges[1].isEmpty()) { options.startAt(Long.parseLong(ranges[0])); } else { options.range(Long.parseLong(ranges[0]), Long.parseLong(ranges[1])); } status = HttpServletResponse.SC_PARTIAL_CONTENT; } Blob blob = blobStore.getBlob(containerName, blobName, options); if (blob == null) { throw new S3Exception(S3ErrorCode.NO_SUCH_KEY); } response.setStatus(status); String corsOrigin = request.getHeader(HttpHeaders.ORIGIN); if (!Strings.isNullOrEmpty(corsOrigin) && corsRules.isOriginAllowed(corsOrigin)) { response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, corsOrigin); response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET"); } addMetadataToResponse(request, response, blob.getMetadata()); // TODO: handles only a single range due to jclouds limitations Collection<String> contentRanges = blob.getAllHeaders().get(HttpHeaders.CONTENT_RANGE); if (!contentRanges.isEmpty()) { response.addHeader(HttpHeaders.CONTENT_RANGE, contentRanges.iterator().next()); response.addHeader(HttpHeaders.ACCEPT_RANGES, "bytes"); } try (InputStream is = blob.getPayload().openStream(); OutputStream os = response.getOutputStream()) { ByteStreams.copy(is, os); os.flush(); } }
Example #6
Source File: NullBlobStore.java From s3proxy with Apache License 2.0 | 4 votes |
@Override @Nullable public Blob getBlob(String container, String name) { return getBlob(container, name, GetOptions.NONE); }