@Override public String writeBlob(InputStream in) throws IOException { String blobId = newBlobStore.writeBlob(in); migratedBlobs.add(blobId); return blobId; }
@Override public long length() { try { return blobStore.getBlobLength(blobId); } catch (IOException e) { throw new IllegalArgumentException("Invalid blob id: " + blobId, e); } }
@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; }
private void testBlobIdWithLength(int blobIdLength) throws Exception { String blobId = Strings.repeat("x", blobIdLength); long blobLength = SegmentTestConstants.MEDIUM_LIMIT; doReturn(blobId).when(blobStore).writeBlob(any(InputStream.class)); doReturn(blobLength).when(blobStore).getBlobLength(blobId); SegmentBlob blob = new SegmentBlob(blobStore, fileStore.getWriter().writeStream(newRandomInputStream(blobLength))); assertEquals(blobLength, blob.length()); }
@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); } }
@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"))); }
@Override public int read(byte[] b, int off, int len) throws IOException { int l; try { l = store.readBlob(id, pos, b, off, len); } catch (Exception e) { throw new IOException(e); } if (l < 0) { return l; } pos += l; return l; }
@Override public String getBlobId(String reference) { if (reference.startsWith(NEW_BLOBSTORE_PREFIX)) { return newBlobStore.getBlobId(reference.substring(NEW_BLOBSTORE_PREFIX.length())); } else if (reference.startsWith(OLD_BLOBSTORE_PREFIX)) { return oldBlobStore.getBlobId(reference.substring(OLD_BLOBSTORE_PREFIX.length())); } else { log.error("Invalid reference: {}", reference); return null; } }
@Override @Nullable public String getReference() { return blobStore.getReference(blobId); }
@Override public int read(byte[] b, int off, int len) throws IOException { int l; try { l = store.readBlob(id, pos, b, off, len); } catch (Exception e) { throw new IOException(e); } if (l < 0) { return l; } pos += l; return l; }
@Override public String getBlobId(String reference) { if (reference.startsWith(NEW_BLOBSTORE_PREFIX)) { return newBlobStore.getBlobId(reference.substring(NEW_BLOBSTORE_PREFIX.length())); } else if (reference.startsWith(OLD_BLOBSTORE_PREFIX)) { return oldBlobStore.getBlobId(reference.substring(OLD_BLOBSTORE_PREFIX.length())); } else { log.error("Invalid reference: {}", reference); return null; } }
@Override @Nullable public String getReference() { return blobStore.getReference(blobId); }
private void writeBlob(String blobId, InputStream stream) { try { blobStore.writeBlob(stream); } catch (IOException e) { throw new BlobWriteException(blobId, e); } }
@Override public long length() { try { return blobStore.getBlobLength(blobId); } catch (IOException e) { throw new IllegalArgumentException("Invalid blob id: " + 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 int read(byte[] b, int off, int len) throws IOException { int l; try { l = store.readBlob(id, pos, b, off, len); } catch (Exception e) { throw new IOException(e); } if (l < 0) { return l; } pos += l; return l; }
@Override public String getBlobId(String reference) { if (reference.startsWith(NEW_BLOBSTORE_PREFIX)) { return newBlobStore.getBlobId(reference.substring(NEW_BLOBSTORE_PREFIX.length())); } else if (reference.startsWith(OLD_BLOBSTORE_PREFIX)) { return oldBlobStore.getBlobId(reference.substring(OLD_BLOBSTORE_PREFIX.length())); } else { log.error("Invalid reference: {}", reference); return null; } }
@Override @CheckForNull public String getReference() { return blobStore.getReference(blobId); }
@Override public String writeBlob(InputStream in) throws IOException { String blobId = newBlobStore.writeBlob(in); migratedBlobs.add(blobId); return blobId; }
@Override public long length() { try { return blobStore.getBlobLength(blobId); } catch (IOException e) { throw new IllegalArgumentException("Invalid blob id: " + blobId, e); } }