/** * Clears a range from a file. * <p> * Calling <code>clearRange</code> releases the storage space used by the specified range. Ranges that have been * cleared are no longer tracked as part of the file. * * @param offset * The offset, in bytes, at which to begin clearing. * @param length * The length, in bytes, of the data range to be cleared. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException */ @DoesServiceRequest public void clearRange(final long offset, final long length) throws StorageException, URISyntaxException { this.clearRange(offset, length, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Clears a range from a file. * <p> * Calling <code>clearRange</code> releases the storage space used by the specified range. Ranges that have been * cleared are no longer tracked as part of the file. * * @param offset * The offset, in bytes, at which to begin clearing. * @param length * The length, in bytes, of the data range to be cleared. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException */ @DoesServiceRequest public void clearRange(final long offset, final long length) throws StorageException, URISyntaxException { this.clearRange(offset, length, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Test clearing file ranges. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileClearRange() throws URISyntaxException, StorageException, IOException { int fileLengthToUse = 8 * 512; byte[] buffer = FileTestHelper.getRandomBuffer(8 * 512); String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); fileRef.create(fileLengthToUse); // Upload one page (page 0) ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); fileRef.uploadRange(inputStream, 0, fileLengthToUse); fileRef.clearRange(3 * 512, 2 * 512); byte[] result = new byte[fileLengthToUse]; fileRef.downloadToByteArray(result, 0); int i = 0; for (; i < 3 * 512; i++) { assertEquals(buffer[i], result[i]); } for (; i < 5 * 512; i++) { assertEquals(0, result[i]); } for (; i < 8 * 512; i++) { assertEquals(buffer[i], result[i]); } }
file.clearRange(0, 512); fail("Shouldn't get here");