Search in sources :

Example 21 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class TestStreamManager method open.

// TriG
// NQuads
private static void open(StreamManager streamMgr, String dataName, Context context) {
    StreamManager.setGlobal(streamMgr);
    try {
        TypedInputStream in = (context != null) ? RDFDataMgr.open(dataName, context) : RDFDataMgr.open(dataName);
        assertNotNull(in);
        IO.close(in);
    } finally {
        StreamManager.setGlobal(streamMgrStd);
    }
}
Also used : TypedInputStream(org.apache.jena.atlas.web.TypedInputStream)

Example 22 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class JenaIOEnvironment method createLocationMapper.

/** Search a path (which is delimited by ";" because ":" is used in URIs)
     *  to find a description of a LocationMapper, then create and return a
     *  LocationMapper based on the description.
     */
public static LocationMapper createLocationMapper(String configPath) {
    if (configPath == null || configPath.length() == 0) {
        log.warn("Null configuration");
        return null;
    }
    // Make a file manager to look for the location mapping file
    StreamManager smgr = new StreamManager();
    smgr.addLocator(new LocatorFile());
    smgr.addLocator(new LocatorClassLoader(smgr.getClass().getClassLoader()));
    try {
        String uriConfig = null;
        TypedInputStream in = null;
        StringTokenizer pathElems = new StringTokenizer(configPath, AdapterFileManager.PATH_DELIMITER);
        while (pathElems.hasMoreTokens()) {
            String uri = pathElems.nextToken();
            if (uri == null || uri.length() == 0)
                break;
            in = smgr.openNoMapOrNull(uri);
            if (in != null) {
                uriConfig = uri;
                break;
            }
        }
        if (in == null) {
            log.debug("Failed to find configuration: " + configPath);
            return null;
        }
        String syntax = FileUtils.guessLang(uriConfig);
        Model model = ModelFactory.createDefaultModel();
        model.read(in, uriConfig, syntax);
        return processConfig(model);
    } catch (JenaException ex) {
        LoggerFactory.getLogger(LocationMapper.class).warn("Error in configuration file: " + ex.getMessage());
        return new LocationMapper();
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) StringTokenizer(java.util.StringTokenizer) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream)

Example 23 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class LocatorFTP method performOpen.

@Override
public TypedInputStream performOpen(String uri) {
    if (uri.startsWith("ftp://")) {
        try {
            URL url = new URL(uri);
            InputStream in = url.openStream();
            ContentType ct = RDFLanguages.guessContentType(uri);
            return new TypedInputStream(in, ct);
        } catch (MalformedURLException ex) {
            throw new RiotException("Bad FTP URL: " + uri, ex);
        } catch (IOException ex) {
            // This includes variations on "not found"
            IO.exception(ex);
        }
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) ContentType(org.apache.jena.atlas.web.ContentType) RiotException(org.apache.jena.riot.RiotException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) URL(java.net.URL)

Example 24 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class LocatorZip method open.

@Override
public TypedInputStream open(String filenameOrURI) {
    ZipEntry entry = zipFile.getEntry(filenameOrURI);
    if (entry == null) {
        if (StreamManager.logAllLookups && log.isDebugEnabled())
            log.debug("Not found: " + zipFileName + " : " + filenameOrURI);
        return null;
    }
    try {
        InputStream in = zipFile.getInputStream(entry);
        if (in == null) {
            if (StreamManager.logAllLookups && log.isTraceEnabled())
                log.trace("Not found: " + filenameOrURI);
            return null;
        }
        if (StreamManager.logAllLookups && log.isTraceEnabled())
            log.trace("Found: " + filenameOrURI);
        ContentType ct = RDFLanguages.guessContentType(filenameOrURI);
        return new TypedInputStream(in, ct, filenameOrURI);
    } catch (IOException ex) {
        log.warn("IO Exception opening zip entry: " + filenameOrURI);
        return null;
    }
}
Also used : ContentType(org.apache.jena.atlas.web.ContentType) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream)

Example 25 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class TestLocators method locatorFile_05.

@Test
public void locatorFile_05() {
    LocatorFile loc = new LocatorFile();
    TypedInputStream ts = loc.open(testingDir + "data.ttl");
    assertTrue("Not equal: " + WebContent.contentTypeTurtle + " != " + ts.getMediaType(), WebContent.contentTypeTurtle.equalsIgnoreCase(ts.getContentType()));
}
Also used : LocatorFile(org.apache.jena.riot.system.stream.LocatorFile) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)32 Test (org.junit.Test)11 BaseTest (org.apache.jena.atlas.junit.BaseTest)8 HttpException (org.apache.jena.atlas.web.HttpException)7 ContentType (org.apache.jena.atlas.web.ContentType)6 InputStream (java.io.InputStream)4 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)4 HttpClient (org.apache.http.client.HttpClient)4 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 JsonValue (org.apache.jena.atlas.json.JsonValue)3 HttpEntity (org.apache.http.HttpEntity)2 Credentials (org.apache.http.auth.Credentials)2 FusekiTestAuth.assertAuthHttpException (org.apache.jena.fuseki.embedded.FusekiTestAuth.assertAuthHttpException)2 Model (org.apache.jena.rdf.model.Model)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 NoSuchFileException (java.nio.file.NoSuchFileException)1 AccessControlException (java.security.AccessControlException)1