/** * Get the {@link CloseableHttpClient} which will be used by this * DocumentLoader to resolve HTTP and HTTPS resources. * * @return The {@link CloseableHttpClient} which this DocumentLoader uses. */ public CloseableHttpClient getHttpClient() { CloseableHttpClient result = httpClient; if (result == null) { synchronized (DocumentLoader.class) { result = httpClient; if (result == null) { result = httpClient = JsonUtils.getDefaultHttpClient(); } } } return result; }
/** * Get the {@link CloseableHttpClient} which will be used by this * DocumentLoader to resolve HTTP and HTTPS resources. * * @return The {@link CloseableHttpClient} which this DocumentLoader uses. */ public CloseableHttpClient getHttpClient() { CloseableHttpClient result = httpClient; if (result == null) { synchronized (DocumentLoader.class) { result = httpClient; if (result == null) { result = httpClient = JsonUtils.getDefaultHttpClient(); } } } return result; }
private Object readSource() throws IOException { // Due to checked IOException we can't easily // do this with .map and .orElseGet() if (getSourceInputStream().isPresent()) { return JsonUtils.fromInputStream(getSourceInputStream().get()); } if (getSourceIri().isPresent()) { // TODO: propagate @base from content return JsonUtils.fromURL(asURL(getSourceIri().get()), JsonUtils.getDefaultHttpClient()); } if (getSourceFile().isPresent()) { try (InputStream inputStream = Files.newInputStream(getSourceFile().get())) { return JsonUtils.fromInputStream(inputStream); } } throw new IllegalStateException("No known source found"); }
@Ignore("Github is frequently unavailable from TravisCI") @Test public final void testPrettyPrintURL() throws Exception { StringWriter output = new StringWriter(); try (InputStream inputStream = JSONUtil .openStreamForURL(new java.net.URL("https://api.github.com/repos/ansell/csvsum" // "http://bie.ala.org.au/search.json?q=Banksia+occidentalis" ), JsonUtils.getDefaultHttpClient()); Reader input = new BufferedReader(new InputStreamReader(inputStream));) { JSONStreamUtil.toPrettyPrint(input, output); } System.out.println(output.toString()); String avatar = JSONStreamUtil.queryJSON(new StringReader(output.toString()), "/owner/avatar_url"); assertTrue(avatar, avatar.contains(".githubusercontent.com/")); assertTrue(avatar, avatar.startsWith("https://avatar")); // JSONUtil.queryJSON( // "http://bie.ala.org.au/search.json?q=Banksia+occidentalis", // "/searchResults/results/0/guid"); }
@Test public void toRdfWithNamespace() throws Exception { final URL contextUrl = getClass().getResource("/custom/contexttest-0003.jsonld"); assertNotNull(contextUrl); final Object context = JsonUtils.fromURL(contextUrl, JsonUtils.getDefaultHttpClient()); assertNotNull(context); final JsonLdOptions options = new JsonLdOptions(); options.useNamespaces = true; final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(context, options); // System.out.println(rdf.getNamespaces()); assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat")); assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev")); }
final Object context = JsonUtils.fromURL(contextUrl, JsonUtils.getDefaultHttpClient()); assertNotNull(context); assertNotNull(arrayContextUrl); final Object arrayContext = JsonUtils.fromURL(arrayContextUrl, JsonUtils.getDefaultHttpClient()); assertNotNull(arrayContext); final JsonLdOptions options = new JsonLdOptions();