KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > servlet > upload > FileUpload


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.servlet.upload;
4
5 import java.io.*;
6
7 /**
8  * Encapsulates base for uploaded file. Its instance may be
9  * either valid, when it represent an uploaded file, or invalid
10  * when uploaded file doesn't exist or there was a problem with it.
11  *
12  * @see jodd.servlet.upload.MultipartRequest
13  */

14 public abstract class FileUpload {
15
16     protected MultipartRequestInputStream input;
17     protected FileUploadHeader header;
18
19     public FileUpload(MultipartRequestInputStream input) {
20         this.input = input;
21         this.header = input.lastHeader;
22     }
23
24     // ---------------------------------------------------------------- header
25

26     public FileUploadHeader getHeader() {
27         return header;
28     }
29     // ---------------------------------------------------------------- size and validity
30

31     protected boolean uploaded = true;
32     protected int size = -1;
33
34     /**
35      * Returns the file upload size.
36      */

37     public int getSize() {
38         return size;
39     }
40
41     /**
42      * Returns <code>true</code> if file was uploaded correctly.
43      */

44     public boolean isUploaded() {
45         return uploaded;
46     }
47
48     // ---------------------------------------------------------------- process
49

50     /**
51      * Process request input stream. Note that file size is unknown at this point.
52      * Therefore, the implementation <b>should</b> set the <b>size</b> attribute
53      * after sucesfull processing.
54      *
55      * @see MultipartRequestInputStream
56      */

57     protected abstract void processStream() throws IOException;
58
59     // ---------------------------------------------------------------- toString
60

61     /**
62      * Returns basic information about the uploaded file.
63      */

64     public String JavaDoc toString() {
65         return "FileUpload: uploaded=[" + uploaded + "] field=[" + header.getFormFieldName() +
66                 "] name=[" + header.getFileName() + "] size=[" + size + ']';
67     }
68 }
Popular Tags