/** * Populates a file's properties and metadata. * <p> * This method populates the file's system properties and user-defined metadata. Before reading or modifying * a file's properties or metadata, call this method or its overload to retrieve the latest values for the * file's properties and metadata from the Microsoft Azure storage service. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final void downloadAttributes() throws StorageException { this.downloadAttributes(null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Populates a file's properties and metadata. * <p> * This method populates the file's system properties and user-defined metadata. Before reading or modifying * a file's properties or metadata, call this method or its overload to retrieve the latest values for the * file's properties and metadata from the Microsoft Azure storage service. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final void downloadAttributes() throws StorageException { this.downloadAttributes(null /* accessCondition */, null /* options */, null /* opContext */); }
public static void waitForCopy(CloudFile file) throws StorageException, InterruptedException { boolean copyInProgress = true; while (copyInProgress) { file.downloadAttributes(); copyInProgress = (file.getCopyState().getStatus() == CopyStatus.PENDING) || (file.getCopyState().getStatus() == CopyStatus.ABORTED); // One second sleep if retry is needed if (copyInProgress) { Thread.sleep(1000); } } }
/** * Test file creation with metadata. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileCreateWithMetadata() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); HashMap<String, String> meta = new HashMap<String, String>(); meta.put("key1", "value1"); file.setMetadata(meta); file.create(1024); CloudFile file2 = this.share.getRootDirectoryReference().getFileReference("file1"); file2.downloadAttributes(); assertEquals(1, file2.getMetadata().size()); assertEquals("value1", file2.getMetadata().get("key1")); file2.setMetadata(new HashMap<String, String>()); file2.uploadMetadata(); file.downloadAttributes(); assertEquals(0, file.getMetadata().size()); }
this.downloadAttributes(accessCondition, options, opContext); length = this.getProperties().getLength();
this.downloadAttributes(accessCondition, options, opContext); length = this.getProperties().getLength();
parentFile.downloadAttributes(accessCondition, this.options, this.opContext);
parentFile.downloadAttributes(accessCondition, this.options, this.opContext);
@Test public void testFileAttributesEncryption() throws URISyntaxException, StorageException, IOException { this.file.downloadAttributes(); assertTrue(this.file.getProperties().isServerEncrypted()); CloudFile testFile = this.share.getRootDirectoryReference().getFileReference("file"); testFile.downloadText(); assertTrue(testFile.getProperties().isServerEncrypted()); }
/** * 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()); }
file.setMetadata(meta2); file.uploadMetadata(); snapshotFile.downloadAttributes(); file.downloadAttributes(); assertTrue(file.getMetadata().size() == 1 && file.getMetadata().get("key2").equals("value2")); assertNotNull(file.getProperties().getEtag());
/** * 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()); }
assertEquals(data, copyData); copy.downloadAttributes(); source.downloadAttributes(); FileProperties prop1 = copy.getProperties(); FileProperties prop2 = source.getProperties();
String copyId = destination.startCopy(blobType.newInstance(credentials.transformUri(source.getUri()))); FileTestHelper.waitForCopy(destination); destination.downloadAttributes();
/** * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class }) public void testFileNamePlusEncoding() throws StorageException, URISyntaxException, IOException, InterruptedException { CloudFile originalFile = FileTestHelper.uploadNewFile(this.share, 1024 /* length */, null); CloudFile copyFile = this.share.getRootDirectoryReference().getFileReference(originalFile.getName() + "copyed"); copyFile.startCopy(originalFile); FileTestHelper.waitForCopy(copyFile); copyFile.downloadAttributes(); originalFile.downloadAttributes(); FileProperties prop1 = copyFile.getProperties(); FileProperties prop2 = originalFile.getProperties(); assertEquals(prop1.getCacheControl(), prop2.getCacheControl()); assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding()); assertEquals(prop1.getContentDisposition(), prop2.getContentDisposition()); assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage()); assertEquals(prop1.getContentMD5(), prop2.getContentMD5()); assertEquals(prop1.getContentType(), prop2.getContentType()); }
FileTestHelper.waitForCopy(copySas); copySas.downloadAttributes(); FileProperties prop1 = copySas.getProperties(); BlobProperties prop2 = sasBlob.getProperties();
/** * 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()); }
fileRef1.uploadProperties(); fileRef1.downloadAttributes(null, options, null); FileProperties props2 = fileRef1.getProperties();
file2.downloadAttributes(); assertEquals("no-transform", file2.getProperties().getCacheControl()); assertEquals("attachment", file2.getProperties().getContentDisposition());
file2.downloadAttributes(); assertEquals(1024, file2.getProperties().getLength()); assertEquals(file.getProperties().getEtag(), file2.getProperties().getEtag());