@Override public String getBlobId(@NotNull String reference) { checkNotNull(reference); DataRecord record; try { record = delegate.getRecordFromReference(reference); if (record != null) { return getBlobId(record); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", reference, e); } return null; }
@Override public String getBlobId(@NotNull String reference) { checkNotNull(reference); DataRecord record; try { record = delegate.getRecordFromReference(reference); if (record != null) { return getBlobId(record); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", reference, e); } return null; }
@Override public String getBlobId(@Nonnull String reference) { checkNotNull(reference); DataRecord record; try { record = delegate.getRecordFromReference(reference); if (record != null) { return getBlobId(record); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", reference, e); } return null; }
@Override public String writeBlob(InputStream stream, BlobOptions options) throws IOException { boolean threw = true; try { long start = System.nanoTime(); checkNotNull(stream); DataRecord dr = writeStream(stream, options); String id = getBlobId(dr); if (tracker != null && !InMemoryDataRecord.isInstance(id)) { try { tracker.add(id); log.trace("Tracked Id {}", id); } catch (Exception e) { log.warn("Could not add track id", e); } } threw = false; stats.uploaded(System.nanoTime() - start, TimeUnit.NANOSECONDS, dr.getLength()); stats.uploadCompleted(id); return id; } catch (DataStoreException e) { throw new IOException(e); } finally { //DataStore does not closes the stream internally //So close the stream explicitly Closeables.close(stream, threw); } }
@Override public String writeBlob(InputStream stream, BlobOptions options) throws IOException { boolean threw = true; try { long start = System.nanoTime(); checkNotNull(stream); DataRecord dr = writeStream(stream, options); String id = getBlobId(dr); if (tracker != null && !InMemoryDataRecord.isInstance(id)) { try { tracker.add(id); log.trace("Tracked Id {}", id); } catch (Exception e) { log.warn("Could not add track id", e); } } threw = false; stats.uploaded(System.nanoTime() - start, TimeUnit.NANOSECONDS, dr.getLength()); stats.uploadCompleted(id); return id; } catch (DataStoreException e) { throw new IOException(e); } finally { //DataStore does not closes the stream internally //So close the stream explicitly Closeables.close(stream, threw); } }
@Override public String writeBlob(InputStream stream, BlobOptions options) throws IOException { boolean threw = true; try { long start = System.nanoTime(); checkNotNull(stream); DataRecord dr = writeStream(stream, options); String id = getBlobId(dr); if (tracker != null && !InMemoryDataRecord.isInstance(id)) { try { tracker.add(id); log.trace("Tracked Id {}", id); } catch (Exception e) { log.warn("Could not add track id", e); } } threw = false; stats.uploaded(System.nanoTime() - start, TimeUnit.NANOSECONDS, dr.getLength()); stats.uploadCompleted(id); return id; } catch (DataStoreException e) { throw new IOException(e); } finally { //DataStore does not closes the stream internally //So close the stream explicitly Closeables.close(stream, threw); } }
@Test public void testReference() throws DataStoreException, IOException { String reference = "testReference"; String blobId = "test"; DataIdentifier testDI = new DataIdentifier(blobId); DataRecord testDR = new ByteArrayDataRecord("foo".getBytes(), testDI, reference); DataStore mockedDS = mock(DataStore.class); when(mockedDS.getRecordFromReference(reference)).thenReturn(testDR); when(mockedDS.getRecord(testDI)).thenReturn(testDR); when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); assertEquals(reference,ds.getReference(blobId)); assertEquals(blobId, BlobId.of(ds.getBlobId(reference)).blobId); assertEquals(BlobId.of(testDR).encodedValue(),ds.getBlobId(reference)); String inMemBlobId = InMemoryDataRecord.getInstance("foo".getBytes()) .getIdentifier().toString(); //For in memory record the reference should be null assertNull(ds.getReference(inMemBlobId)); }