private static void addContentMetdataFromHttpRequest( BlobBuilder.PayloadBlobBuilder builder, HttpServletRequest request) { ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) { userMetadata.put( headerName.substring(USER_METADATA_PREFIX.length()), Strings.nullToEmpty(request.getHeader(headerName))); } } builder.cacheControl(request.getHeader( HttpHeaders.CACHE_CONTROL)) .contentDisposition(request.getHeader( HttpHeaders.CONTENT_DISPOSITION)) .contentEncoding(request.getHeader( HttpHeaders.CONTENT_ENCODING)) .contentLanguage(request.getHeader( HttpHeaders.CONTENT_LANGUAGE)) .userMetadata(userMetadata.build()); String contentType = request.getContentType(); if (contentType != null) { builder.contentType(contentType); } long expires = request.getDateHeader(HttpHeaders.EXPIRES); if (expires != -1) { builder.expires(new Date(expires)); } }
private static void addContentMetdataFromHttpRequest( BlobBuilder.PayloadBlobBuilder builder, HttpServletRequest request) { ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) { userMetadata.put( headerName.substring(USER_METADATA_PREFIX.length()), Strings.nullToEmpty(request.getHeader(headerName))); } } builder.cacheControl(request.getHeader( HttpHeaders.CACHE_CONTROL)) .contentDisposition(request.getHeader( HttpHeaders.CONTENT_DISPOSITION)) .contentEncoding(request.getHeader( HttpHeaders.CONTENT_ENCODING)) .contentLanguage(request.getHeader( HttpHeaders.CONTENT_LANGUAGE)) .userMetadata(userMetadata.build()); String contentType = request.getContentType(); if (contentType != null) { builder.contentType(contentType); } long expires = request.getDateHeader(HttpHeaders.EXPIRES); if (expires != -1) { builder.expires(new Date(expires)); } }
private static void addContentMetdataFromHttpRequest( BlobBuilder.PayloadBlobBuilder builder, HttpServletRequest request) { ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) { userMetadata.put( headerName.substring(USER_METADATA_PREFIX.length()), Strings.nullToEmpty(request.getHeader(headerName))); } } builder.cacheControl(request.getHeader( HttpHeaders.CACHE_CONTROL)) .contentDisposition(request.getHeader( HttpHeaders.CONTENT_DISPOSITION)) .contentEncoding(request.getHeader( HttpHeaders.CONTENT_ENCODING)) .contentLanguage(request.getHeader( HttpHeaders.CONTENT_LANGUAGE)) .userMetadata(userMetadata.build()); String contentType = request.getContentType(); if (contentType != null) { builder.contentType(contentType); } long expires = request.getDateHeader(HttpHeaders.EXPIRES); if (expires != -1) { builder.expires(new Date(expires)); } }
builder.userMetadata(userMetadata); } else { builder.userMetadata(blob.getMetadata().getUserMetadata());
builder.userMetadata(userMetadata); } else { builder.userMetadata(blob.getMetadata().getUserMetadata());
builder.userMetadata(userMetadata); } else { builder.userMetadata(blob.getMetadata().getUserMetadata());
builder.userMetadata(userMetadata); } else { builder.userMetadata(blob.getMetadata().getUserMetadata());
builder.userMetadata(userMetadata); } else { builder.userMetadata(blob.getMetadata().getUserMetadata());
builder.userMetadata(userMetadata); } else { builder.userMetadata(blob.getMetadata().getUserMetadata());
+ "-" + System.currentTimeMillis()) .payload(Long.toString(System.currentTimeMillis())).contentType(MediaType.APPLICATION_OCTET_STREAM) .userMetadata(md).build(); this.writeBlob(b, false); } catch (Exception e) {
.contentType(MediaType.APPLICATION_OCTET_STREAM).userMetadata(md).build();
.contentLength(payload.size()); addContentMetadata(blobBuilder); blobBuilder.userMetadata(userMetadata); Blob blob = blobBuilder.build();
@Test(dataProvider = "ignoreOnMacOSX") public void testOverwriteBlobMetadata() throws Exception { String blobKey = TestUtils.createRandomBlobKey("writePayload-", ".img"); // write blob Blob blob = new BlobBuilderImpl() .name(blobKey) .payload(randomByteSource().slice(0, 1024)) .userMetadata(ImmutableMap.of("key1", "value1")) .build(); storageStrategy.putBlob(CONTAINER_NAME, blob); blob = storageStrategy.getBlob(CONTAINER_NAME, blobKey); assertEquals(blob.getMetadata().getUserMetadata().get("key1"), "value1"); // overwrite blob blob = new BlobBuilderImpl() .name(blobKey) .payload(randomByteSource().slice(0, 1024)) // no metadata .build(); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); storageStrategy.putBlob(CONTAINER_NAME, blob); blob = storageStrategy.getBlob(CONTAINER_NAME, blobKey); assertFalse(blob.getMetadata().getUserMetadata().containsKey("key1")); }
@Override public void addFile(FileEntry fileEntry, InputStream fileStream) throws FileStorageException { String entryName = fileEntry.getId(); long fileSize = fileEntry.getSize() .longValue(); Blob blob = blobStore.blobBuilder(entryName) .payload(fileStream) .contentDisposition(fileEntry.getName()) .contentType(MediaType.OCTET_STREAM.toString()) .contentLength(fileSize) .userMetadata(createFileEntryMetadata(fileEntry)) .build(); try { putBlobWithRetries(blob, 3); LOGGER.debug(MessageFormat.format(Messages.STORED_FILE_0_WITH_SIZE_1_SUCCESSFULLY_2, fileEntry.getId(), fileSize)); } catch (ContainerNotFoundException e) { throw new FileStorageException( MessageFormat.format(Messages.FILE_UPLOAD_FAILED, fileEntry.getName(), fileEntry.getNamespace())); } }
@Test(groups = "live") public void testPutBlobWithMd5() throws IOException, InterruptedException { String containerName = getContainerName(); String blobName = "md5test"; try { long contentLength = 32 * 1024L; ByteSource byteSource = TestUtils.randomByteSource().slice(0, contentLength); ByteSourcePayload payload = Payloads.newByteSourcePayload(byteSource); PayloadEnclosingImpl payloadImpl = new PayloadEnclosingImpl(payload); BlobStore blobStore = view.getBlobStore(); // This would trigger server side validation of md5 HashCode hcMd5 = byteSource.hash(Hashing.md5()); Blob blob = blobStore.blobBuilder(blobName).payload(payloadImpl.getPayload()).contentType("image/jpeg") .contentLength(contentLength).contentLanguage("en").contentDisposition("attachment") .contentMD5(hcMd5).userMetadata(ImmutableMap.of("Adrian", "powderpuff")).build(); blobStore.putBlob(containerName, blob); checkMD5(containerName, blobName, hcMd5.asBytes()); } finally { returnContainer(containerName); } } }
/** * Uploads the block to the cloud service. */ @Override protected void storeBlock(byte[] digest, int level, byte[] data) throws IOException { Preconditions.checkNotNull(context); String id = StringUtils.convertBytesToHex(digest); cache.put(id, data); org.jclouds.blobstore.BlobStore blobStore = context.getBlobStore(); if (!blobStore.blobExists(cloudContainer, id)) { Map<String, String> metadata = Maps.newHashMap(); metadata.put("level", String.valueOf(level)); Blob blob = blobStore.blobBuilder(id) .payload(data) .userMetadata(metadata) .build(); String etag = blobStore.putBlob(cloudContainer, blob, multipart()); LOG.debug("Blob " + id + " created with cloud tag : " + etag); } else { LOG.debug("Blob " + id + " already exists"); } }
/** * Uploads the block to the cloud service. */ @Override protected void storeBlock(byte[] digest, int level, byte[] data) throws IOException { Preconditions.checkNotNull(context); String id = StringUtils.convertBytesToHex(digest); cache.put(id, data); org.jclouds.blobstore.BlobStore blobStore = context.getBlobStore(); if (!blobStore.blobExists(cloudContainer, id)) { Map<String, String> metadata = Maps.newHashMap(); metadata.put("level", String.valueOf(level)); Blob blob = blobStore.blobBuilder(id) .payload(data) .userMetadata(metadata) .build(); String etag = blobStore.putBlob(cloudContainer, blob, multipart()); LOG.debug("Blob " + id + " created with cloud tag : " + etag); } else { LOG.debug("Blob " + id + " already exists"); } }
/** * Uploads the block to the cloud service. */ @Override protected void storeBlock(byte[] digest, int level, byte[] data) throws IOException { Preconditions.checkNotNull(context); String id = StringUtils.convertBytesToHex(digest); cache.put(id, data); org.jclouds.blobstore.BlobStore blobStore = context.getBlobStore(); if (!blobStore.blobExists(cloudContainer, id)) { Map<String, String> metadata = Maps.newHashMap(); metadata.put("level", String.valueOf(level)); Blob blob = blobStore.blobBuilder(id) .payload(data) .userMetadata(metadata) .build(); String etag = blobStore.putBlob(cloudContainer, blob, multipart()); LOG.debug("Blob " + id + " created with cloud tag : " + etag); } else { LOG.debug("Blob " + id + " already exists"); } }
@Override public void updateBucketInfo(Map<String, String> md) throws IOException { try { String lbi = "bucketinfo/" + EncyptUtils.encHashArchiveName(Main.DSEID, Main.chunkStoreEncryptionEnabled); try { this.updateObject(lbi, md); } catch (Exception e) { Blob b = blobStore .blobBuilder("bucketinfo/" + EncyptUtils.encHashArchiveName(Main.DSEID, Main.chunkStoreEncryptionEnabled)) .payload(Long.toString(System.currentTimeMillis())) .contentType(MediaType.APPLICATION_OCTET_STREAM).userMetadata(md).build(); this.writeBlob(b, false); } // this.resetCurrentSize(); } catch (Exception e) { SDFSLogger.getLog().error("unable to update size", e); } }
public void putBlobWithMetadata(ObjectHandle handle, byte[] bytes, Map<String, String> userMetadata) throws UnknownContainerException { BlobStoreContext blobStoreContext = blobStoreContextFactory.alocate(); try { BlobStore blobStore = blobStoreContext.getBlobStore(); Blob blob = blobStore.blobBuilder(handle.getName()) .payload(bytes) .userMetadata(userMetadata) .build(); blobStore.putBlob(handle.getContainer(), blob); } catch (ContainerNotFoundException ex) { throw new UnknownContainerException(handle.getContainer()); } finally { blobStoreContextFactory.dispose(blobStoreContext); } }