@Override public InputStream readBlob(String blobId) { if (store == null) { return null; } try { return store.getInputStream(blobId); } catch (IOException e) { log.warn("Error while reading blob content", e); } return null; }
@Override @NotNull public InputStream getNewStream() { try { return blobStore.getInputStream(blobId); } catch (IOException e) { throw new RuntimeException("Error occurred while obtaining " + "InputStream for blobId ["+ blobId +"]",e); } }
@Override @Nonnull public InputStream getNewStream() { try { return blobStore.getInputStream(blobId); } catch (IOException e) { throw new RuntimeException("Error occurred while obtaining " + "InputStream for blobId ["+ blobId +"]",e); } }
@Override @NotNull public InputStream getNewStream() { try { return blobStore.getInputStream(blobId); } catch (IOException e) { throw new RuntimeException("Error occurred while obtaining " + "InputStream for blobId ["+ blobId +"]",e); } }
@Override public InputStream getInputStream(String blobId) throws IOException { return chooseBlobStoreByBlobId(blobId).getInputStream(blobId); }
@Override public InputStream getInputStream(String blobId) throws IOException { return chooseBlobStoreByBlobId(blobId).getInputStream(blobId); }
@Override public InputStream getInputStream(String blobId) throws IOException { return chooseBlobStoreByBlobId(blobId).getInputStream(blobId); }
@NotNull @Override public InputStream getNewStream() { try { return blobStore.getInputStream(id); } catch (IOException e) { log.error("Error in getNewStream", e); } return null; }
data = blobStore.getInputStream(blobId); } catch (Exception e) { return true;
@Test public void shouldReturnNullIfBlobDoesNotExist() throws Exception { BlobStore s = mock(BlobStore.class); when(s.getInputStream("id")).thenThrow(new IOException("blob not found")); DefaultStandbyBlobReader r = new DefaultStandbyBlobReader(s); assertNull(r.readBlob("id")); }
@Test(expected = NullPointerException.class) public void getInputStreamShouldAlwaysThrowAnExceptionWhenNullBlobIdIsPassed() throws IOException { given: { final BlobStore store = new LoopbackBlobStore(); when: { store.getInputStream(null); } } }
@Test public void shouldReturnBlobContent() throws Exception { BlobStore s = mock(BlobStore.class); when(s.getInputStream("id")).thenReturn(new ByteArrayInputStream(new byte[]{1, 2, 3})); when(s.getBlobLength("id")).thenReturn(3L); DefaultStandbyBlobReader r = new DefaultStandbyBlobReader(s); assertEquals(3, r.getBlobLength("id")); assertArrayEquals(new byte[]{1, 2, 3}, IOUtils.toByteArray(r.readBlob("id"))); }
@Test public void testGetInputStream() throws IOException { for (String id : oldBlobIds) { assertStreamEquals(oldBlobStore.getInputStream(id), splitBlobStore.getInputStream(id)); } for (String id : newBlobIds) { assertStreamEquals(newBlobStore.getInputStream(id), splitBlobStore.getInputStream(id)); } }
private void assertPropertyOnTheNewStore(Blob blob) throws IOException { String blobId = blob.getContentIdentity(); assertStreamEquals(blob.getNewStream(), newBlobStore.getInputStream(blobId)); }
@Test @Parameters(method = "blobIds") public void shouldAlwaysReturnStreamOfRequestedBlobIdUtf8BinRepresentation( final String blobId) throws IOException { given: { final String encoding = "UTF-8"; final BlobStore store = new LoopbackBlobStore(); when: { final InputStream inputStream = store.getInputStream(blobId); then: { assertNotNull(inputStream); } and: { final String actualInputStreamAsString = IOUtils.toString( inputStream, encoding); then: { assertEquals(actualInputStreamAsString, blobId); } } } } }
@Test public void readOnly() throws Exception{ FileDataStore fds = new FileDataStore(); fds.setPath(temporaryFolder.getRoot().getAbsolutePath()); fds.init(null); DataStoreBlobStore writableBS = new DataStoreBlobStore(fds); BlobStore readOnly = ReadOnlyBlobStoreWrapper.wrap(writableBS); try { readOnly.writeBlob(new ByteArrayInputStream("foo".getBytes())); fail(); } catch (Exception ignore) { } String blobId = writableBS.writeBlob(new ByteArrayInputStream("foo".getBytes())); try(InputStream is = readOnly.getInputStream(blobId)) { assertNotNull(is); } }