001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.flatfile.util; 018 019import java.io.BufferedInputStream; 020import java.io.InputStream; 021import java.io.Serializable; 022 023import org.apache.commons.lang3.Validate; 024 025/** 026 * Filter factory designed for use with {@link InputFilteringDynamicField}. 027 * @version $Revision: 1301244 $ $Date: 2012-03-15 17:16:23 -0500 (Thu, 15 Mar 2012) $ 028 */ 029public abstract class FilterFactory implements Serializable { 030 /** Serialization version */ 031 private static final long serialVersionUID = -172092815628700041L; 032 033 /** 034 * Get an InputStream that filters the specified {@link InputStream} 035 * @param is the {@link InputStream} to filter 036 * @return an {@link InputStream} 037 */ 038 public final InputStream getFilter(final InputStream is) { 039 return iGetFilter(Validate.notNull(is).markSupported() ? is 040 : new BufferedInputStream(is)); 041 } 042 043 /** 044 * Template method to be implemented by subclasses. 045 * @param markIsSupported guaranteed to support mark()/reset(). 046 * @return an {@link InputStream} 047 */ 048 protected abstract InputStream iGetFilter(InputStream markIsSupported); 049}