01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
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: package org.apache.cocoon.servlet.multipart;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.util.Map;
22:
23: /**
24: * This class represents a file part parsed from a http post stream.
25: *
26: * @author <a href="mailto:j.tervoorde@home.nl">Jeroen ter Voorde</a>
27: * @version CVS $Id: PartInMemory.java 433543 2006-08-22 06:22:54Z crossley $
28: */
29: public class PartInMemory extends Part {
30:
31: private InputStream in;
32:
33: private int size;
34:
35: /**
36: * Constructor PartInMemory
37: *
38: * @param headers
39: * @param in
40: * @param size
41: */
42: public PartInMemory(Map headers, InputStream in, int size) {
43: super (headers);
44: this .in = in;
45: this .size = size;
46: }
47:
48: /**
49: * Returns the filename
50: */
51: public String getFileName() {
52: return (String) headers.get("filename");
53: }
54:
55: /**
56: * Returns the filesize in bytes
57: */
58: public int getSize() {
59: return this .size;
60: }
61:
62: /**
63: * Returns a (ByteArray)InputStream containing the file data
64: *
65: * @throws IOException
66: */
67: public InputStream getInputStream() throws IOException {
68: if (this .in != null) {
69: return this .in;
70: } else {
71: throw new IllegalStateException(
72: "This part has already been disposed.");
73: }
74: }
75:
76: /**
77: * Clean the byte array content buffer holding part data
78: */
79: public void dispose() {
80: this.in = null;
81: }
82: }
|