throws StorageException, IOException, URISyntaxException { ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, offset, length); this.upload(inputStream, length, accessCondition, options, opContext); inputStream.close();
options.setStoreFileContentMD5(false); fileRef.upload(srcStream, length, null, options, null); fileRef.downloadAttributes(); fileRef.getProperties().setContentMD5("MDAwMDAwMDA=");
file.upload(null, 512); fail("Shouldn't get here");
throws StorageException, IOException, URISyntaxException { ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, offset, length); this.upload(inputStream, length, accessCondition, options, opContext); inputStream.close();
/** * Uploads the source stream data to the file. If the file already exists on the service, it will be overwritten. * * @param sourceStream * An {@link InputStream} object to read from. * @param length * A <code>long</code> which represents the length, in bytes, of the stream data. Must be non zero. * * @throws IOException * If an I/O exception occurred. * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException */ @DoesServiceRequest public void upload(final InputStream sourceStream, final long length) throws StorageException, IOException, URISyntaxException { this.upload(sourceStream, length, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Uploads the source stream data to the file. If the file already exists on the service, it will be overwritten. * * @param sourceStream * An {@link InputStream} object to read from. * @param length * A <code>long</code> which represents the length, in bytes, of the stream data. Must be non zero. * * @throws IOException * If an I/O exception occurred. * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException */ @DoesServiceRequest public void upload(final InputStream sourceStream, final long length) throws StorageException, IOException, URISyntaxException { this.upload(sourceStream, length, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Uploads a file from a local file. If the file 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 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. * * @throws StorageException * If a storage service error occurred. * @throws IOException * @throws URISyntaxException */ public void uploadFromFile(final String path, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException, IOException, URISyntaxException { File file = new File(path); long fileLength = file.length(); InputStream inputStream = new BufferedInputStream(new java.io.FileInputStream(file)); this.upload(inputStream, fileLength, accessCondition, options, opContext); inputStream.close(); }
/** * Uploads a file from a local file. If the file 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 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. * * @throws StorageException * If a storage service error occurred. * @throws IOException * @throws URISyntaxException */ public void uploadFromFile(final String path, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException, IOException, URISyntaxException { File file = new File(path); long fileLength = file.length(); InputStream inputStream = new BufferedInputStream(new java.io.FileInputStream(file)); this.upload(inputStream, fileLength, accessCondition, options, opContext); inputStream.close(); }
protected static void doDownloadRangeToByteArrayTest(CloudFile file, int fileSize, int bufferSize, int bufferOffset, Long fileOffset, Long length) throws IOException, StorageException, URISyntaxException { final Random randGenerator = new Random(); final byte[] buffer = new byte[fileSize]; randGenerator.nextBytes(buffer); byte[] resultBuffer = new byte[bufferSize]; int downloadLength; FileRequestOptions options = new FileRequestOptions(); file.upload(new ByteArrayInputStream(buffer), buffer.length); downloadLength = file.downloadRangeToByteArray(fileOffset, length, resultBuffer, bufferOffset, null, options, null); int downloadSize = Math.min(fileSize - (int) (fileOffset != null ? fileOffset : 0), bufferSize - bufferOffset); if (length != null && length < downloadSize) { downloadSize = length.intValue(); } Assert.assertEquals(downloadSize, downloadLength); for (int i = 0; i < bufferOffset; i++) { Assert.assertEquals(0, resultBuffer[i]); } for (int j = 0; j < downloadLength; j++) { Assert.assertEquals(buffer[(int) ((fileOffset != null ? fileOffset : 0) + j)], resultBuffer[bufferOffset + j]); } for (int k = bufferOffset + downloadLength; k < bufferSize; k++) { Assert.assertEquals(0, resultBuffer[k]); } }
protected static void doDownloadTest(CloudFile file, int fileSize, int bufferSize, int bufferOffset) throws StorageException, IOException, URISyntaxException { final Random randGenerator = new Random(); final byte[] buffer = new byte[fileSize]; randGenerator.nextBytes(buffer); byte[] resultBuffer = new byte[bufferSize]; FileRequestOptions options = new FileRequestOptions(); file.upload(new ByteArrayInputStream(buffer), buffer.length); file.downloadToByteArray(resultBuffer, bufferOffset, null, options, null); for (int i = 0; i < file.getProperties().getLength(); i++) { Assert.assertEquals(buffer[i], resultBuffer[bufferOffset + i]); } if (bufferOffset + fileSize < bufferSize) { for (int k = bufferOffset + fileSize; k < bufferSize; k++) { Assert.assertEquals(0, resultBuffer[k]); } } }
public static CloudFile uploadNewFile( CloudFileShare share, InputStream stream, int length, OperationContext context) throws StorageException, IOException, URISyntaxException { String name = generateRandomFileName(); CloudFile file = null; file = share.getRootDirectoryReference().getFileReference(name); file.upload(stream, length, null, null, context); return file; }
@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())); }
byte[] resultBuffer = new byte[resultBufSize]; file.upload(new ByteArrayInputStream(buffer), buffer.length);
file.upload(wholeFile, 2 * 1024);
@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); }
options.setTimeoutIntervalInMs(90000); options.setRetryPolicyFactory(new RetryNoRetry()); fileRef.upload(sourceStream, fileLength, null, options, operationContext);
/** * 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); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testVerifyTransactionalMD5ValidationMissingOverallMD5() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); final int length = 3*1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); FileRequestOptions options = new FileRequestOptions(); options.setDisableContentMD5Validation(true); options.setStoreFileContentMD5(false); fileRef.upload(srcStream, length, null, options, null); options.setDisableContentMD5Validation(false); options.setStoreFileContentMD5(true); options.setUseTransactionalContentMD5(true); final CloudFile fileRef2 = this.share.getRootDirectoryReference().getFileReference(fileName); fileRef2.downloadRange(1024, (long)1024, new ByteArrayOutputStream(), null, options, null); assertNull(fileRef2.getProperties().getContentMD5()); }