1.1 restoration
[mir.git] / source / mir / session / CommonsUploadedFileAdapter.java
index 4b607ca..968c004 100755 (executable)
  */
 package mir.session;
 
-import java.io.InputStream;
-
 import org.apache.commons.fileupload.FileItem;
 
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+
 public class CommonsUploadedFileAdapter implements UploadedFile {
   private FileItem fileItem;
 
@@ -40,14 +42,25 @@ public class CommonsUploadedFileAdapter implements UploadedFile {
     fileItem = aFileItem;
   }
 
-  public InputStream getInputStream() throws SessionExc, SessionFailure{
+  public void writeToFile(File aFile) throws SessionExc, SessionFailure {
+    try {
+      aFile.getParentFile().mkdirs();
+      fileItem.write(aFile);
+    }
+    catch (Exception e) {
+      e.printStackTrace();
+      throw new SessionFailure(e);
+    }
+  }
+
+  public InputStream getInputStream() throws SessionExc, SessionFailure {
     try {
       return fileItem.getInputStream();
     }
-    catch (Throwable t) {
-      throw new SessionFailure(t);
+    catch (IOException e) {
+      throw new SessionFailure(e);
     }
-  };
+  }
 
   public String getFileName() {
     return fileItem.getName();