@Override public long contentLength() throws IOException { return this.cloudFile.getProperties().getLength(); }
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 void assertAreEqual(FileProperties prop1, FileProperties prop2) { if (prop1 == null) { Assert.assertNull(prop2); } else { Assert.assertNotNull(prop2); Assert.assertEquals(prop1.getCacheControl(), prop2.getCacheControl()); Assert.assertEquals(prop1.getContentDisposition(), prop2.getContentDisposition()); Assert.assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding()); Assert.assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage()); Assert.assertEquals(prop1.getContentMD5(), prop2.getContentMD5()); Assert.assertEquals(prop1.getContentType(), prop2.getContentType()); Assert.assertEquals(prop1.getEtag(), prop2.getEtag()); Assert.assertEquals(prop1.getLastModified(), prop2.getLastModified()); Assert.assertEquals(prop1.getLength(), prop2.getLength()); } }
length = this.getProperties().getLength();
length = this.getProperties().getLength();
this.accessCondition.setLeaseID(previousLeaseId); this.streamLength = parentFile.getProperties().getLength();
this.accessCondition.setLeaseID(previousLeaseId); this.streamLength = parentFile.getProperties().getLength();
/** * 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 file resizing. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileResize2() throws StorageException, URISyntaxException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); CloudFile file2 = this.share.getRootDirectoryReference().getFileReference("file1"); file.create(1024); assertEquals(1024, file.getProperties().getLength()); file2.downloadAttributes(); assertEquals(1024, file2.getProperties().getLength()); file2.getProperties().setContentType("text/plain"); file2.uploadProperties(); file.resize(2048); assertEquals(2048, file.getProperties().getLength()); file.downloadAttributes(); assertEquals("text/plain", file.getProperties().getContentType()); file2.downloadAttributes(); assertEquals(2048, file2.getProperties().getLength()); }
/** * Test file resizing. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileResize() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); CloudFile file2 = this.share.getRootDirectoryReference().getFileReference("file1"); file.create(1024); assertEquals(1024, file.getProperties().getLength()); file2.downloadAttributes(); assertEquals(1024, file2.getProperties().getLength()); file2.getProperties().setContentType("text/plain"); file2.uploadProperties(); file.resize(2048); assertEquals(2048, file.getProperties().getLength()); file.downloadAttributes(); assertEquals("text/plain", file.getProperties().getContentType()); file2.downloadAttributes(); assertEquals(2048, file2.getProperties().getLength()); // Resize to 0 length file.resize(0); assertEquals(0, file.getProperties().getLength()); file.downloadAttributes(); assertEquals("text/plain", file.getProperties().getContentType()); file2.downloadAttributes(); assertEquals(0, file2.getProperties().getLength()); }
/** * Test file exits method. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileExists() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); CloudFile file2 = this.share.getRootDirectoryReference().getFileReference("file1"); assertFalse(file2.exists()); file.create(2048); assertTrue(file2.exists()); assertEquals(2048, file2.getProperties().getLength()); file.delete(); assertFalse(file2.exists()); }
/** * Test FileOutputStream. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileOpenOutputStreamNoArgs() throws URISyntaxException, StorageException { String fileName = FileTestHelper.generateRandomFileName(); CloudFile file = this.share.getRootDirectoryReference().getFileReference(fileName); try { file.openWriteExisting(); } catch (StorageException ex) { assertEquals("The specified resource does not exist.", ex.getMessage()); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } file.openWriteNew(1024); file.openWriteExisting(); CloudFile file2 = this.share.getRootDirectoryReference().getFileReference(fileName); file2.downloadAttributes(); assertEquals(1024, file2.getProperties().getLength()); }
CloudFile file = this.share.getRootDirectoryReference().getFileReference("file29"); file.create(1024); assertEquals(1024, file.getProperties().getLength()); assertNotNull(file.getProperties().getEtag()); GregorianCalendar now = new GregorianCalendar(); assertEquals(1024, file2.getProperties().getLength()); assertEquals(file.getProperties().getEtag(), file2.getProperties().getEtag()); assertEquals(file.getProperties().getLastModified(), file2.getProperties().getLastModified());