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.lib; 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.mapred.FileInputFormat; 027 import org.apache.hadoop.mapred.FileSplit; 028 import org.apache.hadoop.mapred.JobConf; 029 import org.apache.hadoop.mapred.RecordReader; 030 import org.apache.hadoop.mapred.Reporter; 031 032 /** 033 * A wrapper class for a record reader that handles a single file split. It 034 * delegates most of the methods to the wrapped instance. A concrete subclass 035 * needs to provide a constructor that calls this parent constructor with the 036 * appropriate input format. The subclass constructor must satisfy the specific 037 * constructor signature that is required by 038 * <code>CombineFileRecordReader</code>. 039 * 040 * Subclassing is needed to get a concrete record reader wrapper because of the 041 * constructor requirement. 042 * 043 * @see CombineFileRecordReader 044 * @see CombineFileInputFormat 045 */ 046 @InterfaceAudience.Public 047 @InterfaceStability.Stable 048 public abstract class CombineFileRecordReaderWrapper<K,V> 049 implements RecordReader<K,V> { 050 private final RecordReader<K,V> delegate; 051 052 protected CombineFileRecordReaderWrapper(FileInputFormat<K,V> inputFormat, 053 CombineFileSplit split, Configuration conf, Reporter reporter, Integer idx) 054 throws IOException { 055 FileSplit fileSplit = new FileSplit(split.getPath(idx), 056 split.getOffset(idx), 057 split.getLength(idx), 058 split.getLocations()); 059 060 delegate = inputFormat.getRecordReader(fileSplit, (JobConf)conf, reporter); 061 } 062 063 public boolean next(K key, V value) throws IOException { 064 return delegate.next(key, value); 065 } 066 067 public K createKey() { 068 return delegate.createKey(); 069 } 070 071 public V createValue() { 072 return delegate.createValue(); 073 } 074 075 public long getPos() throws IOException { 076 return delegate.getPos(); 077 } 078 079 public void close() throws IOException { 080 delegate.close(); 081 } 082 083 public float getProgress() throws IOException { 084 return delegate.getProgress(); 085 } 086 }