@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); } }
@Override public List<String> readLines() throws IOException { try { if (!gcJournal.exists()) { return Collections.emptyList(); } byte[] data = new byte[(int) gcJournal.getProperties().getLength()]; gcJournal.downloadToByteArray(data, 0); return IOUtils.readLines(new ByteArrayInputStream(data), Charset.defaultCharset()); } catch (StorageException e) { throw new IOException(e); } } }
@Override public List<String> readLines() throws IOException { try { if (!gcJournal.exists()) { return Collections.emptyList(); } byte[] data = new byte[(int) gcJournal.getProperties().getLength()]; gcJournal.downloadToByteArray(data, 0); return IOUtils.readLines(new ByteArrayInputStream(data), Charset.defaultCharset()); } 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); } }
@Override public void eventOccurred(SendingRequestEvent eventArg) { if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) { try { blob.delete(); assertFalse(blob.exists()); } catch (StorageException e) { fail("Delete should succeed."); } } } });
@Test public void testAppendBlobUploadNegativeLength() throws URISyntaxException, StorageException, IOException { final int blobLength = 16 * 1024; String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); final CloudAppendBlob blobRef = this.container .getAppendBlobReference(blobName); final byte[] buff = BlobTestHelper.getRandomBuffer(blobLength); ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff); blobRef.upload(sourceStream, -1); assertTrue(blobRef.exists()); assertEquals(blobRef.getProperties().getLength(), blobLength); }
CloudAppendBlob sasBlob = (CloudAppendBlob) sasClient.getContainerReference(container.getName()) .getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists();