KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > value > MultipleStreamableValue


1 package org.apache.slide.projector.value;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.io.InputStream JavaDoc;
7
8 import org.apache.slide.projector.util.StreamHelper;
9
10 /**
11  * @version $Revision: 1.3 $
12  */

13
14 public class MultipleStreamableValue extends AbstractStreamableValue {
15     private StreamableValue value;
16     private byte[] bytes;
17
18     public MultipleStreamableValue(StreamableValue resource) {
19         this.value = resource;
20     }
21
22     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
23         if ( bytes == null ) {
24             ByteArrayOutputStream JavaDoc outputStream = new ByteArrayOutputStream JavaDoc();
25             StreamHelper.copy(value.getInputStream(), outputStream);
26             bytes = outputStream.toByteArray();
27         }
28         return new ByteArrayInputStream JavaDoc(bytes);
29     }
30
31     public int getContentLength() {
32         return value.getContentLength();
33     }
34
35     public boolean isDocument() {
36         return value.isDocument();
37     }
38
39     public String JavaDoc getContentType() {
40         return value.getContentType();
41     }
42
43     public String JavaDoc getCharacterEncoding() {
44         return value.getCharacterEncoding();
45     }
46 }
47
Popular Tags