001/* 002 * Copyright (c) 2016-2018 Chris K Wensel <chris@wensel.net>. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package cascading.tap; 022 023import java.beans.ConstructorProperties; 024import java.io.IOException; 025import java.util.function.Function; 026 027import cascading.flow.FlowProcess; 028import cascading.tap.type.FileType; 029 030/** 031 * Class FileAdaptorTap extends {@link AdaptorTap} to provide adapted {@link FileType} interface semantics. 032 * <p> 033 * The adapted {@link Tap} must be of type FileType. 034 */ 035public class FileAdaptorTap<TConfig, TInput, TOutput, OConfig, OInput, OOutput> extends AdaptorTap<TConfig, TInput, TOutput, OConfig, OInput, OOutput> implements FileType<TConfig> 036 { 037 @ConstructorProperties({"original", "processProvider", "configProvider"}) 038 public FileAdaptorTap( Tap<OConfig, OInput, OOutput> original, Function<FlowProcess<? extends TConfig>, FlowProcess<? extends OConfig>> processProvider, Function<TConfig, OConfig> configProvider ) 039 { 040 super( original, processProvider, configProvider ); 041 042 if( !( original instanceof FileType ) ) 043 throw new IllegalArgumentException( "original Tap must be of type: " + FileType.class.getName() ); 044 } 045 046 protected FileType<TConfig> getFileOriginal() 047 { 048 return (FileType<TConfig>) getOriginal(); 049 } 050 051 @Override 052 public boolean isDirectory( FlowProcess<? extends TConfig> flowProcess ) throws IOException 053 { 054 return getFileOriginal().isDirectory( (FlowProcess<? extends TConfig>) processProvider.apply( flowProcess ) ); 055 } 056 057 @Override 058 public boolean isDirectory( TConfig conf ) throws IOException 059 { 060 return getFileOriginal().isDirectory( (TConfig) configProvider.apply( conf ) ); 061 } 062 063 @Override 064 public String[] getChildIdentifiers( FlowProcess<? extends TConfig> flowProcess ) throws IOException 065 { 066 return getFileOriginal().getChildIdentifiers( (TConfig) processProvider.apply( flowProcess ) ); 067 } 068 069 @Override 070 public String[] getChildIdentifiers( TConfig conf ) throws IOException 071 { 072 return getFileOriginal().getChildIdentifiers( (TConfig) configProvider.apply( conf ) ); 073 } 074 075 @Override 076 public String[] getChildIdentifiers( FlowProcess<? extends TConfig> flowProcess, int depth, boolean fullyQualified ) throws IOException 077 { 078 return getFileOriginal().getChildIdentifiers( (TConfig) processProvider.apply( flowProcess ), depth, fullyQualified ); 079 } 080 081 @Override 082 public String[] getChildIdentifiers( TConfig conf, int depth, boolean fullyQualified ) throws IOException 083 { 084 return getFileOriginal().getChildIdentifiers( (TConfig) configProvider.apply( conf ), depth, fullyQualified ); 085 } 086 087 @Override 088 public long getSize( FlowProcess<? extends TConfig> flowProcess ) throws IOException 089 { 090 return getFileOriginal().getSize( (TConfig) processProvider.apply( flowProcess ) ); 091 } 092 093 @Override 094 public long getSize( TConfig conf ) throws IOException 095 { 096 return getFileOriginal().getSize( (TConfig) configProvider.apply( conf ) ); 097 } 098 }