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.apache.any23.configuration.Settings;
21  import org.apache.any23.extractor.ExtractionContext;
22  import org.eclipse.rdf4j.common.lang.FileFormat;
23  import org.eclipse.rdf4j.model.IRI;
24  import org.eclipse.rdf4j.model.Resource;
25  import org.eclipse.rdf4j.model.Value;
26  import org.eclipse.rdf4j.rio.RDFFormat;
27  
28  import java.io.OutputStream;
29  
30  /**
31   * Base interface for constructors of {@link TripleHandler} implementations
32   * that write to an {@link OutputStream} using a particular {@link FileFormat}.
33   * @author Hans Brende (hansbrende@apache.org)
34   */
35  public interface TripleWriterFactory extends BaseWriterFactory<OutputStream> {
36  
37      /**
38       * @deprecated since 2.3. Use {@link #getTripleFormat()} instead.
39       */
40      @Override
41      @Deprecated
42      default RDFFormat getRdfFormat() {
43          return getTripleFormat().toRDFFormat();
44      }
45  
46      /**
47       * @return the format used to write to {@link OutputStream}s
48       */
49      TripleFormat getTripleFormat();
50  
51      /**
52       * @deprecated since 2.3. Use {@link #getTripleFormat()}.{@link TripleFormat#getMimeType() getMimeType()} instead.
53       */
54      @Override
55      @Deprecated
56      default String getMimeType() {
57          return getTripleFormat().getMimeType();
58      }
59  
60      /**
61       * @deprecated since 2.3. Use {@link #getTripleWriter(OutputStream, Settings)} instead.
62       */
63      @Override
64      @Deprecated
65      default FormatWriter getRdfWriter(OutputStream os) {
66          TripleHandler th = getTripleWriter(os, Settings.of());
67          return th instanceof FormatWriterWriter.html#FormatWriter">FormatWriter"../../../../org/apache/any23/writer/FormatWriter.html#FormatWriter">FormatWriter ? (FormatWriterWriter.html#FormatWriter">FormatWriter)th : new FormatWriter() {
68              @Override
69              public boolean isAnnotated() {
70                  return false;
71              }
72              @Override
73              public void setAnnotated(boolean f) {}
74              @Override
75              public void startDocument(IRI documentIRI) throws TripleHandlerException {
76                  th.startDocument(documentIRI);
77              }
78              @Override
79              public void openContext(ExtractionContext context) throws TripleHandlerException {
80                  th.openContext(context);
81              }
82              @Override
83              public void receiveTriple(Resource s, IRI p, Value o, IRI g, ExtractionContext context) throws TripleHandlerException {
84                  th.receiveTriple(s, p, o, g, context);
85              }
86              @Override
87              public void receiveNamespace(String prefix, String uri, ExtractionContext context) throws TripleHandlerException {
88                  th.receiveNamespace(prefix, uri, context);
89              }
90              @Override
91              public void closeContext(ExtractionContext context) throws TripleHandlerException {
92                  th.closeContext(context);
93              }
94              @Override
95              public void endDocument(IRI documentIRI) throws TripleHandlerException {
96                  th.endDocument(documentIRI);
97              }
98              @Override
99              public void setContentLength(long contentLength) {
100                 th.setContentLength(contentLength);
101             }
102             @Override
103             public void close() throws TripleHandlerException {
104                 th.close();
105             }
106         };
107     }
108 
109 
110     /**
111      *
112      * @return the settings supported by writers produced by this factory
113      */
114     @Override
115     Settings getSupportedSettings();
116 
117 
118     /**
119      * @param out the {@link OutputStream} to write to
120      * @param settings the settings with which to configure the writer
121      * @return a {@link TripleHandler} which writes to the specified {@link OutputStream}
122      * @throws NullPointerException if the output stream or settings is null
123      * @throws IllegalArgumentException if the settings are not correctly configured
124      */
125     @Override
126     TripleHandler getTripleWriter(OutputStream out, Settings settings);
127 
128 }