KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > servlet > multipart > PartInMemory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.servlet.multipart;
17
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
20 import java.util.Map JavaDoc;
21
22 /**
23  * This class represents a file part parsed from a http post stream.
24  *
25  * @author <a HREF="mailto:j.tervoorde@home.nl">Jeroen ter Voorde</a>
26  * @version CVS $Id: PartInMemory.java 280876 2005-09-14 15:44:29Z sylvain $
27  */

28 public class PartInMemory extends Part {
29
30     private InputStream JavaDoc in;
31
32     private int size;
33
34     /**
35      * Constructor PartInMemory
36      *
37      * @param headers
38      * @param in
39      * @param size
40      */

41     public PartInMemory(Map JavaDoc headers, InputStream JavaDoc in, int size) {
42         super(headers);
43         this.in = in;
44         this.size = size;
45     }
46
47     /**
48      * Returns the filename
49      */

50     public String JavaDoc getFileName() {
51         return (String JavaDoc) headers.get("filename");
52     }
53
54     /**
55      * Returns the filesize in bytes
56      */

57     public int getSize() {
58         return this.size;
59     }
60
61     /**
62      * Returns a (ByteArray)InputStream containing the file data
63      *
64      * @throws Exception
65      */

66     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
67         if (this.in != null) {
68             return this.in;
69         } else {
70             throw new IllegalStateException JavaDoc("This part has already been disposed.");
71         }
72     }
73     
74     /**
75      * Clean the byte array content buffer holding part data
76      */

77     public void dispose() {
78         this.in = null;
79     }
80 }
81
Popular Tags