@Test void testWriteMementoBadDirectory() { final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + "resource"); final File file = new File(getClass().getResource("/resource.nq").getFile()); final Resource res = new FileResource(identifier, file); final File dir = new File(file.getParentFile(), "nonexistent"); final Instant time = now(); assertThrows(UncheckedIOException.class, () -> FileUtils.writeMemento(dir, res, time)); }
public static void writeMemento(final File resourceDir, final Resource resource, final Instant time) { try (final BufferedWriter writer = newBufferedWriter( getNquadsFile(resourceDir, time).toPath(), UTF_8, CREATE, WRITE, TRUNCATE_EXISTING)) { try (final Stream<String> quads = generateServerManaged(resource).map(FileUtils::serializeQuad)) { final Iterator<String> lineIter = quads.iterator(); while (lineIter.hasNext()) { writer.write(lineIter.next() + lineSeparator()); } } try (final Stream<String> quads = resource.stream().filter(FileUtils::notServerManaged) .map(FileUtils::serializeQuad)) { final Iterator<String> lineiter = quads.iterator(); while (lineiter.hasNext()) { writer.write(lineiter.next() + lineSeparator()); } } } catch (final IOException ex) { throw new UncheckedIOException( "Error writing resource version for " + resource.getIdentifier().getIRIString(), ex); } }
FileUtils { public static void writeMemento(final File resourceDir, final Resource resource, final Instant time) { try (final BufferedWriter writer = newBufferedWriter( getNquadsFile(resourceDir, time).toPath(), UTF_8, CREATE, WRITE, TRUNCATE_EXISTING)) { try (final Stream<String> quads = generateServerManaged(resource).map(FileUtils::serializeQuad)) { final Iterator<String> lineIter = quads.iterator(); while (lineIter.hasNext()) { writer.write(lineIter.next() + lineSeparator()); } } try (final Stream<String> quads = resource.stream().filter(FileUtils::notServerManaged) .map(FileUtils::serializeQuad)) { final Iterator<String> lineiter = quads.iterator(); while (lineiter.hasNext()) { writer.write(lineiter.next() + lineSeparator()); } } } catch (final IOException ex) { throw new UncheckedIOException( "Error writing resource version for " + resource.getIdentifier().getIRIString(), ex); } } }
FileUtils { public static void writeMemento(final File resourceDir, final Resource resource, final Instant time) { try (final BufferedWriter writer = newBufferedWriter( getNquadsFile(resourceDir, time).toPath(), UTF_8, CREATE, WRITE, TRUNCATE_EXISTING)) { try (final Stream<String> quads = generateServerManaged(resource).map(FileUtils::serializeQuad)) { final Iterator<String> lineIter = quads.iterator(); while (lineIter.hasNext()) { writer.write(lineIter.next() + lineSeparator()); } } try (final Stream<String> quads = resource.stream().filter(FileUtils::notServerManaged) .map(FileUtils::serializeQuad)) { final Iterator<String> lineiter = quads.iterator(); while (lineiter.hasNext()) { writer.write(lineiter.next() + lineSeparator()); } } } catch (final IOException ex) { throw new UncheckedIOException( "Error writing resource version for " + resource.getIdentifier().getIRIString(), ex); } } private  FileUtils(); }
FileUtils { public static void writeMemento(final File resourceDir, final Resource resource, final Instant time) { try (final BufferedWriter writer = newBufferedWriter( getNquadsFile(resourceDir, time).toPath(), UTF_8, CREATE, WRITE, TRUNCATE_EXISTING)) { try (final Stream<String> quads = generateServerManaged(resource).map(FileUtils::serializeQuad)) { final Iterator<String> lineIter = quads.iterator(); while (lineIter.hasNext()) { writer.write(lineIter.next() + lineSeparator()); } } try (final Stream<String> quads = resource.stream().filter(FileUtils::notServerManaged) .map(FileUtils::serializeQuad)) { final Iterator<String> lineiter = quads.iterator(); while (lineiter.hasNext()) { writer.write(lineiter.next() + lineSeparator()); } } } catch (final IOException ex) { throw new UncheckedIOException( "Error writing resource version for " + resource.getIdentifier().getIRIString(), ex); } } private  FileUtils(); static File getResourceDirectory(final File baseDirectory, final IRI identifier); static Stream<Quad> parseQuad(final String line); static boolean filterServerManagedQuads(final Quad quad); static boolean uncheckedDeleteIfExists(final Path path); static Stream<Path> uncheckedList(final Path path); static void writeMemento(final File resourceDir, final Resource resource,
            final Instant time); static InputStream getBoundedStream(final InputStream stream, final int from, final int to); static String serializeQuad(final Quad quad); static File getNquadsFile(final File dir, final Instant time); }
FileUtils { public static void writeMemento(final File resourceDir, final Resource resource, final Instant time) { try (final BufferedWriter writer = newBufferedWriter( getNquadsFile(resourceDir, time).toPath(), UTF_8, CREATE, WRITE, TRUNCATE_EXISTING)) { try (final Stream<String> quads = generateServerManaged(resource).map(FileUtils::serializeQuad)) { final Iterator<String> lineIter = quads.iterator(); while (lineIter.hasNext()) { writer.write(lineIter.next() + lineSeparator()); } } try (final Stream<String> quads = resource.stream().filter(FileUtils::notServerManaged) .map(FileUtils::serializeQuad)) { final Iterator<String> lineiter = quads.iterator(); while (lineiter.hasNext()) { writer.write(lineiter.next() + lineSeparator()); } } } catch (final IOException ex) { throw new UncheckedIOException( "Error writing resource version for " + resource.getIdentifier().getIRIString(), ex); } } private  FileUtils(); static File getResourceDirectory(final File baseDirectory, final IRI identifier); static Stream<Quad> parseQuad(final String line); static boolean filterServerManagedQuads(final Quad quad); static boolean uncheckedDeleteIfExists(final Path path); static Stream<Path> uncheckedList(final Path path); static void writeMemento(final File resourceDir, final Resource resource,
            final Instant time); static InputStream getBoundedStream(final InputStream stream, final int from, final int to); static String serializeQuad(final Quad quad); static File getNquadsFile(final File dir, final Instant time); static final String CONFIG_FILE_LDP_TYPE; static final String CONFIG_FILE_DIGEST_ALGORITHM; static final int LENGTH; static final int MAX; }