/** * Checks to see if the file exists. * * @return <code>true</code> if the file exists, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final boolean exists() throws StorageException { return this.exists(null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Checks to see if the file exists. * * @return <code>true</code> if the file exists, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final boolean exists() throws StorageException { return this.exists(null /* accessCondition */, null /* options */, null /* opContext */); }
@Override public boolean exists() { try { return this.fileShare.exists() && cloudFile.exists(); } catch (StorageException e) { log.error(MSG_FAIL_CHECK_EXIST, e); throw new StorageRuntimeException(MSG_FAIL_CHECK_EXIST, e); } }
/** * Checks to see if the file exists, using the specified access condition, request options and operation context. * * @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 <code>true</code> if the file exists, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final boolean exists(final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { return this.exists(false /* primaryOnly */, accessCondition, options, opContext); }
/** * Checks to see if the file exists, using the specified access condition, request options and operation context. * * @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 <code>true</code> if the file exists, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final boolean exists(final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { return this.exists(false /* primaryOnly */, accessCondition, options, opContext); }
@Test public void testCloudFileCreate() throws StorageException, URISyntaxException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); assertFalse(file.exists()); // Create file.create(512); assertTrue(file.exists()); // Create again (should succeed) file.create(128); assertTrue(file.exists()); }
this.getShare().assertNoSnapshot(); boolean exists = this.exists(true, accessCondition, options, opContext); if (exists) { try {
this.getShare().assertNoSnapshot(); boolean exists = this.exists(true, accessCondition, options, opContext); if (exists) { try {
@Override public void eventOccurred(SendingRequestEvent eventArg) { if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) { try { file.delete(); assertFalse(file.exists()); } catch (Exception e) { fail("Delete should succeed."); } } } });
/** * 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 file creation and deletion. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileCreateAndDelete() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); file.create(0); assertTrue(file.exists()); file.delete(); }
CloudFile snapshotFile2 = new CloudFile(uriBuilder.addToURI(file.getUri()), this.share.getServiceClient().getCredentials()); assertEquals(snapshot.snapshotID, snapshotFile2.getShare().snapshotID); assertTrue(snapshotFile2.exists());
/** * Tests to make sure you can't delete a directory if it is nonempty. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryWithFilesDelete() throws URISyntaxException, StorageException { if (doCloudFileDirectorySetup(this.share)) { CloudFileDirectory dir1 = this.share.getRootDirectoryReference().getDirectoryReference( "TopDir1/MidDir1/EndDir1"); CloudFile file1 = dir1.getFileReference("EndFile1"); try { dir1.delete(); fail("Shouldn't be able to delete directory when files still exist in it."); } catch (StorageException e) { assertEquals(e.getHttpStatusCode(), 409); assertEquals(e.getMessage(), "The specified directory is not empty."); } file1.delete(); dir1.delete(); assertFalse(file1.exists()); assertFalse(dir1.exists()); } }