All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openrdf.repository.object.advisers.SparqlQueryResolver Maven / Gradle / Ivy

Go to download

The Object Repository maps Java objects to and from RDF resources and OWL classes to Java classes in a non-intrusive manner that enables developers to work at the object level.

The newest version!
package org.openrdf.repository.object.advisers;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.GZIPInputStream;

import org.openrdf.query.MalformedQueryException;

public class SparqlQueryResolver {
	private static SparqlQueryResolver instance = new SparqlQueryResolver();

	public static synchronized SparqlQueryResolver getInstance() {
		return instance;
	}

	public static synchronized void setInstance(SparqlQueryResolver resolver) {
		instance = resolver;
	}

	public SparqlQuery resolve(String systemId) throws IOException,
			MalformedQueryException {
		URLConnection con = new URL(systemId).openConnection();
		con.addRequestProperty("Accept", "application/sparql-query");
		con.addRequestProperty("Accept-Encoding", "gzip");
		String encoding = con.getHeaderField("Content-Encoding");
		InputStream in = con.getInputStream();
		String base = con.getURL().toExternalForm();
		if (encoding != null && encoding.contains("gzip")) {
			in = new GZIPInputStream(in);
		}
		InputStreamReader reader = new InputStreamReader(in, "UTF-8");
		try {
			return new SparqlQuery(reader, base);
		} finally {
			reader.close();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy