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.io.formats;
2021import org.apache.giraph.io.EdgeReader;
22import org.apache.giraph.utils.IntPair;
23import org.apache.hadoop.io.IntWritable;
24import org.apache.hadoop.io.NullWritable;
25import org.apache.hadoop.io.Text;
26import org.apache.hadoop.mapreduce.InputSplit;
27import org.apache.hadoop.mapreduce.TaskAttemptContext;
2829import java.io.IOException;
30import java.util.regex.Pattern;
3132/**33 * Simple text-based {@link org.apache.giraph.io.EdgeInputFormat} for34 * unweighted graphs with int ids.35 *36 * Each line consists of: source_vertex, target_vertex37 */38publicclassIntNullTextEdgeInputFormatextends39 TextEdgeInputFormat<IntWritable, NullWritable> {
40/** Splitter for endpoints */41privatestaticfinal Pattern SEPARATOR = Pattern.compile("[\t ]");
4243 @Override
44public EdgeReader<IntWritable, NullWritable> createEdgeReader(
45 InputSplit split, TaskAttemptContext context) throws IOException {
46returnnewIntNullTextEdgeReader();
47 }
4849/**50 * {@link org.apache.giraph.io.EdgeReader} associated with51 * {@link IntNullTextEdgeInputFormat}.52 */53publicclassIntNullTextEdgeReaderextends54 TextEdgeReaderFromEachLineProcessed<IntPair> {
55 @Override
56protectedIntPair preprocessLine(Text line) throws IOException {
57 String[] tokens = SEPARATOR.split(line.toString());
58returnnewIntPair(Integer.parseInt(tokens[0]),
59 Integer.parseInt(tokens[1]));
60 }
6162 @Override
63protected IntWritable getSourceVertexId(IntPair endpoints)
64throws IOException {
65returnnew IntWritable(endpoints.getFirst());
66 }
6768 @Override
69protected IntWritable getTargetVertexId(IntPair endpoints)
70throws IOException {
71returnnew IntWritable(endpoints.getSecond());
72 }
7374 @Override
75protected NullWritable getValue(IntPair endpoints) throws IOException {
76return NullWritable.get();
77 }
78 }
79 }