![JAR search and dependency download from the Maven repository](/logo.png)
org.cloudgraph.mapreduce.GraphXmlOutputFormat Maven / Gradle / Ivy
/**
* Copyright 2017 TerraMeta Software, Inc.
*
* Licensed 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.cloudgraph.mapreduce;
import java.io.DataOutputStream;
import java.io.IOException;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.ReflectionUtils;
/**
* An XML oriented output format based on FileOutputFormat
*
* @see org.cloudgraph.mapreduce.GraphXmlRecordReader
* @see org.cloudgraph.mapreduce.GraphWritable
*
* @author Scott Cinnamond
* @since 0.6.0
*/
public class GraphXmlOutputFormat extends FileOutputFormat implements
Configurable, GraphXml {
/** The configuration. */
private Configuration conf = null;
@Override
public Configuration getConf() {
return this.conf;
}
@Override
public void setConf(Configuration configuration) {
this.conf = configuration;
}
@Override
public RecordWriter getRecordWriter(TaskAttemptContext job)
throws IOException, InterruptedException {
Configuration conf = job.getConfiguration();
boolean isCompressed = getCompressOutput(job);
CompressionCodec codec = null;
String extension = "";
if (isCompressed) {
Class extends CompressionCodec> codecClass = getOutputCompressorClass(job, GzipCodec.class);
codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf);
extension = codec.getDefaultExtension();
}
Path file = getDefaultWorkFile(job, extension);
FileSystem fs = file.getFileSystem(conf);
if (!isCompressed) {
FSDataOutputStream fileOut = fs.create(file, false);
return new GraphXmlRecordWriter(fileOut, job);
} else {
FSDataOutputStream fileOut = fs.create(file, false);
return new GraphXmlRecordWriter(new DataOutputStream(codec.createOutputStream(fileOut)), job);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy