@Test(expectedExceptions = IllegalArgumentException.class) public void testNoNameIsBad() { AzureBlob blob = injector.getInstance(AzureBlob.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(5368709120000L); blob.setPayload(payload); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindAzureBlobMetadataToRequest binder = injector.getInstance(BindAzureBlobMetadataToRequest.class); binder.bindToRequest(request, blob); }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AzureBlob, "this binder is only valid for AzureBlobs!"); checkNotNull(request, "request"); AzureBlob blob = AzureBlob.class.cast(input); checkArgument(blob.getPayload().getContentMetadata().getContentLength() != null && blob.getPayload().getContentMetadata().getContentLength() >= 0, "size must be set"); Builder<String, String> headers = ImmutableMap.builder(); String cacheControl = blob.getPayload().getContentMetadata().getCacheControl(); if (cacheControl != null) { headers.put(AzureStorageHeaders.CACHE_CONTROL, cacheControl); } headers.put("x-ms-blob-type", blob.getProperties().getType().toString()); String contentDisposition = blob.getPayload().getContentMetadata().getContentDisposition(); if (contentDisposition != null) { headers.put("x-ms-blob-content-disposition", contentDisposition); } switch (blob.getProperties().getType()) { case PAGE_BLOB: headers.put(HttpHeaders.CONTENT_LENGTH, "0"); headers.put("x-ms-blob-content-length", blob.getPayload().getContentMetadata().getContentLength().toString()); break; case BLOCK_BLOB: checkArgument( checkNotNull(blob.getPayload().getContentMetadata().getContentLength(), "blob.getContentLength()") <= 256L * 1024 * 1024, "maximum size for put Blob is 256MB"); break; } request = (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build(); return blobBinder.bindToRequest(request, azureBlob2Blob.apply(blob)); }
BindAzureBlobMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AzureBlob, "this binder is only valid for AzureBlobs!"); checkNotNull(request, "request"); AzureBlob blob = AzureBlob.class.cast(input); checkArgument(blob.getPayload().getContentMetadata().getContentLength() != null && blob.getPayload().getContentMetadata().getContentLength() >= 0, "size must be set"); Builder<String, String> headers = ImmutableMap.builder(); String cacheControl = blob.getPayload().getContentMetadata().getCacheControl(); if (cacheControl != null) { headers.put(AzureStorageHeaders.CACHE_CONTROL, cacheControl); } headers.put("x-ms-blob-type", blob.getProperties().getType().toString()); String contentDisposition = blob.getPayload().getContentMetadata().getContentDisposition(); if (contentDisposition != null) { headers.put("x-ms-blob-content-disposition", contentDisposition); } switch (blob.getProperties().getType()) { case PAGE_BLOB: headers.put(HttpHeaders.CONTENT_LENGTH, "0"); headers.put("x-ms-blob-content-length", blob.getPayload().getContentMetadata().getContentLength().toString()); break; case BLOCK_BLOB: checkArgument( checkNotNull(blob.getPayload().getContentMetadata().getContentLength(), "blob.getContentLength()") <= 256L * 1024 * 1024, "maximum size for put Blob is 256MB"); break; } request = (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build(); return blobBinder.bindToRequest(request, azureBlob2Blob.apply(blob)); } }
BindAzureBlobMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AzureBlob, "this binder is only valid for AzureBlobs!"); checkNotNull(request, "request"); AzureBlob blob = AzureBlob.class.cast(input); checkArgument(blob.getPayload().getContentMetadata().getContentLength() != null && blob.getPayload().getContentMetadata().getContentLength() >= 0, "size must be set"); Builder<String, String> headers = ImmutableMap.builder(); String cacheControl = blob.getPayload().getContentMetadata().getCacheControl(); if (cacheControl != null) { headers.put(AzureStorageHeaders.CACHE_CONTROL, cacheControl); } headers.put("x-ms-blob-type", blob.getProperties().getType().toString()); String contentDisposition = blob.getPayload().getContentMetadata().getContentDisposition(); if (contentDisposition != null) { headers.put("x-ms-blob-content-disposition", contentDisposition); } switch (blob.getProperties().getType()) { case PAGE_BLOB: headers.put(HttpHeaders.CONTENT_LENGTH, "0"); headers.put("x-ms-blob-content-length", blob.getPayload().getContentMetadata().getContentLength().toString()); break; case BLOCK_BLOB: checkArgument( checkNotNull(blob.getPayload().getContentMetadata().getContentLength(), "blob.getContentLength()") <= 256L * 1024 * 1024, "maximum size for put Blob is 256MB"); break; } request = (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build(); return blobBinder.bindToRequest(request, azureBlob2Blob.apply(blob)); } @Inject  BindAzureBlobMetadataToRequest(AzureBlobToBlob azureBlob2Blob, BindUserMetadataToHeadersWithPrefix blobBinder); }
BindAzureBlobMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AzureBlob, "this binder is only valid for AzureBlobs!"); checkNotNull(request, "request"); AzureBlob blob = AzureBlob.class.cast(input); checkArgument(blob.getPayload().getContentMetadata().getContentLength() != null && blob.getPayload().getContentMetadata().getContentLength() >= 0, "size must be set"); Builder<String, String> headers = ImmutableMap.builder(); String cacheControl = blob.getPayload().getContentMetadata().getCacheControl(); if (cacheControl != null) { headers.put(AzureStorageHeaders.CACHE_CONTROL, cacheControl); } headers.put("x-ms-blob-type", blob.getProperties().getType().toString()); String contentDisposition = blob.getPayload().getContentMetadata().getContentDisposition(); if (contentDisposition != null) { headers.put("x-ms-blob-content-disposition", contentDisposition); } switch (blob.getProperties().getType()) { case PAGE_BLOB: headers.put(HttpHeaders.CONTENT_LENGTH, "0"); headers.put("x-ms-blob-content-length", blob.getPayload().getContentMetadata().getContentLength().toString()); break; case BLOCK_BLOB: checkArgument( checkNotNull(blob.getPayload().getContentMetadata().getContentLength(), "blob.getContentLength()") <= 256L * 1024 * 1024, "maximum size for put Blob is 256MB"); break; } request = (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build(); return blobBinder.bindToRequest(request, azureBlob2Blob.apply(blob)); } @Inject  BindAzureBlobMetadataToRequest(AzureBlobToBlob azureBlob2Blob, BindUserMetadataToHeadersWithPrefix blobBinder); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input); }
BindAzureBlobMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AzureBlob, "this binder is only valid for AzureBlobs!"); checkNotNull(request, "request"); AzureBlob blob = AzureBlob.class.cast(input); checkArgument(blob.getPayload().getContentMetadata().getContentLength() != null && blob.getPayload().getContentMetadata().getContentLength() >= 0, "size must be set"); Builder<String, String> headers = ImmutableMap.builder(); String cacheControl = blob.getPayload().getContentMetadata().getCacheControl(); if (cacheControl != null) { headers.put(AzureStorageHeaders.CACHE_CONTROL, cacheControl); } headers.put("x-ms-blob-type", blob.getProperties().getType().toString()); String contentDisposition = blob.getPayload().getContentMetadata().getContentDisposition(); if (contentDisposition != null) { headers.put("x-ms-blob-content-disposition", contentDisposition); } switch (blob.getProperties().getType()) { case PAGE_BLOB: headers.put(HttpHeaders.CONTENT_LENGTH, "0"); headers.put("x-ms-blob-content-length", blob.getPayload().getContentMetadata().getContentLength().toString()); break; case BLOCK_BLOB: checkArgument( checkNotNull(blob.getPayload().getContentMetadata().getContentLength(), "blob.getContentLength()") <= 256L * 1024 * 1024, "maximum size for put Blob is 256MB"); break; } request = (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build(); return blobBinder.bindToRequest(request, azureBlob2Blob.apply(blob)); } @Inject  BindAzureBlobMetadataToRequest(AzureBlobToBlob azureBlob2Blob, BindUserMetadataToHeadersWithPrefix blobBinder); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }