001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.view.client.web.struts; 018 019import java.io.IOException; 020import java.io.InputStream; 021import java.io.OutputStream; 022import javax.activation.DataSource; 023import org.apache.struts.upload.FormFile; 024 025public class FormFileDataSource 026 implements DataSource { 027 028 private FormFile formFile; 029 030 /** Creates a new instance of FormFileDataSource */ 031 public FormFileDataSource(FormFile formFile) { 032 this.formFile = formFile; 033 } 034 035 @Override 036 public InputStream getInputStream() 037 throws IOException { 038 return formFile.getInputStream(); 039 } 040 041 @Override 042 public OutputStream getOutputStream() 043 throws IOException { 044 throw new UnsupportedOperationException(); 045 } 046 047 @Override 048 public String getContentType(){ 049 return formFile.getContentType(); 050 } 051 052 @Override 053 public String getName(){ 054 return formFile.getFileName(); 055 } 056 057}