01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.servlet.upload;
04:
05: import java.io.IOException;
06:
07: /**
08: * Encapsulates base for uploaded file. Its instance may be
09: * 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: protected 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:
30: // ---------------------------------------------------------------- size and validity
31:
32: protected boolean uploaded = true;
33: protected int size = -1;
34:
35: /**
36: * Returns the file upload size.
37: */
38: public int getSize() {
39: return size;
40: }
41:
42: /**
43: * Returns <code>true</code> if file was uploaded correctly.
44: */
45: public boolean isUploaded() {
46: return uploaded;
47: }
48:
49: // ---------------------------------------------------------------- process
50:
51: /**
52: * Process request input stream. Note that file size is unknown at this point.
53: * Therefore, the implementation <b>should</b> set the <b>size</b> attribute
54: * after sucesfull processing.
55: *
56: * @see MultipartRequestInputStream
57: */
58: protected abstract void processStream() throws IOException;
59:
60: // ---------------------------------------------------------------- toString
61:
62: /**
63: * Returns basic information about the uploaded file.
64: */
65: @Override
66: public String toString() {
67: return "FileUpload: uploaded=[" + uploaded + "] field=["
68: + header.getFormFieldName() + "] name=["
69: + header.getFileName() + "] size=[" + size + ']';
70: }
71: }
|