01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package org.restlet.resource;
20:
21: import java.io.IOException;
22: import java.io.InputStream;
23: import java.io.OutputStream;
24:
25: import org.restlet.data.MediaType;
26: import org.restlet.util.ByteUtils;
27:
28: /**
29: * Representation based on a BIO output stream. This class is a good basis to write
30: * your own representations, especially for the dynamic and large ones. For this you
31: * just need to create a subclass and override the abstract
32: * Representation.write(OutputStream) method. This method will later be called back
33: * by the connectors when the actual representation's content is needed.
34: *
35: * @author Jerome Louvel (contact@noelios.com)
36: */
37: public abstract class OutputRepresentation extends StreamRepresentation {
38: /**
39: * Constructor.
40: *
41: * @param mediaType
42: * The representation's mediaType.
43: */
44: public OutputRepresentation(MediaType mediaType) {
45: super (mediaType);
46: }
47:
48: /**
49: * Constructor.
50: *
51: * @param mediaType
52: * The representation's mediaType.
53: * @param expectedSize
54: * The expected input stream size.
55: */
56: public OutputRepresentation(MediaType mediaType, long expectedSize) {
57: super (mediaType);
58: setSize(expectedSize);
59: }
60:
61: /**
62: * Returns a stream with the representation's content. Internally, it uses a
63: * writer thread and a pipe stream.
64: *
65: * @return A stream with the representation's content.
66: */
67: public InputStream getStream() throws IOException {
68: return ByteUtils.getStream(this );
69: }
70:
71: /**
72: * Writes the representation to a byte stream.
73: *
74: * @param outputStream
75: * The output stream.
76: */
77: public abstract void write(OutputStream outputStream)
78: throws IOException;
79:
80: }
|