You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2015/01/05 16:07:55 UTC
[47/52] [abbrv] jena git commit: Further rebranding to Elephas
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfjson/RdfJsonWriter.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfjson/RdfJsonWriter.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfjson/RdfJsonWriter.java
new file mode 100644
index 0000000..30bd4fa
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfjson/RdfJsonWriter.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.output.writers.rdfjson;
+
+import java.io.Writer;
+
+import org.apache.jena.hadoop.rdf.io.output.writers.AbstractWholeFileTripleWriter;
+import org.apache.jena.riot.Lang;
+
+/**
+ * A record writer for RDF/JSON
+ *
+ *
+ * @param <TKey>
+ * Key type
+ *
+ */
+public class RdfJsonWriter<TKey> extends AbstractWholeFileTripleWriter<TKey> {
+
+ /**
+ * Creates a new record writer
+ *
+ * @param writer
+ * Writer
+ */
+ public RdfJsonWriter(Writer writer) {
+ super(writer);
+ }
+
+ @Override
+ protected Lang getRdfLanguage() {
+ return Lang.RDFJSON;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfxml/RdfXmlWriter.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfxml/RdfXmlWriter.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfxml/RdfXmlWriter.java
new file mode 100644
index 0000000..f202914
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/rdfxml/RdfXmlWriter.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.output.writers.rdfxml;
+
+import java.io.Writer;
+
+import org.apache.jena.hadoop.rdf.io.output.writers.AbstractWholeFileTripleWriter;
+import org.apache.jena.riot.Lang;
+
+/**
+ * A record writer for RDF/XML
+ *
+ *
+ * @param <TKey>
+ * Key type
+ *
+ */
+public class RdfXmlWriter<TKey> extends AbstractWholeFileTripleWriter<TKey> {
+
+ /**
+ * Creates a new record writer
+ *
+ * @param writer
+ * Writer
+ */
+ public RdfXmlWriter(Writer writer) {
+ super(writer);
+ }
+
+ @Override
+ protected Lang getRdfLanguage() {
+ return Lang.RDFXML;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftQuadWriter.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftQuadWriter.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftQuadWriter.java
new file mode 100644
index 0000000..599dba9
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftQuadWriter.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.output.writers.thrift;
+
+import java.io.Writer;
+
+import org.apache.jena.hadoop.rdf.io.output.writers.AbstractWholeFileQuadWriter;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFLanguages;
+
+public class ThriftQuadWriter<TKey> extends AbstractWholeFileQuadWriter<TKey> {
+
+ public ThriftQuadWriter(Writer writer) {
+ super(writer);
+ }
+
+ @Override
+ protected Lang getRdfLanguage() {
+ return RDFLanguages.THRIFT;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftTripleWriter.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftTripleWriter.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftTripleWriter.java
new file mode 100644
index 0000000..0089459
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/thrift/ThriftTripleWriter.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.output.writers.thrift;
+
+import java.io.Writer;
+
+import org.apache.jena.hadoop.rdf.io.output.writers.AbstractWholeFileTripleWriter;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFLanguages;
+
+public class ThriftTripleWriter<TKey> extends AbstractWholeFileTripleWriter<TKey> {
+
+ public ThriftTripleWriter(Writer writer) {
+ super(writer);
+ }
+
+ @Override
+ protected Lang getRdfLanguage() {
+ return RDFLanguages.THRIFT;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/trig/BatchedTriGWriter.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/trig/BatchedTriGWriter.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/trig/BatchedTriGWriter.java
new file mode 100644
index 0000000..4c0c75f
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/trig/BatchedTriGWriter.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.output.writers.trig;
+
+import java.io.Writer;
+
+import org.apache.jena.hadoop.rdf.io.output.writers.AbstractBatchedQuadWriter;
+import org.apache.jena.riot.Lang;
+
+/**
+ * A record writer for TriG that uses the batched approach, note that this
+ * approach will produce invalid data when blank nodes span batches
+ *
+ * @param <TKey>
+ * Key type
+ */
+public class BatchedTriGWriter<TKey> extends AbstractBatchedQuadWriter<TKey> {
+
+ /**
+ * Creates a new record writer
+ *
+ * @param writer
+ * Writer
+ * @param batchSize
+ * Batch size
+ */
+ public BatchedTriGWriter(Writer writer, long batchSize) {
+ super(writer, batchSize);
+ }
+
+ @Override
+ protected Lang getRdfLanguage() {
+ return Lang.TRIG;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/turtle/BatchedTurtleWriter.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/turtle/BatchedTurtleWriter.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/turtle/BatchedTurtleWriter.java
new file mode 100644
index 0000000..86ab2f9
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/output/writers/turtle/BatchedTurtleWriter.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.output.writers.turtle;
+
+import java.io.Writer;
+
+import org.apache.jena.hadoop.rdf.io.output.writers.AbstractBatchedTripleWriter;
+import org.apache.jena.riot.Lang;
+
+/**
+ * A record writer for Turtle that uses the batched approach, note that this
+ * approach will produce invalid data when blank nodes span batches
+ *
+ *
+ *
+ * @param <TKey>
+ */
+public class BatchedTurtleWriter<TKey> extends
+ AbstractBatchedTripleWriter<TKey> {
+
+ /**
+ * Creates a new record writer
+ *
+ * @param writer
+ * Writer
+ * @param batchSize
+ * Batch size
+ */
+ public BatchedTurtleWriter(Writer writer, long batchSize) {
+ super(writer, batchSize);
+ }
+
+ @Override
+ protected Lang getRdfLanguage() {
+ return Lang.TURTLE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/HadoopRdfIORegistry.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/HadoopRdfIORegistry.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/HadoopRdfIORegistry.java
new file mode 100644
index 0000000..7b04ef4
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/HadoopRdfIORegistry.java
@@ -0,0 +1,310 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * A registry which is used by various classes to dynamically select record
+ * readers and writers based on a provided {@link Lang}
+ * <p>
+ * Readers and writers are dynamically discovered using the Java
+ * {@link ServiceLoader} mechanism. This will look for files under
+ * {@code META-INF/services} named
+ * {@code org.apache.jena.hadoop.rdf.io.registry.ReaderFactory} and
+ * {@code org.apache.jena.hadoop.rdf.io.registry.WriterFactory}. This follows
+ * the standard {@linkplain ServiceLoader} format of provided one class name per
+ * line which implements the relevant interface.
+ * </p>
+ *
+ */
+public class HadoopRdfIORegistry {
+
+ private static Map<Lang, ReaderFactory> readerFactories = new HashMap<>();
+ private static Map<Lang, WriterFactory> writerFactories = new HashMap<>();
+ private static boolean init = false;
+
+ static {
+ init();
+ }
+
+ private static synchronized void init() {
+ if (init)
+ return;
+
+ // Dynamically load and register reader factories
+ ServiceLoader<ReaderFactory> readerFactoryLoader = ServiceLoader.load(ReaderFactory.class);
+ Iterator<ReaderFactory> readerFactoryIterator = readerFactoryLoader.iterator();
+ while (readerFactoryIterator.hasNext()) {
+ ReaderFactory f = readerFactoryIterator.next();
+ addReaderFactory(f);
+ }
+
+ // Dynamically load and register writer factories
+ ServiceLoader<WriterFactory> writerFactoryLoader = ServiceLoader.load(WriterFactory.class);
+ Iterator<WriterFactory> writerFactoryIterator = writerFactoryLoader.iterator();
+ while (writerFactoryIterator.hasNext()) {
+ WriterFactory f = writerFactoryIterator.next();
+ addWriterFactory(f);
+ }
+
+ init = true;
+ }
+
+ /**
+ * Resets the registry to the default configuration
+ */
+ public static synchronized void reset() {
+ if (!init)
+ return;
+
+ init = false;
+ init();
+ }
+
+ /**
+ * Registers the reader factory for all the languages it declares itself as
+ * supporting
+ *
+ * @param f
+ * Reader factory
+ */
+ public static void addReaderFactory(ReaderFactory f) {
+ if (f == null)
+ throw new NullPointerException("Factory cannot be null");
+
+ readerFactories.put(f.getPrimaryLanguage(), f);
+ for (Lang altLang : f.getAlternativeLanguages()) {
+ readerFactories.put(altLang, f);
+ }
+ }
+
+ /**
+ * Registers the writer factory for all the languages it declares itself as
+ * supporting
+ *
+ * @param f
+ * Writer factory
+ */
+ public static void addWriterFactory(WriterFactory f) {
+ if (f == null)
+ throw new NullPointerException("Factory cannot be null");
+
+ writerFactories.put(f.getPrimaryLanguage(), f);
+ for (Lang altLang : f.getAlternativeLanguages()) {
+ writerFactories.put(altLang, f);
+ }
+ }
+
+ /**
+ * Gets whether there is a quad reader available for the given language
+ *
+ * @param lang
+ * Language
+ * @return True if available, false otherwise
+ */
+ public static boolean hasQuadReader(Lang lang) {
+ if (lang == null)
+ return false;
+
+ ReaderFactory f = readerFactories.get(lang);
+ if (f == null)
+ return false;
+ return f.canReadQuads();
+ }
+
+ /**
+ * Gets whether there is a triple reader available for the given language
+ *
+ * @param lang
+ * Language
+ * @return True if available, false otherwise
+ */
+ public static boolean hasTriplesReader(Lang lang) {
+ if (lang == null)
+ return false;
+
+ ReaderFactory f = readerFactories.get(lang);
+ if (f == null)
+ return false;
+ return f.canReadTriples();
+ }
+
+ /**
+ * Tries to create a quad reader for the given language
+ *
+ * @param lang
+ * Language
+ * @return Quad reader if one is available
+ * @throws IOException
+ * Thrown if a quad reader is not available or the given
+ * language does not support quads
+ */
+ public static RecordReader<LongWritable, QuadWritable> createQuadReader(Lang lang) throws IOException {
+ if (lang == null)
+ throw new IOException("Cannot create a quad reader for an undefined language");
+
+ ReaderFactory f = readerFactories.get(lang);
+ if (f == null)
+ throw new IOException("No factory registered for language " + lang.getName());
+ if (!f.canReadQuads())
+ throw new IOException(lang.getName() + " does not support reading quads");
+
+ RecordReader<LongWritable, QuadWritable> reader = f.createQuadReader();
+ if (reader == null)
+ throw new IOException("Registered factory for " + lang.getName() + " produced a null triples reader");
+ return reader;
+ }
+
+ /**
+ * Tries to create a triple reader for the given language
+ *
+ * @param lang
+ * Language
+ * @return Triple reader if one is available
+ * @throws IOException
+ * Thrown if a triple reader is not available or the given
+ * language does not support triple
+ */
+ public static RecordReader<LongWritable, TripleWritable> createTripleReader(Lang lang) throws IOException {
+ if (lang == null)
+ throw new IOException("Cannot create a triple reader for an undefined language");
+
+ ReaderFactory f = readerFactories.get(lang);
+ if (f == null)
+ throw new IOException("No factory registered for language " + lang.getName());
+ if (!f.canReadTriples())
+ throw new IOException(lang.getName() + " does not support reading triples");
+
+ RecordReader<LongWritable, TripleWritable> reader = f.createTripleReader();
+ if (reader == null)
+ throw new IOException("Registered factory for " + lang.getName() + " produced a null triples reader");
+ return reader;
+ }
+
+ /**
+ * Gets whether there is a quad writer available for the given language
+ *
+ * @param lang
+ * Language
+ * @return True if available, false otherwise
+ */
+ public static boolean hasQuadWriter(Lang lang) {
+ if (lang == null)
+ return false;
+
+ WriterFactory f = writerFactories.get(lang);
+ if (f == null)
+ return false;
+ return f.canWriteQuads();
+ }
+
+ /**
+ * Gets whether there is a triple writer available for the given language
+ *
+ * @param lang
+ * Language
+ * @return True if available, false otherwise
+ */
+ public static boolean hasTriplesWriter(Lang lang) {
+ if (lang == null)
+ return false;
+
+ WriterFactory f = writerFactories.get(lang);
+ if (f == null)
+ return false;
+ return f.canWriteTriples();
+ }
+
+ /**
+ * Tries to create a quad writer for the given language
+ *
+ * @param lang
+ * Language
+ * @param writer
+ * Writer
+ * @param config
+ * Configuration
+ *
+ * @return Quad writer if one is available
+ * @throws IOException
+ * Thrown if a quad writer is not available or the given
+ * language does not support quads
+ */
+ public static <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Lang lang, Writer writer,
+ Configuration config) throws IOException {
+ if (lang == null)
+ throw new IOException("Cannot create a quad writer for an undefined language");
+
+ WriterFactory f = writerFactories.get(lang);
+ if (f == null)
+ throw new IOException("No factory registered for language " + lang.getName());
+ if (!f.canWriteQuads())
+ throw new IOException(lang.getName() + " does not support writeing quads");
+
+ RecordWriter<TKey, QuadWritable> rwriter = f.<TKey> createQuadWriter(writer, config);
+ if (rwriter == null)
+ throw new IOException("Registered factory for " + lang.getName() + " produced a null triples writer");
+ return rwriter;
+ }
+
+ /**
+ * Tries to create a triple writer for the given language
+ *
+ * @param lang
+ * Language
+ * @param writer
+ * Writer
+ * @param config
+ * Configuration
+ * @return Triple writer if one is available
+ * @throws IOException
+ * Thrown if a triple writer is not available or the given
+ * language does not support triple
+ */
+ public static <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Lang lang, Writer writer,
+ Configuration config) throws IOException {
+ if (lang == null)
+ throw new IOException("Cannot create a triple writer for an undefined language");
+
+ WriterFactory f = writerFactories.get(lang);
+ if (f == null)
+ throw new IOException("No factory registered for language " + lang.getName());
+ if (!f.canWriteTriples())
+ throw new IOException(lang.getName() + " does not support writing triples");
+
+ RecordWriter<TKey, TripleWritable> rwriter = f.<TKey> createTripleWriter(writer, config);
+ if (rwriter == null)
+ throw new IOException("Registered factory for " + lang.getName() + " produced a null triples writer");
+ return rwriter;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/ReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/ReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/ReaderFactory.java
new file mode 100644
index 0000000..e1c98c7
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/ReaderFactory.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Interface for reader factories
+ *
+ */
+public interface ReaderFactory {
+
+ /**
+ * Gets the primary language this factory produces readers for
+ *
+ * @return Primary language
+ */
+ public abstract Lang getPrimaryLanguage();
+
+ /**
+ * Gets the alternative languages this factory can produce readers for
+ *
+ * @return Alternative languages
+ */
+ public abstract Collection<Lang> getAlternativeLanguages();
+
+ /**
+ * Gets whether this factory can produce readers that are capable of reading
+ * quads
+ *
+ * @return True if quads can be read, false if not
+ */
+ public abstract boolean canReadQuads();
+
+ /**
+ * Gets whether this factory can produce readers that are capable of reading
+ * triples
+ *
+ * @return True if triples can be read, false if not
+ */
+ public abstract boolean canReadTriples();
+
+ /**
+ * Creates a quad reader
+ *
+ * @return Quad reader
+ * @throws IOException
+ * May be thrown if a quad reader cannot be created
+ */
+ public abstract RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException;
+
+ /**
+ * Creates a triples reader
+ *
+ * @return Triples reader
+ * @throws IOException
+ * May be thrown if a triple reader cannot be created
+ */
+ public abstract RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/WriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/WriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/WriterFactory.java
new file mode 100644
index 0000000..db5635f
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/WriterFactory.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Interface for writer factories
+ *
+ */
+public interface WriterFactory {
+
+ /**
+ * Gets the primary language this factory produces writers for
+ *
+ * @return Primary language
+ */
+ public abstract Lang getPrimaryLanguage();
+
+ /**
+ * Gets the alternative languages this factory can produce writers for
+ *
+ * @return Alternative languages
+ */
+ public abstract Collection<Lang> getAlternativeLanguages();
+
+ /**
+ * Gets whether this factory can produce writers that are capable of reading
+ * quads
+ *
+ * @return True if quads can be read, false if not
+ */
+ public abstract boolean canWriteQuads();
+
+ /**
+ * Gets whether this factory can produce writers that are capable of reading
+ * triples
+ *
+ * @return True if triples can be read, false if not
+ */
+ public abstract boolean canWriteTriples();
+
+ /**
+ * Creates a quad writer
+ *
+ * @param writer
+ * Writer
+ * @param config
+ * Configuration
+ *
+ * @return Quad writer
+ * @throws IOException
+ * May be thrown if a quad writer cannot be created
+ */
+ public abstract <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config)
+ throws IOException;
+
+ /**
+ * Creates a triples writer
+ *
+ * @param writer
+ * Writer
+ * @param config
+ * Configuration
+ *
+ * @return Triples writer
+ * @throws IOException
+ * May be thrown if a triple writer cannot be created
+ */
+ public abstract <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractQuadsOnlyReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractQuadsOnlyReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractQuadsOnlyReaderFactory.java
new file mode 100644
index 0000000..7fe15a9
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractQuadsOnlyReaderFactory.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.registry.ReaderFactory;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Abstract reader factory for languages that only support quads
+ */
+public abstract class AbstractQuadsOnlyReaderFactory implements ReaderFactory {
+
+ private Lang lang;
+ private Collection<Lang> alternateLangs = Collections.unmodifiableList(Collections.<Lang>emptyList());
+
+ public AbstractQuadsOnlyReaderFactory(Lang lang) {
+ this(lang, (Collection<Lang>)null);
+ }
+
+ public AbstractQuadsOnlyReaderFactory(Lang lang, Lang...altLangs) {
+ this(lang, Arrays.asList(altLangs));
+ }
+
+ public AbstractQuadsOnlyReaderFactory(Lang lang, Collection<Lang> altLangs) {
+ this.lang = lang;
+ if (altLangs != null)
+ this.alternateLangs = Collections.unmodifiableCollection(altLangs);
+ }
+
+ @Override
+ public final Lang getPrimaryLanguage() {
+ return this.lang;
+ }
+
+ @Override
+ public final Collection<Lang> getAlternativeLanguages() {
+ return this.alternateLangs;
+ }
+
+ @Override
+ public final boolean canReadQuads() {
+ return true;
+ }
+
+ @Override
+ public final boolean canReadTriples() {
+ return false;
+ }
+
+ @Override
+ public abstract RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException;
+
+ @Override
+ public final RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException {
+ throw new IOException(this.lang.getName() + " does not support reading triples");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractReaderFactory.java
new file mode 100644
index 0000000..60e45af
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractReaderFactory.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.registry.ReaderFactory;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Abstract reader factory for languages that support triples and quads
+ */
+public abstract class AbstractReaderFactory implements ReaderFactory {
+
+ private Lang lang;
+ private Collection<Lang> alternateLangs = Collections.unmodifiableList(Collections.<Lang>emptyList());
+
+ public AbstractReaderFactory(Lang lang) {
+ this(lang, (Collection<Lang>)null);
+ }
+
+ public AbstractReaderFactory(Lang lang, Lang...altLangs) {
+ this(lang, Arrays.asList(altLangs));
+ }
+
+ public AbstractReaderFactory(Lang lang, Collection<Lang> altLangs) {
+ this.lang = lang;
+ if (altLangs != null)
+ this.alternateLangs = Collections.unmodifiableCollection(altLangs);
+ }
+
+ @Override
+ public final Lang getPrimaryLanguage() {
+ return this.lang;
+ }
+
+ @Override
+ public final Collection<Lang> getAlternativeLanguages() {
+ return this.alternateLangs;
+ }
+
+ @Override
+ public final boolean canReadQuads() {
+ return true;
+ }
+
+ @Override
+ public final boolean canReadTriples() {
+ return true;
+ }
+
+ @Override
+ public abstract RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException;
+
+ @Override
+ public abstract RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractTriplesOnlyReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractTriplesOnlyReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractTriplesOnlyReaderFactory.java
new file mode 100644
index 0000000..7fb8131
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/AbstractTriplesOnlyReaderFactory.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.registry.ReaderFactory;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Abstract reader factory for languages that only support triples
+ */
+public abstract class AbstractTriplesOnlyReaderFactory implements ReaderFactory {
+
+ private Lang lang;
+ private Collection<Lang> alternateLangs = Collections.unmodifiableList(Collections.<Lang>emptyList());
+
+ public AbstractTriplesOnlyReaderFactory(Lang lang) {
+ this(lang, (Collection<Lang>)null);
+ }
+
+ public AbstractTriplesOnlyReaderFactory(Lang lang, Lang...altLangs) {
+ this(lang, Arrays.asList(altLangs));
+ }
+
+ public AbstractTriplesOnlyReaderFactory(Lang lang, Collection<Lang> altLangs) {
+ this.lang = lang;
+ if (altLangs != null)
+ this.alternateLangs = Collections.unmodifiableCollection(altLangs);
+ }
+
+ @Override
+ public final Lang getPrimaryLanguage() {
+ return this.lang;
+ }
+
+ @Override
+ public final Collection<Lang> getAlternativeLanguages() {
+ return this.alternateLangs;
+ }
+
+ @Override
+ public final boolean canReadQuads() {
+ return false;
+ }
+
+ @Override
+ public final boolean canReadTriples() {
+ return true;
+ }
+
+ @Override
+ public final RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException {
+ throw new IOException(this.lang.getName() + " does not support reading quads");
+ }
+
+ @Override
+ public abstract RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/JsonLDReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/JsonLDReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/JsonLDReaderFactory.java
new file mode 100644
index 0000000..6b064a4
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/JsonLDReaderFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.jsonld.JsonLDQuadReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.jsonld.JsonLDTripleReader;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class JsonLDReaderFactory extends AbstractReaderFactory {
+
+ public JsonLDReaderFactory() {
+ super(Lang.JSONLD);
+ }
+
+ @Override
+ public RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException {
+ return new JsonLDQuadReader();
+ }
+
+ @Override
+ public RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException {
+ return new JsonLDTripleReader();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NQuadsReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NQuadsReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NQuadsReaderFactory.java
new file mode 100644
index 0000000..2296296
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NQuadsReaderFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.nquads.WholeFileNQuadsReader;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class NQuadsReaderFactory extends AbstractQuadsOnlyReaderFactory {
+
+ public NQuadsReaderFactory() {
+ super(Lang.NQUADS, Lang.NQ);
+ }
+
+ @Override
+ public RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException {
+ return new WholeFileNQuadsReader();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NTriplesReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NTriplesReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NTriplesReaderFactory.java
new file mode 100644
index 0000000..a98a1ae
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/NTriplesReaderFactory.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.ntriples.WholeFileNTriplesReader;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+public class NTriplesReaderFactory extends AbstractTriplesOnlyReaderFactory {
+
+ public NTriplesReaderFactory() {
+ super(Lang.NTRIPLES, Lang.NT);
+ }
+
+ @Override
+ public RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException {
+ return new WholeFileNTriplesReader();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfJsonReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfJsonReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfJsonReaderFactory.java
new file mode 100644
index 0000000..ccf5feb
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfJsonReaderFactory.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.rdfjson.RdfJsonReader;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class RdfJsonReaderFactory extends AbstractTriplesOnlyReaderFactory {
+
+ public RdfJsonReaderFactory() {
+ super(Lang.RDFJSON);
+ }
+
+ @Override
+ public RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException {
+ return new RdfJsonReader();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfXmlReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfXmlReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfXmlReaderFactory.java
new file mode 100644
index 0000000..1aa88d7
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/RdfXmlReaderFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.rdfxml.RdfXmlReader;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+public class RdfXmlReaderFactory extends AbstractTriplesOnlyReaderFactory {
+
+ public RdfXmlReaderFactory() {
+ super(Lang.RDFXML);
+ }
+
+ @Override
+ public RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException {
+ return new RdfXmlReader();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/ThriftReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/ThriftReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/ThriftReaderFactory.java
new file mode 100644
index 0000000..25e8234
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/ThriftReaderFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.thrift.ThriftQuadReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.thrift.ThriftTripleReader;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.RDFLanguages;
+
+/**
+ *
+ */
+public class ThriftReaderFactory extends AbstractReaderFactory {
+
+ public ThriftReaderFactory() {
+ super(RDFLanguages.THRIFT);
+ }
+
+ @Override
+ public RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException {
+ return new ThriftQuadReader();
+ }
+
+ @Override
+ public RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException {
+ return new ThriftTripleReader();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriGReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriGReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriGReaderFactory.java
new file mode 100644
index 0000000..83ea818
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriGReaderFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.trig.TriGReader;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class TriGReaderFactory extends AbstractQuadsOnlyReaderFactory {
+
+ public TriGReaderFactory() {
+ super(Lang.TRIG);
+ }
+
+ @Override
+ public RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException {
+ return new TriGReader();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriXReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriXReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriXReaderFactory.java
new file mode 100644
index 0000000..cb8795c
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TriXReaderFactory.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.trix.TriXReader;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class TriXReaderFactory extends AbstractQuadsOnlyReaderFactory {
+
+ public TriXReaderFactory() {
+ super(Lang.TRIX);
+ }
+
+ @Override
+ public RecordReader<LongWritable, QuadWritable> createQuadReader() throws IOException {
+ return new TriXReader();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TurtleReaderFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TurtleReaderFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TurtleReaderFactory.java
new file mode 100644
index 0000000..7800376
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/readers/TurtleReaderFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.readers;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.jena.hadoop.rdf.io.input.readers.turtle.TurtleReader;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+public class TurtleReaderFactory extends AbstractTriplesOnlyReaderFactory {
+
+ public TurtleReaderFactory() {
+ super(Lang.TURTLE, Lang.TTL, Lang.N3);
+ }
+
+ @Override
+ public RecordReader<LongWritable, TripleWritable> createTripleReader() throws IOException {
+ return new TurtleReader();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractQuadsOnlyWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractQuadsOnlyWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractQuadsOnlyWriterFactory.java
new file mode 100644
index 0000000..0cf137e
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractQuadsOnlyWriterFactory.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.registry.WriterFactory;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Abstract writer factory for languages that only support quads
+ */
+public abstract class AbstractQuadsOnlyWriterFactory implements WriterFactory {
+
+ private Lang lang;
+ private Collection<Lang> alternateLangs = Collections.unmodifiableList(Collections.<Lang> emptyList());
+
+ public AbstractQuadsOnlyWriterFactory(Lang lang) {
+ this(lang, (Collection<Lang>) null);
+ }
+
+ public AbstractQuadsOnlyWriterFactory(Lang lang, Lang... altLangs) {
+ this(lang, Arrays.asList(altLangs));
+ }
+
+ public AbstractQuadsOnlyWriterFactory(Lang lang, Collection<Lang> altLangs) {
+ this.lang = lang;
+ if (altLangs != null)
+ this.alternateLangs = Collections.unmodifiableCollection(altLangs);
+ }
+
+ @Override
+ public final Lang getPrimaryLanguage() {
+ return this.lang;
+ }
+
+ @Override
+ public final Collection<Lang> getAlternativeLanguages() {
+ return this.alternateLangs;
+ }
+
+ @Override
+ public final boolean canWriteQuads() {
+ return true;
+ }
+
+ @Override
+ public final boolean canWriteTriples() {
+ return false;
+ }
+
+ @Override
+ public abstract <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config)
+ throws IOException;
+
+ @Override
+ public final <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException {
+ throw new IOException(this.lang.getName() + " does not support writing triples");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractTriplesOnlyWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractTriplesOnlyWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractTriplesOnlyWriterFactory.java
new file mode 100644
index 0000000..e45c3da
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractTriplesOnlyWriterFactory.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.registry.WriterFactory;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Abstract writer factory for languages that only support triples
+ */
+public abstract class AbstractTriplesOnlyWriterFactory implements WriterFactory {
+
+ private Lang lang;
+ private Collection<Lang> alternateLangs = Collections.unmodifiableList(Collections.<Lang> emptyList());
+
+ public AbstractTriplesOnlyWriterFactory(Lang lang) {
+ this(lang, (Collection<Lang>) null);
+ }
+
+ public AbstractTriplesOnlyWriterFactory(Lang lang, Lang... altLangs) {
+ this(lang, Arrays.asList(altLangs));
+ }
+
+ public AbstractTriplesOnlyWriterFactory(Lang lang, Collection<Lang> altLangs) {
+ this.lang = lang;
+ if (altLangs != null)
+ this.alternateLangs = Collections.unmodifiableCollection(altLangs);
+ }
+
+ @Override
+ public final Lang getPrimaryLanguage() {
+ return this.lang;
+ }
+
+ @Override
+ public final Collection<Lang> getAlternativeLanguages() {
+ return this.alternateLangs;
+ }
+
+ @Override
+ public final boolean canWriteQuads() {
+ return false;
+ }
+
+ @Override
+ public final boolean canWriteTriples() {
+ return true;
+ }
+
+ @Override
+ public final <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config)
+ throws IOException {
+ throw new IOException(this.lang.getName() + " does not support writing quads");
+ }
+
+ @Override
+ public abstract <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractWriterFactory.java
new file mode 100644
index 0000000..669b9c4
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/AbstractWriterFactory.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.registry.WriterFactory;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ * Abstract writer factory for languages that support triples and quads
+ */
+public abstract class AbstractWriterFactory implements WriterFactory {
+
+ private Lang lang;
+ private Collection<Lang> alternateLangs = Collections.unmodifiableList(Collections.<Lang>emptyList());
+
+ public AbstractWriterFactory(Lang lang) {
+ this(lang, (Collection<Lang>)null);
+ }
+
+ public AbstractWriterFactory(Lang lang, Lang...altLangs) {
+ this(lang, Arrays.asList(altLangs));
+ }
+
+ public AbstractWriterFactory(Lang lang, Collection<Lang> altLangs) {
+ this.lang = lang;
+ if (altLangs != null)
+ this.alternateLangs = Collections.unmodifiableCollection(altLangs);
+ }
+
+ @Override
+ public final Lang getPrimaryLanguage() {
+ return this.lang;
+ }
+
+ @Override
+ public final Collection<Lang> getAlternativeLanguages() {
+ return this.alternateLangs;
+ }
+
+ @Override
+ public final boolean canWriteQuads() {
+ return true;
+ }
+
+ @Override
+ public final boolean canWriteTriples() {
+ return true;
+ }
+
+ @Override
+ public abstract <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config) throws IOException;
+
+ @Override
+ public abstract <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config) throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/JsonLDWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/JsonLDWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/JsonLDWriterFactory.java
new file mode 100644
index 0000000..89e93ed
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/JsonLDWriterFactory.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.jsonld.JsonLDQuadWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.jsonld.JsonLDTripleWriter;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class JsonLDWriterFactory extends AbstractWriterFactory {
+
+ public JsonLDWriterFactory() {
+ super(Lang.JSONLD);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new JsonLDQuadWriter<>(writer);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new JsonLDTripleWriter<>(writer);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NQuadsWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NQuadsWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NQuadsWriterFactory.java
new file mode 100644
index 0000000..abbbd0f
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NQuadsWriterFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.nquads.NQuadsWriter;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class NQuadsWriterFactory extends AbstractQuadsOnlyWriterFactory {
+
+ public NQuadsWriterFactory() {
+ super(Lang.NQUADS, Lang.NQ);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new NQuadsWriter<TKey>(writer);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NTriplesWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NTriplesWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NTriplesWriterFactory.java
new file mode 100644
index 0000000..88c9551
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/NTriplesWriterFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.ntriples.NTriplesWriter;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class NTriplesWriterFactory extends AbstractTriplesOnlyWriterFactory {
+
+ public NTriplesWriterFactory() {
+ super(Lang.NTRIPLES, Lang.NT);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new NTriplesWriter<TKey>(writer);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfJsonWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfJsonWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfJsonWriterFactory.java
new file mode 100644
index 0000000..8252422
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfJsonWriterFactory.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.rdfjson.RdfJsonWriter;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class RdfJsonWriterFactory extends AbstractTriplesOnlyWriterFactory {
+
+ public RdfJsonWriterFactory() {
+ super(Lang.RDFJSON);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new RdfJsonWriter<TKey>(writer);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfXmlWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfXmlWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfXmlWriterFactory.java
new file mode 100644
index 0000000..b4ac8e3
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/RdfXmlWriterFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.rdfxml.RdfXmlWriter;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.Lang;
+
+/**
+ *
+ */
+public class RdfXmlWriterFactory extends AbstractTriplesOnlyWriterFactory {
+
+ public RdfXmlWriterFactory() {
+ super(Lang.RDFXML);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new RdfXmlWriter<TKey>(writer);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/49c4cffe/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/ThriftWriterFactory.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/ThriftWriterFactory.java b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/ThriftWriterFactory.java
new file mode 100644
index 0000000..757472c
--- /dev/null
+++ b/jena-elephas/jena-elephas-io/src/main/java/org/apache/jena/hadoop/rdf/io/registry/writers/ThriftWriterFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.hadoop.rdf.io.registry.writers;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+import org.apache.commons.io.output.WriterOutputStream;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.StreamRdfQuadWriter;
+import org.apache.jena.hadoop.rdf.io.output.writers.StreamRdfTripleWriter;
+import org.apache.jena.hadoop.rdf.types.QuadWritable;
+import org.apache.jena.hadoop.rdf.types.TripleWritable;
+import org.apache.jena.riot.RDFLanguages;
+import org.apache.jena.riot.thrift.StreamRDF2Thrift;
+
+/**
+ *
+ */
+public class ThriftWriterFactory extends AbstractWriterFactory {
+
+ public ThriftWriterFactory() {
+ super(RDFLanguages.THRIFT);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new StreamRdfQuadWriter<TKey>(new StreamRDF2Thrift(new WriterOutputStream(writer, Charset.forName("utf-8")),
+ false), writer);
+ }
+
+ @Override
+ public <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config)
+ throws IOException {
+ return new StreamRdfTripleWriter<TKey>(new StreamRDF2Thrift(new WriterOutputStream(writer, Charset.forName("utf-8")),
+ false), writer);
+ }
+
+}