/** * Opens an InputStream for reading data from a remote data store. * * @param dataStore the remote data store that the data is to be read from * @param reference the reference to the data within the remote data store * @return a new InputStream which can be used for reading the data * @throws IOException if the data cannot be opened for reading */ @Nonnull public static InputStream openInputStream(final DataStore dataStore, final String reference) throws IOException { try { return dataStore.retrieve(reference); } catch (final DataStoreException ex) { throw new IOException(ex); } } }
private byte[] getBytes(final DocumentWorkerFieldEncoding encoding, final String data) throws DataStoreException, IOException { final String nonNullData = nullToEmpty(data); switch (nullToUtf8(encoding)) { case storage_ref: return IOUtils.toByteArray(dataStore.retrieve(nonNullData)); case base64: return Base64.getDecoder().decode(nonNullData); default: //utf8 return nonNullData.getBytes(StandardCharsets.UTF_8); } }
@Override public InputStream getStream(final String ref) throws DataSourceException { try { return store.retrieve(ref); } catch (ReferenceNotFoundException e) { throw new SourceNotFoundException("Reference not found: " + ref, e); } catch (DataStoreException e) { throw new DataSourceException("Failed to get data stream", e); } }
private ContentFileTestExpectation getContentExpectation(final String storageRef, final String fieldName, final TestItem<TTestInput, DocumentWorkerTestExpectation> testItem) { final ContentFileTestExpectation expectation = new ContentFileTestExpectation(); try (InputStream dataStream = workerServices.getDataStore().retrieve(storageRef)) { final Path contentFile = saveContentFile(testItem, testItem.getTag(), fieldName, dataStream); expectation.setExpectedContentFile(contentFile.toString()); expectation.setComparisonType(ContentComparisonType.BINARY); expectation.setExpectedSimilarityPercentage(100); } catch (final DataStoreException | IOException e) { System.out.print("Failed To get data stream :" + e.toString()); } return expectation; }