1 /* 2 * Copyright 2004-2010 the Seasar Foundation and the Others. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 * either express or implied. See the License for the specific language 14 * governing permissions and limitations under the License. 15 */ 16 17 package org.seasar.cubby.converter.impl; 18 19 import java.io.IOException; 20 import java.io.InputStream; 21 22 import org.apache.commons.fileupload.FileItem; 23 import org.seasar.cubby.converter.Converter; 24 25 /** 26 * {@link FileItem}から{@link InputStream}へ変換する{@link Converter}です。 27 * 28 * @author baba 29 */ 30 public class InputStreamFileItemConverter extends AbstractFileItemConverter { 31 32 /** 33 * {@inheritDoc} 34 * 35 * @return {@link InputStream}のクラスを返します。 36 */ 37 public Class<?> getObjectType() { 38 return InputStream.class; 39 } 40 41 /** 42 * {@inheritDoc} 43 * <p> 44 * 指定された{@link FileItem}から取得した{@link InputStream}を返します。変換時に 45 * {@link IOException}が発生した場合は <code>null</code> を返します。 46 * </p> 47 * 48 * @return 指定された{@link FileItem}から取得した{@link InputStream} 49 * @see FileItem#getInputStream() 50 */ 51 @Override 52 protected Object convert(final FileItem fileItem) { 53 try { 54 return fileItem.getInputStream(); 55 } catch (final IOException e) { 56 return null; 57 } 58 } 59 60 }