private ReferencedData storeOrSerialize(InputStream stream, String dataStoreRef, DataStore store, int dataSize, int resultSizeLimit) throws IOException, DataStoreException { if (dataSize < resultSizeLimit) { return ReferencedData.getWrappedData(IOUtils.toByteArray(stream)); } else { return ReferencedData.getReferencedData(store.store(stream, dataStoreRef)); } } }
/** * 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); } } }
@Override public long getDataSize(final String ref) throws DataSourceException { try { return store.size(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 String storeDocument(InputStream contentToStore) throws DataStoreException { DataStore store = getFsDataStore(); return store.store(contentToStore, properties.getDataStorePartialReference()); }
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); } }
/** * Either wraps or store in the data store the selected content. * * @param content the content to wrap or store. * @return A ReferencedData object containing either the wrapped bytes or data store reference. * @throws DataStoreException */ public ReferencedData wrapOrStoreData(byte[] content) throws DataStoreException { if (content.length > resultSizeLimit) { return ReferencedData.getReferencedData(dataStore.store(content, dataStoreReference)); } else { return ReferencedData.getWrappedData(content); } }
@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); } }
@Override public TTask createTask(TestItem<TInput, TExpected> testItem) throws Exception { ReferencedData sourceData; if (!Strings.isNullOrEmpty(overrideReference)) { testItem.getInputData().setStorageReference(overrideReference); sourceData = ReferencedData.getReferencedData(overrideReference); } else if (!Strings.isNullOrEmpty(testItem.getInputData().getStorageReference())) { sourceData = ReferencedData.getReferencedData(testItem.getInputData().getStorageReference()); } else { Path inputFile = Paths.get(testItem.getInputData().getInputFile()); if (Files.notExists(inputFile) && !Strings.isNullOrEmpty(testSourcefileBaseFolder)) { inputFile = Paths.get(testSourcefileBaseFolder, testItem.getInputData().getInputFile()); } if (Files.notExists(inputFile)) { inputFile = Paths.get(testFilesFolder, testItem.getInputData().getInputFile()); } if (testItem.getInputData().isUseDataStore()) { try (InputStream inputStream = Files.newInputStream(inputFile)) { String reference = dataStore.store(inputStream, containerId); sourceData = ReferencedData.getReferencedData(reference); inputStream.close(); } } else { byte[] fileContent = Files.readAllBytes(inputFile); sourceData = ReferencedData.getWrappedData(fileContent); } } return createTask(testItem, sourceData); }
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; }
metadata.put("content", String.valueOf(1L)); String storedDataLocation = store.store(new ByteArrayInputStream(condition.value.getBytes()), properties.getDataStorePartialReference());