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.fs.FileSystem; 026 import org.apache.hadoop.mapred.JobConf; 027 import org.apache.hadoop.mapred.OutputFormat; 028 import org.apache.hadoop.mapred.RecordWriter; 029 import org.apache.hadoop.mapred.Reporter; 030 import org.apache.hadoop.util.Progressable; 031 032 /** 033 * FilterOutputFormat is a convenience class that wraps OutputFormat. 034 * @deprecated Use 035 * {@link org.apache.hadoop.mapreduce.lib.output.FilterOutputFormat} instead. 036 */ 037 @Deprecated 038 @InterfaceAudience.Public 039 @InterfaceStability.Stable 040 public class FilterOutputFormat<K, V> implements OutputFormat<K, V> { 041 042 protected OutputFormat<K,V> baseOut; 043 044 public FilterOutputFormat () { 045 this.baseOut = null; 046 } 047 048 /** 049 * Create a FilterOutputFormat based on the supplied output format. 050 * @param out the underlying OutputFormat 051 */ 052 public FilterOutputFormat (OutputFormat<K,V> out) { 053 this.baseOut = out; 054 } 055 056 public RecordWriter<K, V> getRecordWriter(FileSystem ignored, JobConf job, 057 String name, Progressable progress) throws IOException { 058 return getBaseOut().getRecordWriter(ignored, job, name, progress); 059 } 060 061 public void checkOutputSpecs(FileSystem ignored, JobConf job) 062 throws IOException { 063 getBaseOut().checkOutputSpecs(ignored, job); 064 } 065 066 private OutputFormat<K,V> getBaseOut() throws IOException { 067 if (baseOut == null) { 068 throw new IOException("Outputformat not set for FilterOutputFormat"); 069 } 070 return baseOut; 071 } 072 073 /** 074 * <code>FilterRecordWriter</code> is a convenience wrapper 075 * class that implements {@link RecordWriter}. 076 */ 077 078 public static class FilterRecordWriter<K,V> implements RecordWriter<K,V> { 079 080 protected RecordWriter<K,V> rawWriter = null; 081 082 public FilterRecordWriter() throws IOException { 083 rawWriter = null; 084 } 085 086 public FilterRecordWriter(RecordWriter<K,V> rawWriter) throws IOException { 087 this.rawWriter = rawWriter; 088 } 089 090 public void close(Reporter reporter) throws IOException { 091 getRawWriter().close(reporter); 092 } 093 094 public void write(K key, V value) throws IOException { 095 getRawWriter().write(key, value); 096 } 097 098 private RecordWriter<K,V> getRawWriter() throws IOException { 099 if (rawWriter == null) { 100 throw new IOException ("Record Writer not set for FilterRecordWriter"); 101 } 102 return rawWriter; 103 } 104 } 105 106 }