View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *  http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.any23.writer;
19  
20  import org.eclipse.rdf4j.model.IRI;
21  import org.eclipse.rdf4j.model.Resource;
22  import org.eclipse.rdf4j.model.Value;
23  
24  /**
25   * Base interface for triple writers that don't need an extraction context to write triples
26   *
27   * @author Hans Brende (hansbrende@apache.org)
28   */
29  public interface TripleWriter extends AutoCloseable {
30  
31      /**
32       * Writes a triple and, optionally, a graph resource name.
33       * @param s the subject to write
34       * @param p the predicate to write
35       * @param o the object to write
36       * @param g the graph name to write, or null
37       * @throws TripleHandlerException if there is an error writing the triple
38       */
39      void writeTriple(Resource s, IRI p, Value o, Resource g) throws TripleHandlerException;
40  
41      /**
42       * Writes a prefix-namespace mapping. <br><b>NOTE:</b> this method should be called
43       * <b>before</b> writing out any triples. Calling this method <b>after</b> writing
44       * out a triple may result in the prefix-namespace mapping being ignored.
45       * @param prefix the namespace prefix
46       * @param uri the namespace uri
47       * @throws TripleHandlerException if there was an error writing out the prefix-namespace mapping
48       */
49      void writeNamespace(String prefix, String uri) throws TripleHandlerException;
50  
51      /**
52       * Releases resources associated with this {@link TripleWriter}, and flushes (but by default does not close)
53       * any underlying {@link java.io.OutputStream}s. Future invocations of methods of this writer
54       * produce <b>undefined behavior</b> after this method has been called.
55       * @throws TripleHandlerException if there was an error closing this {@link TripleWriter}
56       */
57      @Override
58      void close() throws TripleHandlerException;
59  
60  }