01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: // Created on Jun 12, 2006
18: package edu.iu.uis.eden.test.web;
19:
20: import java.io.File;
21: import java.io.FileInputStream;
22: import java.io.FileNotFoundException;
23: import java.io.IOException;
24: import java.io.InputStream;
25:
26: import org.apache.struts.upload.FormFile;
27: import org.springframework.util.FileCopyUtils;
28:
29: /**
30: * A mock FormFile which is constructed directly from a File on disk
31: * @author Aaron Hamid (arh14 at cornell dot edu)
32: */
33: public class MockFormFile implements FormFile {
34: private File file;
35: private String fileName;
36: private int fileSize;
37: private String contentType = "application/octet-stream";
38:
39: public MockFormFile(File file) {
40: this .file = file;
41: this .fileName = file.getName();
42: this .fileSize = (int) file.length();
43: }
44:
45: public String getContentType() {
46: return contentType;
47: }
48:
49: public void setContentType(String contentType) {
50: this .contentType = contentType;
51: }
52:
53: public byte[] getFileData() throws FileNotFoundException,
54: IOException {
55: return FileCopyUtils.copyToByteArray(file);
56: }
57:
58: public String getFileName() {
59: return fileName;
60: }
61:
62: public void setFileName(String fileName) {
63: this .fileName = fileName;
64: }
65:
66: public int getFileSize() {
67: return fileSize;
68: }
69:
70: public void setFileSize(int fileSize) {
71: this .fileSize = fileSize;
72: }
73:
74: public InputStream getInputStream() throws FileNotFoundException,
75: IOException {
76: return new FileInputStream(file);
77: }
78:
79: public void destroy() {
80: }
81:
82: public String toString() {
83: return "[MockFormFile: " + file + "]";
84: }
85: }
|