blob.upload(in, length, null, null, operationContext); BlobProperties properties = blob.getProperties(); attributes.put("azure.container", containerName);
final byte[] buff = new byte[length]; randGenerator.nextBytes(buff); blobSnapshot.upload(new ByteArrayInputStream(buff), -1); fail("Expect an IllegalArgumentException from upload");
final byte[] buff = new byte[length]; randGenerator.nextBytes(buff); blobSnapshot.upload(new ByteArrayInputStream(buff), -1); fail("Expect an IllegalArgumentException from upload");
public void upload(InputStream sourceStream, OperationContext opContext) throws StorageException, IOException { getBlob().upload(sourceStream, 0, null, null, opContext); }
final byte[] buff = new byte[length]; randGenerator.nextBytes(buff); blobSnapshot.upload(new ByteArrayInputStream(buff), -1); fail("Expect an IllegalArgumentException from upload"); } catch (IllegalArgumentException e) {
public void upload(InputStream sourceStream, OperationContext opContext) throws StorageException, IOException { getBlob().upload(sourceStream, 0, null, null, opContext); }
public void upload(InputStream sourceStream, OperationContext opContext) throws StorageException, IOException { getBlob().upload(sourceStream, 0, null, null, opContext); }
public void upload(InputStream sourceStream, OperationContext opContext) throws StorageException, IOException { getBlob().upload(sourceStream, 0, null, null, opContext); }
throws StorageException, IOException { ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, offset, length); this.upload(inputStream, length, accessCondition, options, opContext); inputStream.close();
throws StorageException, IOException { ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, offset, length); this.upload(inputStream, length, accessCondition, options, opContext); inputStream.close();
/** * Uploads a blob from a file. If the blob already exists on the service, it will be overwritten. * * @param path * A <code>String</code> which represents the path to the file to be uploaded. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the blob. * @param options * A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudBlobClient}). * @param opContext * An {@link OperationContext} object that represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @throws StorageException * If a storage service error occurred. * @throws IOException */ public void uploadFromFile(final String path, final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext) throws StorageException, IOException { File file = new File(path); long fileLength = file.length(); InputStream inputStream = new FileInputStream(file); // The call to upload supports FileInputStream efficiently. this.upload(inputStream, fileLength, accessCondition, options, opContext); inputStream.close(); }
/** * Uploads a blob from a file. If the blob already exists on the service, it will be overwritten. * * @param path * A <code>String</code> which represents the path to the file to be uploaded. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the blob. * @param options * A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudBlobClient}). * @param opContext * An {@link OperationContext} object that represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @throws StorageException * If a storage service error occurred. * @throws IOException */ public void uploadFromFile(final String path, final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext) throws StorageException, IOException { File file = new File(path); long fileLength = file.length(); InputStream inputStream = new BufferedInputStream(new FileInputStream(file)); this.upload(inputStream, fileLength, accessCondition, options, opContext); inputStream.close(); }
protected static void doDownloadRangeToByteArrayTest(CloudBlob blob, int blobSize, int bufferSize, int bufferOffset, Long blobOffset, Long length) throws IOException, StorageException { final Random randGenerator = new Random(); final byte[] buffer = new byte[blobSize]; randGenerator.nextBytes(buffer); byte[] resultBuffer = new byte[bufferSize]; int downloadLength; BlobRequestOptions options = new BlobRequestOptions(); blob.upload(new ByteArrayInputStream(buffer), buffer.length); downloadLength = blob.downloadRangeToByteArray(blobOffset, length, resultBuffer, bufferOffset, null, options, null); int downloadSize = Math.min(blobSize - (int) (blobOffset != null ? blobOffset : 0), bufferSize - bufferOffset); if (length != null && length < downloadSize) { downloadSize = length.intValue(); } assertEquals(downloadSize, downloadLength); for (int i = 0; i < bufferOffset; i++) { assertEquals(0, resultBuffer[i]); } for (int j = 0; j < downloadLength; j++) { assertEquals(buffer[(int) ((blobOffset != null ? blobOffset : 0) + j)], resultBuffer[bufferOffset + j]); } for (int k = bufferOffset + downloadLength; k < bufferSize; k++) { assertEquals(0, resultBuffer[k]); } }
protected static void doDownloadTest(CloudBlob blob, int blobSize, int bufferSize, int bufferOffset) throws StorageException, IOException { final Random randGenerator = new Random(); final byte[] buffer = new byte[blobSize]; randGenerator.nextBytes(buffer); byte[] resultBuffer = new byte[bufferSize]; BlobRequestOptions options = new BlobRequestOptions(); if (blob.getClass() == CloudBlockBlob.class) { options.setUseTransactionalContentMD5(true); } blob.upload(new ByteArrayInputStream(buffer), buffer.length); blob.downloadToByteArray(resultBuffer, bufferOffset, null, options, null); for (int i = 0; i < blob.getProperties().getLength(); i++) { assertEquals(buffer[i], resultBuffer[bufferOffset + i]); } if (bufferOffset + blobSize < bufferSize) { for (int k = bufferOffset + blobSize; k < bufferSize; k++) { assertEquals(0, resultBuffer[k]); } } }
@NotNull public BlobFile createBlobFile(@NotNull ClientStorageAccount storageAccount, @NotNull BlobDirectory parentBlobDirectory, @NotNull BlobFile blobFile) throws AzureCmdException { try { CloudBlobClient client = getCloudBlobClient(storageAccount); String containerName = parentBlobDirectory.getContainerName(); CloudBlobContainer container = client.getContainerReference(containerName); CloudBlobDirectory parentDirectory = container.getDirectoryReference(parentBlobDirectory.getPath()); CloudBlob blob = getCloudBlob(parentDirectory, blobFile); blob.upload(new ByteArrayInputStream(new byte[0]), 0); return reloadBlob(blob, containerName, blobFile); } catch (Throwable t) { throw new AzureCmdException("Error creating the Blob File", t); } }
case BLOCK_BLOB: blob = container.getBlockBlobReference(name); blob.upload(getRandomDataStream(length), length, null, null, context); break; ((CloudPageBlob) blob).create(length, null, null, context); } else { blob.upload(getRandomDataStream(length), length, null, null, context); ((CloudAppendBlob) blob).createOrReplace(null, null, context); } else { blob.upload(getRandomDataStream(length), length, null, null, context);
@Test public void testBlobLeaseAcquireAndRelease() throws URISyntaxException, StorageException, IOException { final int length = 128; final CloudBlob blobRef = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "test", 128, null); // Get Lease OperationContext operationContext = new OperationContext(); final String leaseID = blobRef.acquireLease(15, null /*proposed lease id */, null /*access condition*/, null/* BlobRequestOptions */, operationContext); final AccessCondition leaseCondition = AccessCondition.generateLeaseCondition(leaseID); assertTrue(operationContext.getLastResult().getStatusCode() == HttpURLConnection.HTTP_CREATED); tryUploadWithBadLease(length, blobRef, null, StorageErrorCodeStrings.LEASE_ID_MISSING); // Try to upload with lease blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1, leaseCondition, null, null); // Release lease blobRef.releaseLease(leaseCondition); // now upload with no lease specified. blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1); }
/** * Try to upload with a bad lease * * @param length * @param blobRef * @throws IOException */ private void tryUploadWithBadLease(final int length, final CloudBlob blobRef, final AccessCondition leaseCondition, final String expectedError) throws IOException { try { blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1, leaseCondition, null, null); fail("Did not throw expected exception"); } catch (final StorageException ex) { assertEquals(ex.getHttpStatusCode(), 412); assertEquals(ex.getErrorCode(), expectedError); } }
byte[] resultBuffer = new byte[resultBufSize]; blob.upload(new ByteArrayInputStream(buffer), buffer.length);