Interface IO


  • public interface IO

    IO interface for reading RDF data from various input sources.

    This interface is usually used in conjunction with Adder or Remover to specify the RDF to be added/removed from the parent Connection

    The IO object is stateful in that once you set the context(Resource) context} and/or format(RDFFormat) format, you can repeatedly use the object to read in RDF from a file(Path) file} or stream using the same context/format.

    Usage

    Connection aConn = // obtain connection aConn.add().io().format(RDFFormat.TURTLE).file(new File("mydata.ttl")); // reuse the object URI aContext = Values.uri("urn:context"); IO aIO = aConn.add().io(); aIO.format(RDFFormat.TURTLE) .context(aCxt); Collection<File> aFiles = // get file list for (File aFile : aFiles) { // this will parse the file using the Turtle parser & put the resulting RDF // into the previously specified context. aIO.file(aFile); }
    Since:
    0.3
    Version:
    6.0
    Author:
    Michael Grove
    See Also:
    Adder, Remover
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      IO context​(Resource theContext)
      Set the context that will be applied to all statements created when the RDF is read in from the specified IO source.
      IO file​(java.nio.file.Path theFile)
      Load RDF data from this file.
      IO format​(RDFFormat theFormat)
      Specify that subsequent IO operations with this class will be parsed using this RDF format.
      IO serverSide()
      Normally, it is assumed that a file(Path) file} resides on the same machine as the client.
      IO stream​(java.io.InputStream theStream)
      Read RDF data from the provided InputStream.
    • Method Detail

      • format

        IO format​(RDFFormat theFormat)
           throws StardogException
        Specify that subsequent IO operations with this class will be parsed using this RDF format.
        Parameters:
        theFormat - the RDF format to use
        Returns:
        this IO
        Throws:
        StardogException - if there is an error
      • stream

        IO stream​(java.io.InputStream theStream)
           throws StardogException

        Read RDF data from the provided InputStream. You must have specified a format(RDFFormat) before reading the RDF data.

        The stream is closed after the content is parsed.

        Parameters:
        theStream - the stream
        Returns:
        this IO
        Throws:
        StardogException - if there is an error
        See Also:
        format(RDFFormat)
      • file

        IO file​(java.nio.file.Path theFile)
         throws StardogException

        Load RDF data from this file. If no format(RDFFormat) format} is specified a format will be guessed based on the file extension. If the path points to a directory all the files in that directory will be loaded recursively. If no format is specified then only the files in the directory with a recognized file extension will be loaded.

        Parameters:
        theFile - the file to load from
        Returns:
        this IO
        Throws:
        StardogException - if there was an error
        See Also:
        format(RDFFormat)
      • context

        IO context​(Resource theContext)
            throws StardogException

        Set the context that will be applied to all statements created when the RDF is read in from the specified IO source. If you are using an RDF format which specifies a context, such as Trig or NQuads, the context on the parsed statements will override any specified context value.

        Parameters:
        theContext - the context for the statements
        Returns:
        this IO
        Throws:
        StardogException - if there was an error setting the context
      • serverSide

        IO serverSide()

        Normally, it is assumed that a file(Path) file} resides on the same machine as the client. When this option is enabled, the Connection will assume the file is located on the server so that only the reference to the file, rather than its contents, needs to be sent to the server.

        Returns:
        this IO