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 java.io.IOException;
2223import org.apache.giraph.graph.Vertex;
24import org.apache.giraph.io.formats.TextVertexOutputFormat;
25import org.apache.hadoop.io.DoubleWritable;
26import org.apache.hadoop.io.LongWritable;
27import org.apache.hadoop.io.Text;
28import org.apache.hadoop.mapreduce.TaskAttemptContext;
2930/**31 * Simple vertex output format for weighted graphs.32 */33publicclassVertexWithDoubleValueDoubleEdgeTextOutputFormatextends34 TextVertexOutputFormat<LongWritable, DoubleWritable, DoubleWritable> {
35 @Override
36publicTextVertexWriter createVertexWriter(TaskAttemptContext context)
37throws IOException, InterruptedException {
38returnnewVertexWithDoubleValueWriter();
39 }
4041/**42 * Vertex writer used with43 * {@link VertexWithDoubleValueDoubleEdgeTextOutputFormat}.44 */45publicclassVertexWithDoubleValueWriterextendsTextVertexWriter {
46 @Override
47publicvoid writeVertex(
48 Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex)
49throws IOException, InterruptedException {
50 StringBuilder output = new StringBuilder();
51 output.append(vertex.getId().get());
52 output.append('\t');
53 output.append(vertex.getValue().get());
54 getRecordWriter().write(new Text(output.toString()), null);
55 }
56 }
57 }