AbstractBlobStore implements GarbageCollectableBlobStore,
        Cache.Backend<AbstractBlobStore.BlockId, AbstractBlobStore.Data> { @Override public String writeBlob(String tempFilePath) throws IOException { File file = new File(tempFilePath); InputStream in = null; try { in = new FileInputStream(file); return writeBlob(in); } finally { org.apache.commons.io.IOUtils.closeQuietly(in); FileUtils.forceDelete(file); } }  void setBlockSizeMin(int x); @Override long getBlockSizeMin(); @Override void setBlockSize(int x); void setStatsCollector(BlobStatsCollector stats); int getBlockSize(); @Override String writeBlob(String tempFilePath); @Override String writeBlob(InputStream in); @Override String writeBlob(InputStream in, BlobOptions options); @Override InputStream getInputStream(String blobId); @Override String getReference(@NotNull String blobId); @Override String getBlobId(@NotNull String reference); void setReferenceKey(byte[] referenceKey); void setReferenceKeyEncoded(String encodedKey); void setReferenceKeyPlainText(String textKey); @Override void clearInUse(); @Override abstract void startMark(); @Override abstract int sweep(); @Override int readBlob(String blobId, long pos, byte[] buff, int off,
            int length); @Override Data load(BlockId id); @Override long getBlobLength(String blobId); @Override Iterator<String> resolveChunks(String blobId); @Override boolean deleteChunks(List<String> chunkIds, long maxLastModifiedTime); @Override void close();  }
@Test public void testCloseStream() throws Exception { final AtomicBoolean closed = new AtomicBoolean(); InputStream in = new InputStream() { @Override public void close() { closed.set(true); } @Override public int read() throws IOException { return -1; } }; store.writeBlob(in); assertTrue(closed.get()); }
@Test public void testExceptionWhileReading() throws Exception { final AtomicBoolean closed = new AtomicBoolean(); InputStream in = new InputStream() { @Override public void close() { closed.set(true); } @Override public int read() throws IOException { throw new RuntimeException("abc"); } }; try { store.writeBlob(in); } catch (Exception e) { String msg = e.getMessage(); assertTrue(msg, msg.indexOf("abc") >= 0); } assertTrue(closed.get()); }
@Test public void uploadCallback() throws Exception { assumeTrue(supportsStatsCollection()); TestCollector collector = new TestCollector(); setupCollector(collector); int size = 10 * 1024; store.writeBlob(randomStream(42, size)); assertCollectedSize(collector.size, size); assertEquals(1, collector.uploadCount); }