/** * Helper method to use to create a lambda for * {@link Optional#orElseThrow(Supplier)} to indicate a format is * unsupported. * * @param unsupportedFormat * The format that was not found. * @return A lambda that can be used to generate an exception if the format * is not found. */ public static Supplier<UnsupportedRDFormatException> unsupportedFormat(RDFFormat unsupportedFormat) { return () -> new UnsupportedRDFormatException("Did not recognise RDF format object " + unsupportedFormat); }
/** * Write contents of graph to writer using N3 serialization * * @param graph * @param writer */ public static void writeStatements(Collection<Statement> statements, OutputStream outputStream) { try { RDFWriter writer= Rio.createWriter(RDFFormat.N3, outputStream); writer.startRDF(); for(Statement statement:statements) { writer.handleStatement(statement); } writer.endRDF(); } catch (UnsupportedRDFormatException e) { e.printStackTrace(); } catch (RDFHandlerException e) { e.printStackTrace(); } }
/** * Helper method to use to create a lambda for * {@link Optional#orElseThrow(Supplier)} to indicate a format is * unsupported. * * @param unsupportedFormat * The format that was not found. * @return A lambda that can be used to generate an exception if the format * is not found. */ public static Supplier<UnsupportedRDFormatException> unsupportedFormat(String unsupportedFormat) { return () -> new UnsupportedRDFormatException("Did not recognise RDF format string " + unsupportedFormat); } }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, matcher); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, matcher); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matchers the Matchers to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ @SafeVarargs public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V>... matchers) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matchers the Matchers to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ @SafeVarargs public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V>... matchers) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher1 the Matcher to wrap * @param matcher2 the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher1, Matcher<V> matcher2) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher1 the Matcher to wrap * @param matcher2 the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher1, Matcher<V> matcher2) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); }
throw new UnsupportedRDFormatException(errInfo.getErrorMessage());