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 *
34 * @param s
35 * the subject to write
36 * @param p
37 * the predicate to write
38 * @param o
39 * the object to write
40 * @param g
41 * the graph name to write, or null
42 *
43 * @throws TripleHandlerException
44 * if there is an error writing the triple
45 */
46 void writeTriple(Resource s, IRI p, Value o, Resource g) throws TripleHandlerException;
47
48 /**
49 * Writes a prefix-namespace mapping. <br>
50 * <b>NOTE:</b> this method should be called <b>before</b> writing out any triples. Calling this method <b>after</b>
51 * writing out a triple may result in the prefix-namespace mapping being ignored.
52 *
53 * @param prefix
54 * the namespace prefix
55 * @param uri
56 * the namespace uri
57 *
58 * @throws TripleHandlerException
59 * if there was an error writing out the prefix-namespace mapping
60 */
61 void writeNamespace(String prefix, String uri) throws TripleHandlerException;
62
63 /**
64 * Releases resources associated with this {@link TripleWriter}, and flushes (but by default does not close) any
65 * underlying {@link java.io.OutputStream}s. Future invocations of methods of this writer produce <b>undefined
66 * behavior</b> after this method has been called.
67 *
68 * @throws TripleHandlerException
69 * if there was an error closing this {@link TripleWriter}
70 */
71 @Override
72 void close() throws TripleHandlerException;
73
74 }