/** * Downloads the contents of a file to a stream. * * @param outStream * An <code>{@link OutputStream}</code> object that represents the target stream. * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final void download(final OutputStream outStream) throws StorageException { this.download(outStream, null /* accessCondition */, null /* options */, null /* opContext */); }
fileRef.download(new ByteArrayOutputStream(), null, options, null); fail(); fileRef.download(new ByteArrayOutputStream(), null, options, null); fileRef.getProperties().setContentMD5(calculatedMD5); fileRef.uploadProperties(null, options, null); fileRef.download(new ByteArrayOutputStream(), null, options, null); fileRef.downloadToByteArray(new byte[4096], 0);
/** * Create a file and try to download a range of its contents * * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test public void testFileDownloadRangeValidationTest() throws StorageException, URISyntaxException, IOException { final int length = 5 * 1024 * 1024; final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); fileRef.upload(FileTestHelper.getRandomDataStream(length), length); //Download full file fileRef.download(new ByteArrayOutputStream()); assertEquals(length, fileRef.getProperties().getLength()); //Download file range. byte[] downloadBuffer = new byte[100]; int downloadLength = fileRef.downloadRangeToByteArray(0, (long) 100, downloadBuffer, 0); assertEquals(length, fileRef.getProperties().getLength()); assertEquals(100, downloadLength); }
fileRef1.download(new ByteArrayOutputStream(), null, options, null); props2 = fileRef1.getProperties();
/** * Downloads the contents of a file to a stream. * * @param outStream * An <code>{@link OutputStream}</code> object that represents the target stream. * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final void download(final OutputStream outStream) throws StorageException { this.download(outStream, null /* accessCondition */, null /* options */, null /* opContext */); }
FileRequestOptions options = new FileRequestOptions(); options.setDisableContentMD5Validation(true); file3.download(stream, null, options, null); FileTestHelper.assertAreEqual(file2.getProperties(), file3.getProperties());
/** * Downloads a file to a string using the specified encoding. * * @param charsetName * A <code>String</code> which represents the name of the charset to use to encode the content. * If null, the platform's default encoding is used. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the file. * @param options * A {@link FileRequestOptions} 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 CloudFileClient}). * @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. * * @return A <code>String</code> which represents the file's contents. * * @throws StorageException * If a storage service error occurred. * @throws IOException */ public String downloadText(final String charsetName, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); this.download(baos, accessCondition, options, opContext); return charsetName == null ? baos.toString() : baos.toString(charsetName); }
/** * Downloads a file to a string using the specified encoding. * * @param charsetName * A <code>String</code> which represents the name of the charset to use to encode the content. * If null, the platform's default encoding is used. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the file. * @param options * A {@link FileRequestOptions} 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 CloudFileClient}). * @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. * * @return A <code>String</code> which represents the file's contents. * * @throws StorageException * If a storage service error occurred. * @throws IOException */ public String downloadText(final String charsetName, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); this.download(baos, accessCondition, options, opContext); return charsetName == null ? baos.toString() : baos.toString(charsetName); }
OutputStream outputStream = new BufferedOutputStream(new java.io.FileOutputStream(path)); try { this.download(outputStream, accessCondition, options, opContext); outputStream.close();
OutputStream outputStream = new BufferedOutputStream(new java.io.FileOutputStream(path)); try { this.download(outputStream, accessCondition, options, opContext); outputStream.close();
file.download(outStream); } catch (URISyntaxException e) { e.printStackTrace();
@Test public void testFileUploadFromStreamTest() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); int length = 2 * 1024; ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(length); fileRef.upload(srcStream, length); ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); fileRef.download(dstStream); FileTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); length = 5 * 1024 * 1024; srcStream = FileTestHelper.getRandomDataStream(length); fileRef.upload(srcStream, length); dstStream = new ByteArrayOutputStream(); fileRef.download(dstStream); FileTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); }
/** * Test file stream uploading. * * @throws URISyntaxException * @throws StorageException */ @Test public void testFileUploadFromStreamTest1() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); int length = 2 * 1024; ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(length); fileRef.upload(srcStream, length); ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); fileRef.download(dstStream); FileTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); length = 5 * 1024 * 1024; srcStream = FileTestHelper.getRandomDataStream(length); fileRef.upload(srcStream, length); dstStream = new ByteArrayOutputStream(); fileRef.download(dstStream); FileTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); }
@Test @Category(SlowTests.class) public void testCopyPageBlobSas() throws Exception { // Create source on server. final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference(); try { container.create(); final CloudPageBlob source = container.getPageBlobReference("source"); source.getMetadata().put("Test", "value"); final int length = 512; final ByteArrayInputStream data = BlobTestHelper.getRandomDataStream(length); source.upload(data, length); final CloudFile destination = doCloudBlobCopy(source, length); final ByteArrayOutputStream copyData = new ByteArrayOutputStream(); destination.download(copyData); BlobTestHelper.assertStreamsAreEqual(data, new ByteArrayInputStream(copyData.toByteArray())); } finally { container.deleteIfExists(); } }
httpShare.getServiceClient().getCredentials().getClass().toString()); CloudFile httpFile = httpShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpFile.download(new ByteArrayOutputStream()); httpsShare.getServiceClient().getCredentials().getClass().toString()); CloudFile httpsFile = httpsShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpsFile.download(new ByteArrayOutputStream()); httpShare.getServiceClient().getCredentials().getClass().toString()); CloudFile httpFile = httpShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpFile.download(new ByteArrayOutputStream()); httpsShare.getServiceClient().getCredentials().getClass().toString()); httpsFile = httpsShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpsFile.download(new ByteArrayOutputStream());
sasFile.download(new ByteArrayOutputStream(), null, null, context);
@Test public void testFileEmptyHeaderSigningTest() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); final int length = 2 * 1024; ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(length); OperationContext context = new OperationContext(); context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); connection.setRequestProperty("x-ms-foo", ""); } }); fileRef.upload(srcStream, length, null, null, context); fileRef.download(new ByteArrayOutputStream(), null, null, context); }
@Test public void testFileSAS() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { SharedAccessFilePolicy policy = createSharedAccessPolicy( EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.LIST), 300); FileSharePermissions perms = new FileSharePermissions(); perms.getSharedAccessPolicies().put("readperm", policy); this.share.uploadPermissions(perms); Thread.sleep(30000); CloudFile sasFile = new CloudFile( new URI(this.file.getUri().toString() + "?" + this.file.generateSharedAccessSignature(null, "readperm"))); sasFile.download(new ByteArrayOutputStream()); // do not give the client and check that the new file's client has the correct permissions CloudFile fileFromUri = new CloudFile(PathUtility.addToQuery(this.file.getStorageUri(), this.file.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromUri.getServiceClient().getCredentials().getClass().toString()); // create credentials from sas StorageCredentials creds = new StorageCredentialsSharedAccessSignature( this.file.generateSharedAccessSignature(policy, null, null)); CloudFileClient client = new CloudFileClient(sasFile.getServiceClient().getStorageUri(), creds); CloudFile fileFromClient = client.getShareReference(this.file.getShare().getName()).getRootDirectoryReference() .getFileReference(this.file.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromClient.getServiceClient().getCredentials().getClass().toString()); assertEquals(client, fileFromClient.getServiceClient()); }
fileFromSasShare.download(new ByteArrayOutputStream());