@Override public String writeBlob(String tempFileName) throws IOException { File file = new File(tempFileName); InputStream in = null; try { in = new FileInputStream(file); return writeBlob(in); } finally { closeQuietly(in); FileUtils.forceDelete(file); } }
@Override public String writeBlob(String tempFileName) throws IOException { File file = new File(tempFileName); InputStream in = null; try { in = new FileInputStream(file); return writeBlob(in); } finally { closeQuietly(in); FileUtils.forceDelete(file); } }
@Override public String writeBlob(String tempFileName) throws IOException { File file = new File(tempFileName); InputStream in = null; try { in = new FileInputStream(file); return writeBlob(in); } finally { closeQuietly(in); FileUtils.forceDelete(file); } }
@Override public String writeBlob(InputStream stream) throws IOException { return writeBlob(stream, new BlobOptions()); }
@Override public String writeBlob(InputStream stream) throws IOException { return writeBlob(stream, new BlobOptions()); }
@Override public String writeBlob(InputStream stream) throws IOException { return writeBlob(stream, new BlobOptions()); }
@Override public String serialize(Blob blob) { try (InputStream is = blob.getNewStream()) { return dataStore.writeBlob(is); } catch (Exception e) { log.warn("Error occurred while serializing Blob with id {}", blob.getContentIdentity(), e); return String.format("%s%s", ERROR_MARKER, blob.getContentIdentity()); } }
@Override public String serialize(Blob blob) { try (InputStream is = blob.getNewStream()) { return dataStore.writeBlob(is); } catch (Exception e) { log.warn("Error occurred while serializing Blob with id {}", blob.getContentIdentity(), e); return String.format("%s%s", ERROR_MARKER, blob.getContentIdentity()); } }
@Override public String serialize(Blob blob) { try (InputStream is = blob.getNewStream()) { return dataStore.writeBlob(is); } catch (Exception e) { log.warn("Error occurred while serializing Blob with id {}", blob.getContentIdentity(), e); return String.format("%s%s", ERROR_MARKER, blob.getContentIdentity()); } }
@Test public void testAddOnTrackError() throws Exception { int maxInlineSize = 300; byte[] data = new byte[maxInlineSize]; new Random().nextBytes(data); DataStore mockedDS = mock(DataStore.class); when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); BlobIdTracker mockedTracker = mock(BlobIdTracker.class); doThrow(new IOException("Mocking tracking error")).when(mockedTracker).add(any(String.class)); ds.addTracker(mockedTracker); String id = ds.writeBlob(new ByteArrayInputStream(data)); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), ds.getInputStream(id))); }
@Test public void testGetAllChunkIds() throws Exception { File rootFolder = folder.newFolder(); dataStore = getBlobStore(rootFolder); int number = 10; Set<String> added = newHashSet(); for (int i = 0; i < number; i++) { String rec = dataStore.writeBlob(randomStream(i, 16516)); added.add(rec); } Set<String> retrieved = newHashSet(dataStore.getAllChunkIds(0)); assertEquals(added, retrieved); }
@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 inMemoryRecord() throws Exception{ File fdsDir = temporaryFolder.newFolder(); FileDataStore fds = DataStoreUtils.createFDS(fdsDir, 10000); DataStoreBlobStore dbs = new DataStoreBlobStore(fds); ByteArrayInputStream is = new ByteArrayInputStream("".getBytes()); String blobId = dbs.writeBlob(is); File writerDir = temporaryFolder.newFolder(); PreExtractedTextProvider textProvider = new DataStoreTextWriter(writerDir, true); assertNull(textProvider.getText("/content", new BlobStoreBlob(dbs, blobId))); }
assertEquals(testDI.toString(), BlobId.of(ds.writeBlob(new ByteArrayInputStream(data))).blobId);
@Test public void testInlineBinary() throws DataStoreException, IOException { int maxInlineSize = 300; DataStore mockedDS = mock(DataStore.class); when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); byte[] data = new byte[maxInlineSize]; new Random().nextBytes(data); DataRecord dr = ds.addRecord(new ByteArrayInputStream(data)); assertTrue(InMemoryDataRecord.isInstance(dr.getIdentifier().toString())); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), dr.getStream())); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), new BlobStoreInputStream(ds, dr.getIdentifier().toString(), 0))); assertEquals(dr, ds.getRecordIfStored(dr.getIdentifier())); assertEquals(dr, ds.getRecord(dr.getIdentifier())); //Check for BlobStore methods assertEquals(maxInlineSize, ds.getBlobLength(dr.getIdentifier().toString())); assertEquals(dr.getIdentifier().toString(), BlobId.of(ds.writeBlob(new ByteArrayInputStream(data))).blobId); }
fds.init(new File(tempFolder.getRoot(), "fdsRoot").getAbsolutePath()); DataStoreBlobStore dsbs = new DataStoreBlobStore(fds); BlobFactory factory = in -> new BlobStoreBlob(dsbs, dsbs.writeBlob(in));