1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.examples;
2021import org.apache.giraph.graph.Vertex;
22import org.apache.giraph.io.formats.TextVertexOutputFormat;
23import org.apache.hadoop.io.DoubleWritable;
24import org.apache.hadoop.io.LongWritable;
25import org.apache.hadoop.io.NullWritable;
26import org.apache.hadoop.io.Text;
27import org.apache.hadoop.mapreduce.TaskAttemptContext;
2829import java.io.IOException;
3031/**32 * Output format for vertices with a long as id, a double as value and33 * null edges34 */35publicclassVertexWithDoubleValueNullEdgeTextOutputFormatextends36 TextVertexOutputFormat<LongWritable, DoubleWritable, NullWritable> {
37 @Override
38publicTextVertexWriter createVertexWriter(TaskAttemptContext context)
39throws IOException, InterruptedException {
40returnnewVertexWithDoubleValueWriter();
41 }
4243/**44 * Vertex writer used with45 * {@link VertexWithDoubleValueNullEdgeTextOutputFormat}.46 */47publicclassVertexWithDoubleValueWriterextendsTextVertexWriter {
48 @Override
49publicvoid writeVertex(
50 Vertex<LongWritable, DoubleWritable, NullWritable> vertex)
51throws IOException, InterruptedException {
52 StringBuilder output = new StringBuilder();
53 output.append(vertex.getId().get());
54 output.append('\t');
55 output.append(vertex.getValue().get());
56 getRecordWriter().write(new Text(output.toString()), null);
57 }
58 }
59 }