1 /*
2 * Copyright 2004-2008 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 package org.seasar.cubby.dxo.converter.impl;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20
21 import org.apache.commons.fileupload.FileItem;
22 import org.seasar.framework.log.Logger;
23
24 /**
25 * {@link FileItem}から{@link InputStream}へ変換する{@link org.seasar.extension.dxo.converter.Converter}です。
26 *
27 * @author baba
28 * @since 1.0.0
29 */
30 public class InputStreamConverter extends AbstractFileItemConverter {
31
32 /** ロガー。 */
33 private static final Logger logger = Logger
34 .getLogger(InputStreamConverter.class);
35
36 /**
37 * {@inheritDoc}
38 *
39 * @return {@link InputStream}のクラスを返します。
40 */
41 @SuppressWarnings("unchecked")
42 public Class getDestClass() {
43 return InputStream.class;
44 }
45
46 /**
47 * {@inheritDoc}
48 * <p>
49 * 指定された{@link FileItem}から取得した{@link InputStream}を返します。変換時に{@link IOException}が発生した場合は
50 * <code>null</code> を返します。
51 * </p>
52 *
53 * @return 指定された{@link FileItem}から取得した{@link InputStream}
54 * @see FileItem#getInputStream()
55 */
56 @Override
57 protected Object convert(final FileItem fileItem) {
58 try {
59 return fileItem.getInputStream();
60 } catch (final IOException e) {
61 logger.log(e);
62 return null;
63 }
64 }
65
66 }