@Test void testSetFileContentError() { final InputStream throwingMockInputStream = mock(InputStream.class, inv -> { throw new IOException("Expected error"); }); final BinaryService service = new FileBinaryService(); final IRI fileIRI = rdf.createIRI("file: assertAll(() -> service.setContent(BinaryMetadata.builder(fileIRI).build(), throwingMockInputStream) .handle((val, err) -> { assertNotNull(err, "There should have been an error with the input stream!"); return null; }).toCompletableFuture().join()); }
@Override public CompletionStage<Void> setContent(final BinaryMetadata metadata, final InputStream stream) { requireNonNull(stream, "InputStream may not be null!"); return supplyAsync(() -> { final File file = getFileFromIdentifier(metadata.getIdentifier()); LOGGER.debug("Setting binary content for {} at {}", metadata.getIdentifier(), file.getAbsolutePath()); try (final InputStream input = stream) { final File parent = file.getParentFile(); parent.mkdirs(); copy(stream, file.toPath(), REPLACE_EXISTING); } catch (final IOException ex) { throw new UncheckedIOException("Error while setting content for " + metadata.getIdentifier(), ex); } return null; }); }
FileBinaryService implements BinaryService { @Override public CompletionStage<Void> setContent(final BinaryMetadata metadata, final InputStream stream) { requireNonNull(stream, "InputStream may not be null!"); return supplyAsync(() -> { final File file = getFileFromIdentifier(metadata.getIdentifier()); LOGGER.debug("Setting binary content for {} at {}", metadata.getIdentifier(), file.getAbsolutePath()); try (final InputStream input = stream) { final File parent = file.getParentFile(); parent.mkdirs(); copy(stream, file.toPath(), REPLACE_EXISTING); } catch (final IOException ex) { throw new UncheckedIOException("Error while setting content for " + metadata.getIdentifier(), ex); } return null; }); } }
FileBinaryService implements BinaryService { @Override public CompletionStage<Void> setContent(final BinaryMetadata metadata, final InputStream stream) { requireNonNull(stream, "InputStream may not be null!"); return supplyAsync(() -> { final File file = getFileFromIdentifier(metadata.getIdentifier()); LOGGER.debug("Setting binary content for {} at {}", metadata.getIdentifier(), file.getAbsolutePath()); try (final InputStream input = stream) { final File parent = file.getParentFile(); parent.mkdirs(); copy(stream, file.toPath(), REPLACE_EXISTING); } catch (final IOException ex) { throw new UncheckedIOException("Error while setting content for " + metadata.getIdentifier(), ex); } return null; }); } FileBinaryService(); @Inject  FileBinaryService(final IdentifierService idService);  FileBinaryService(final IdentifierService idService, final String basePath,
            final int hierarchy, final int length); private  FileBinaryService(final IdentifierService idService, final Config config); }
FileBinaryService implements BinaryService { @Override public CompletionStage<Void> setContent(final BinaryMetadata metadata, final InputStream stream) { requireNonNull(stream, "InputStream may not be null!"); return supplyAsync(() -> { final File file = getFileFromIdentifier(metadata.getIdentifier()); LOGGER.debug("Setting binary content for {} at {}", metadata.getIdentifier(), file.getAbsolutePath()); try (final InputStream input = stream) { final File parent = file.getParentFile(); parent.mkdirs(); copy(stream, file.toPath(), REPLACE_EXISTING); } catch (final IOException ex) { throw new UncheckedIOException("Error while setting content for " + metadata.getIdentifier(), ex); } return null; }); } FileBinaryService(); @Inject  FileBinaryService(final IdentifierService idService);  FileBinaryService(final IdentifierService idService, final String basePath,
            final int hierarchy, final int length); private  FileBinaryService(final IdentifierService idService, final Config config); @Override CompletionStage<Binary> get(final IRI identifier); @Override CompletionStage<Void> purgeContent(final IRI identifier); @Override CompletionStage<Void> setContent(final BinaryMetadata metadata, final InputStream stream); @Override String generateIdentifier(final IRI identifier); }
FileBinaryService implements BinaryService { @Override public CompletionStage<Void> setContent(final BinaryMetadata metadata, final InputStream stream) { requireNonNull(stream, "InputStream may not be null!"); return supplyAsync(() -> { final File file = getFileFromIdentifier(metadata.getIdentifier()); LOGGER.debug("Setting binary content for {} at {}", metadata.getIdentifier(), file.getAbsolutePath()); try (final InputStream input = stream) { final File parent = file.getParentFile(); parent.mkdirs(); copy(stream, file.toPath(), REPLACE_EXISTING); } catch (final IOException ex) { throw new UncheckedIOException("Error while setting content for " + metadata.getIdentifier(), ex); } return null; }); } FileBinaryService(); @Inject  FileBinaryService(final IdentifierService idService);  FileBinaryService(final IdentifierService idService, final String basePath,
            final int hierarchy, final int length); private  FileBinaryService(final IdentifierService idService, final Config config); @Override CompletionStage<Binary> get(final IRI identifier); @Override CompletionStage<Void> purgeContent(final IRI identifier); @Override CompletionStage<Void> setContent(final BinaryMetadata metadata, final InputStream stream); @Override String generateIdentifier(final IRI identifier); static final String CONFIG_FILE_BINARY_PATH; static final String CONFIG_FILE_BINARY_HIERARCHY; static final String CONFIG_FILE_BINARY_LENGTH; }