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.utils.IntPair;
22import org.apache.hadoop.io.IntWritable;
23import org.apache.hadoop.io.Text;
24import org.apache.hadoop.io.Writable;
25import org.apache.hadoop.mapreduce.InputSplit;
26import org.apache.hadoop.mapreduce.TaskAttemptContext;
2728import java.io.IOException;
29import java.util.regex.Pattern;
3031/**32 * Simple text-based {@link org.apache.giraph.io.VertexValueInputFormat}33 * for integer ids and values.34 *35 * Each line consists of: id, value36 *37 * @param <E> Edge value38 */39publicclass IntIntTextVertexValueInputFormat<E extends Writable> extends40 TextVertexValueInputFormat<IntWritable, IntWritable, E> {
41/** Separator for id and value */42privatestaticfinal Pattern SEPARATOR = Pattern.compile("[\t ]");
4344 @Override
45publicTextVertexValueReader createVertexValueReader(
46 InputSplit split, TaskAttemptContext context) throws IOException {
47returnnewIntIntTextVertexValueReader();
48 }
4950/**51 * {@link org.apache.giraph.io.VertexValueReader} associated with52 * {@link IntIntTextVertexValueInputFormat}.53 */54publicclassIntIntTextVertexValueReaderextends55 TextVertexValueReaderFromEachLineProcessed<IntPair> {
5657 @Override
58protectedIntPair preprocessLine(Text line) throws IOException {
59 String[] tokens = SEPARATOR.split(line.toString());
60returnnewIntPair(Integer.parseInt(tokens[0]),
61 Integer.parseInt(tokens[1]));
62 }
6364 @Override
65protected IntWritable getId(IntPair data) throws IOException {
66returnnew IntWritable(data.getFirst());
67 }
6869 @Override
70protected IntWritable getValue(IntPair data) throws IOException {
71returnnew IntWritable(data.getSecond());
72 }
73 }
74 }