.payload(payload); addContentMetdataFromHttpRequest(builder, request); builder.contentLength(payload.size());
.blobBuilder(blobName) .payload(is) .contentLength(contentLength);
public synchronized void putIfAbsent(File file) throws FileNotFoundException { allocateContainer(); BlobStore store = context.getBlobStore(); if (!store.blobExists(container, file.getName())) { LOG.info("Uploading '{}' to '{}' blob cache.", file.getName(), container); Blob blob = context.getBlobStore().blobBuilder(container) .name(file.getName()) .payload(file) .contentLength(file.length()) .build(); store.putBlob(container, blob, multipart()); } }
@Test public void testGetBlobTrailingSlash() throws Exception { String key = "key"; ByteSource byteSource = randomByteSource().slice(0, 1024); Blob blob = new BlobBuilderImpl() .name(key) .payload(byteSource) .contentLength(byteSource.size()) .build(); storageStrategy.putBlob(CONTAINER_NAME, blob); blob = storageStrategy.getBlob(CONTAINER_NAME, key); assertThat(blob).isNotNull(); blob = storageStrategy.getBlob(CONTAINER_NAME, key + "/"); assertThat(blob).isNull(); }
@Test public void testPutBlobTrailingSlash() throws Exception { String key = "key"; ByteSource byteSource = ByteSource.empty(); Blob blob = new BlobBuilderImpl() .name(key + "/") .payload(byteSource) .contentLength(byteSource.size()) .build(); storageStrategy.putBlob(CONTAINER_NAME, blob); blob = storageStrategy.getBlob(CONTAINER_NAME, key); assertThat(blob).isNull(); blob = storageStrategy.getBlob(CONTAINER_NAME, key + "/"); assertThat(blob).isNotNull(); }
@Test(dataProvider = "getBlobsToEscape", groups = {"integration", "live"}) public void testBlobNameEscaping(Set<String> blobNames) throws InterruptedException { final String containerName = getContainerName(); BlobStore blobStore = view.getBlobStore(); try { for (String name : blobNames) { Blob blob = blobStore.blobBuilder(name).payload(ByteSource.wrap("test".getBytes())).contentLength(4) .build(); blobStore.putBlob(containerName, blob); } checkEqualNames(blobNames, blobStore.list(containerName)); } finally { returnContainer(containerName); } }
@Override public Void call() throws Exception { Payload payload = Payloads.newByteSourcePayload(expected); payload.getContentMetadata().setContentType("image/png"); Blob blob = view.getBlobStore().blobBuilder(name).payload(payload).contentLength(expected.size()).build(); view.getBlobStore().putBlob(container, blob); assertConsistencyAwareBlobExists(container, name); blob = view.getBlobStore().getBlob(container, name); byte[] actual = ByteStreams2.toByteArrayAndClose(blob.getPayload().openStream()); assertThat(actual).isEqualTo(expected.read()); view.getBlobStore().removeBlob(container, name); assertConsistencyAwareBlobDoesntExist(container, name); return null; }
@Test public void testPutIncorrectContentLength() throws Exception { Blob blob = new BlobBuilderImpl() .name("key") .payload(randomByteSource().slice(0, 1024)) .contentLength(512) .build(); try { storageStrategy.putBlob(CONTAINER_NAME, blob); Fail.failBecauseExceptionWasNotThrown(IOException.class); } catch (IOException ioe) { // expected } }
public synchronized void putIfAbsent(File file) throws FileNotFoundException { allocateContainer(); BlobStore store = context.getBlobStore(); if (!store.blobExists(container, file.getName())) { LOG.info("Uploading '{}' to '{}' blob cache.", file.getName(), container); Blob blob = context.getBlobStore().blobBuilder(container) .name(file.getName()) .payload(file) .contentLength(file.length()) .build(); store.putBlob(container, blob, multipart()); } }
private void put(String name, String content) { BlobStore blobStore = context.getBlobStore(); byte[] bytes = content.getBytes(Charsets.UTF_8); Blob blob = blobStore.blobBuilder(name) .payload(ByteSource.wrap(bytes)) .contentLength(bytes.length) .build(); try { blobStore.putBlob(containerName, blob); } catch (Exception e) { LOG.error("PUT " + name + " failed", e); } }
private Blob createBlob( FileResource fileResource, byte[] bytes ) { return blobStore.blobBuilder( fileResource.getStorageKey() ) .payload( bytes ) .contentLength( fileResource.getContentLength() ) .contentMD5( HashCode.fromString( fileResource.getContentMd5() ) ) .contentType( fileResource.getContentType() ) .contentDisposition( "filename=" + fileResource.getName() ) .build(); }
private Blob makeBlob(String blobName, ByteSource payload) throws IOException { return blobStore.blobBuilder(blobName) .payload(payload) .contentLength(payload.size()) .build(); }
protected void addMultipartBlobToContainer(String containerName, String key) throws IOException { ByteSource sourceToUpload = TestUtils.randomByteSource().slice(0, PART_SIZE + 1); BlobStore blobStore = view.getBlobStore(); blobStore.createContainerInLocation(null, containerName); Blob blob = blobStore.blobBuilder(key).payload(sourceToUpload).contentLength(sourceToUpload.size()) .contentType(MediaType.TEXT_PLAIN).build(); blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart()); }
@Test public void testSignPutBlob() throws Exception { HashCode hashCode = HashCode.fromBytes(new byte[16]); BlobStore signPutBlob = requestsSendResponses(init()); Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2L).contentMD5(hashCode) .contentType("text/plain").expires(new Date(1000)).build(); HttpRequest compare = putBlob(); compare.setPayload(blob.getPayload()); assertEquals(signPutBlob.getContext().getSigner().signPutBlob(container, blob), compare); }
private void uploadByteSource(String container, String name, ByteSource byteSource) throws IOException { BlobStore blobStore = view.getBlobStore(); blobStore.putBlob(container, blobStore.blobBuilder(name) .payload(new ByteSourcePayload(byteSource)) .contentType("text/plain") .contentMD5(byteSource.hash(md5())) .contentLength(byteSource.size()) .build()); }
private Blob createBlob( FileResource fileResource, File file ) { return blobStore.blobBuilder( fileResource.getStorageKey() ) .payload( file ) .contentLength( fileResource.getContentLength() ) .contentMD5( HashCode.fromString( fileResource.getContentMd5() ) ) .contentType( fileResource.getContentType() ) .contentDisposition( "filename=" + fileResource.getName() ) .build(); }
@Override public void checkoutFile(String name) throws IOException { name = FilenameUtils.separatorsToUnix(name); String blb = "claims/" + name + "/" + EncyptUtils.encHashArchiveName(Main.DSEID, Main.chunkStoreEncryptionEnabled); Blob b = null; b = blobStore.blobBuilder(blb).payload(B2Bytes).contentLength(B2Bytes.length) .contentType(MediaType.APPLICATION_OCTET_STREAM).build(); this.writeBlob(b, false); }
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { Blob blob = blobFactory.get().name(blobName).forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }) .contentType("text/plain").build(); assertEquals(blob.getPayload().getContentMetadata().getContentMD5(), new byte[] { 0, 2, 4, 8 }); HttpRequest request = signer.signPutBlob(containerName, blob); assertRequestLineEquals(request, "PUT " + fullUrl + " HTTP/1.1"); assertNonPayloadHeadersEqual( request, "Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\nContent-Length: 2\nContent-MD5: AAIECA==\nContent-Type: text/plain\n"); assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, new byte[] { 0, 2, 4, 8 }, null); assertEquals(request.getFilters().size(), 0); }
@Test public void testSignPutBlob() throws Exception { BlobStore signPutBlob = requestsSendResponses(init()); Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }) .contentType("text/plain").expires(new Date(1000)).build(); HttpRequest compare = putBlob(); compare.setPayload(blob.getPayload()); assertEquals(signPutBlob.getContext().getSigner().signPutBlob(container, blob), compare); }
private void uploadConstitution(String container, String name, String contentDisposition) throws IOException { view.getBlobStore().putBlob( container, view.getBlobStore().blobBuilder(name).payload(oneHundredOneConstitutions.getInput()).contentType( "text/plain").contentMD5(oneHundredOneConstitutionsMD5).contentLength( oneHundredOneConstitutionsLength).contentDisposition(contentDisposition).build()); }