private void createNextFile(int suffix) throws IOException { try { currentBlob = directory.getAppendBlobReference(getJournalFileName(suffix + 1)); currentBlob.createOrReplace(); blockCount = 0; } catch (URISyntaxException | StorageException e) { throw new IOException(e); } }
private void createNextFile(int suffix) throws IOException { try { currentBlob = directory.getAppendBlobReference(getJournalFileName(suffix + 1)); currentBlob.createOrReplace(); blockCount = 0; } catch (URISyntaxException | StorageException e) { throw new IOException(e); } }
/** * Creates an empty append blob. If the blob already exists, this will replace it. * <p> * To avoid overwriting and instead throw an error, please use the * {@link #createOrReplace(AccessCondition, BlobRequestOptions, OperationContext)} overload with the appropriate * {@link AccessCondition}. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void createOrReplace() throws StorageException { this.createOrReplace(null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Creates an empty append blob. If the blob already exists, this will replace it. * <p> * To avoid overwriting and instead throw an error, please use the * {@link #createOrReplace(AccessCondition, BlobRequestOptions, OperationContext)} overload with the appropriate * {@link AccessCondition}. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void createOrReplace() throws StorageException { this.createOrReplace(null /* accessCondition */, null /* options */, null /* opContext */); }
@Override public void writeLine(String line) throws IOException { try { if (!gcJournal.exists()) { gcJournal.createOrReplace(); } gcJournal.appendText(line + "\n", Charsets.UTF_8.name(), null, null, null); } catch (StorageException e) { throw new IOException(e); } }
@Override public void writeLine(String line) throws IOException { try { if (!gcJournal.exists()) { gcJournal.createOrReplace(); } gcJournal.appendText(line + "\n", Charsets.UTF_8.name(), null, null, null); } catch (StorageException e) { throw new IOException(e); } }
private void roll() { try { date = new Date(); String stamp = new SimpleDateFormat("yyyy-MM-dd").format(date); String blobName = baseBlobName + "_" + stamp + ".log"; blob = container.getAppendBlobReference(blobName); if (!blob.exists()) { blob.createOrReplace(); HashMap<String, String> metadata = new HashMap<>(); metadata.put("date", stamp); metadata.put("name", baseBlobName); blob.setMetadata(metadata); blob.uploadMetadata(); } } catch (StorageException ex) { throw new RuntimeException(ex); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } }
public AzureJournalWriter() throws IOException { List<CloudAppendBlob> blobs = getJournalBlobs(); if (blobs.isEmpty()) { try { currentBlob = directory.getAppendBlobReference(getJournalFileName(1)); currentBlob.createOrReplace(); } catch (URISyntaxException | StorageException e) { throw new IOException(e); } } else { currentBlob = blobs.get(0); } Integer bc = currentBlob.getProperties().getAppendBlobCommittedBlockCount(); blockCount = bc == null ? 0 : bc; }
public AzureJournalWriter() throws IOException { List<CloudAppendBlob> blobs = getJournalBlobs(); if (blobs.isEmpty()) { try { currentBlob = directory.getAppendBlobReference(getJournalFileName(1)); currentBlob.createOrReplace(); } catch (URISyntaxException | StorageException e) { throw new IOException(e); } } else { currentBlob = blobs.get(0); } Integer bc = currentBlob.getProperties().getAppendBlobCommittedBlockCount(); blockCount = bc == null ? 0 : bc; }
private void doCreateAppendBlob(CloudAppendBlob client, BlobServiceRequestOptions opts, Exchange exchange) throws Exception { LOG.trace("Creating an append blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); try { client.createOrReplace(opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } catch (StorageException ex) { if (ex.getHttpStatusCode() != 409) { throw ex; } } ExchangeUtil.getMessageForResponse(exchange) .setHeader(BlobServiceConstants.APPEND_BLOCK_CREATED, Boolean.TRUE); }
@Before public void setup() throws StorageException, InvalidKeyException, URISyntaxException { container = azurite.getContainer("oak-test"); getBlob().createOrReplace(); }
protected JournalReader createJournalReader(String s) throws IOException { try { CloudAppendBlob blob = container.getAppendBlobReference("journal/journal.log.001"); blob.createOrReplace(); blob.appendText(s); return new JournalReader(new AzureJournalFile(container.getDirectoryReference("journal"), "journal.log")); } catch (StorageException | URISyntaxException e) { throw new IOException(e); } } }
@Test public void testOpenOutputStream() throws URISyntaxException, StorageException, IOException { int blobLengthToUse = 8 * 512; byte[] buffer = BlobTestHelper.getRandomBuffer(8 * 512); String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); final CloudAppendBlob blobRef = this.container .getAppendBlobReference(blobName); blobRef.createOrReplace(); BlobOutputStream blobOutputStream = blobRef.openWriteNew(); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); blobOutputStream = blobRef.openWriteNew(); inputStream = new ByteArrayInputStream(buffer); blobOutputStream.write(inputStream, 512); inputStream = new ByteArrayInputStream(buffer, 512, 3 * 512); blobOutputStream.write(inputStream, 3 * 512); blobOutputStream.close(); byte[] result = new byte[blobLengthToUse]; blobRef.downloadToByteArray(result, 0); int i = 0; for (; i < 4 * 512; i++) { assertEquals(buffer[i], result[i]); } for (; i < 8 * 512; i++) { assertEquals(0, result[i]); } }
@Test public void testAppendBlockFromStream() throws StorageException, IOException, URISyntaxException { int blobSize = 2 * 1024; String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); CloudAppendBlob blob = container.getAppendBlobReference(blobName); blob.createOrReplace(); // Append a block byte[] buffer = BlobTestHelper.getRandomBuffer(blobSize); ByteArrayInputStream sourceStream = new ByteArrayInputStream(buffer); long pos = blob.appendBlock(sourceStream, -1); assertEquals(0, pos); // Download and verify equality byte[] resultBuffer = new byte[blobSize]; blob.downloadToByteArray(resultBuffer, 0); for (int i = 0; i < blob.getProperties().getLength(); i++) { assertEquals(buffer[i], resultBuffer[i]); } // Append another block to check the position is updated correctly sourceStream = new ByteArrayInputStream(buffer); pos = blob.appendBlock(sourceStream, -1); assertEquals(blobSize, pos); }
@Test public void testAppendBlobAppendFromStream() throws StorageException, IOException, URISyntaxException { // Every time append a buffer that is bigger than a single block. byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.createOrReplace(); blob.append(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(12 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), buffer.length, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(18 * 1024 * 1024, blob.getProperties().getLength()); }
@Test public void testAppendBlobAppendFromStreamWithLength() throws StorageException, IOException, URISyntaxException { // Every time append a buffer that is bigger than a single block. byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.createOrReplace(); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024); blob.downloadAttributes(); assertEquals(5 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024); blob.downloadAttributes(); assertEquals(10 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(15 * 1024 * 1024, blob.getProperties().getLength()); } }
assertFalse(blob.deleteIfExists()); blob.createOrReplace(); assertTrue(blob.exists()); blob.createOrReplace(); assertFalse(blob.deleteIfExists(DeleteSnapshotsOption.NONE, null, null, ctx));
.generateRandomBlobNameWithPrefix("testblob"); CloudAppendBlob blob = container.getAppendBlobReference(blobName); blob.createOrReplace(); final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buffer); blob.appendBlock(sourceStream, blobSize);
blob1.createOrReplace(); accessCondition = AccessCondition.generateIfNoneMatchCondition(blob1 .getProperties().getEtag()); blob2.createOrReplace(); accessCondition = AccessCondition.generateIfMatchCondition(blob1 .getProperties().getEtag());
blob.createOrReplace(); assertTrue(blob.exists());