01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.outerj.daisy.frontend.editor;
17:
18: import org.outerj.daisy.repository.PartDataSource;
19:
20: import java.io.InputStream;
21: import java.io.IOException;
22:
23: public class UploadPartDataSource implements PartDataSource {
24: private final org.apache.cocoon.servlet.multipart.Part part;
25:
26: public UploadPartDataSource(
27: org.apache.cocoon.servlet.multipart.Part part) {
28: this .part = part;
29: }
30:
31: public InputStream createInputStream() throws IOException {
32: // Here we make the assumption that part.getInputStream() will always
33: // return a new input stream, which is the case in Cocoon's PartOnDisk
34: // implementation, but not in the PartInMemory implementation.
35: try {
36: return part.getInputStream();
37: } catch (Exception e) {
38: throw new RuntimeException(
39: "Error getting upload input stream.", e);
40: }
41: }
42:
43: public long getSize() {
44: return part.getSize();
45: }
46:
47: }
|