001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.hadoop.mapred; 020 021 import java.io.IOException; 022 023 import org.apache.hadoop.classification.InterfaceAudience; 024 import org.apache.hadoop.classification.InterfaceStability; 025 import org.apache.hadoop.conf.Configuration; 026 import org.apache.hadoop.io.Text; 027 import org.apache.hadoop.io.Writable; 028 import org.apache.hadoop.io.WritableComparable; 029 030 /** 031 * This class converts the input keys and values to their String forms by calling toString() 032 * method. This class to SequenceFileAsTextInputFormat class is as LineRecordReader 033 * class to TextInputFormat class. 034 * @deprecated Use 035 * {@link org.apache.hadoop.mapreduce.lib.input.SequenceFileAsTextRecordReader} 036 * instead 037 */ 038 @Deprecated 039 @InterfaceAudience.Public 040 @InterfaceStability.Stable 041 public class SequenceFileAsTextRecordReader 042 implements RecordReader<Text, Text> { 043 044 private final SequenceFileRecordReader<WritableComparable, Writable> 045 sequenceFileRecordReader; 046 047 private WritableComparable innerKey; 048 private Writable innerValue; 049 050 public SequenceFileAsTextRecordReader(Configuration conf, FileSplit split) 051 throws IOException { 052 sequenceFileRecordReader = 053 new SequenceFileRecordReader<WritableComparable, Writable>(conf, split); 054 innerKey = sequenceFileRecordReader.createKey(); 055 innerValue = sequenceFileRecordReader.createValue(); 056 } 057 058 public Text createKey() { 059 return new Text(); 060 } 061 062 public Text createValue() { 063 return new Text(); 064 } 065 066 /** Read key/value pair in a line. */ 067 public synchronized boolean next(Text key, Text value) throws IOException { 068 Text tKey = key; 069 Text tValue = value; 070 if (!sequenceFileRecordReader.next(innerKey, innerValue)) { 071 return false; 072 } 073 tKey.set(innerKey.toString()); 074 tValue.set(innerValue.toString()); 075 return true; 076 } 077 078 public float getProgress() throws IOException { 079 return sequenceFileRecordReader.getProgress(); 080 } 081 082 public synchronized long getPos() throws IOException { 083 return sequenceFileRecordReader.getPos(); 084 } 085 086 public synchronized void close() throws IOException { 087 sequenceFileRecordReader.close(); 088 } 089 090 }