PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/razpub/src/com/razie/pub/playground/MediaRssDrawStream.scala

http://razpub.googlecode.com/
Scala | 71 lines | 31 code | 9 blank | 31 comment | 1 complexity | a4b0d7465ab3a0f037d7224ced69925d MD5 | raw file
 1/**
 2 * Razvan's public code. Copyright 2008 based on Apache license (share alike) see LICENSE.txt for
 3 * details. No warranty implied nor any liability assumed for this code.
 4 */
 5package com.razie.pub.playground
 6
 7import java.io.ByteArrayOutputStream;
 8import java.io.IOException;
 9
10import razie.draw.DrawStream;
11import razie.draw.Renderer;
12import razie.draw.SimpleDrawStream;
13import razie.draw.Technology;
14
15/**
16 * TODO 2-2 complete and use
17 */
18object MediaRssDrawStream  {
19val RSS_BEGIN="<rss>"
20val RSS_END="</rss>"
21	
22    /** use this to stream to some other stream (http etc)...) */
23    def make(wrapped:DrawStream): MediaRssDrawStream = {
24        val res = new MediaRssDrawStream(wrapped)
25//        res.switchTechnology(Renderer.Technology.HTML)
26        wrapped.write(RSS_BEGIN)
27        res
28    }
29
30    /**
31     * use this to stream into a string..use toString at the end
32     *
33     * @throws IOException
34     */
35    def make() : MediaRssDrawStream = {
36        val res = new MediaRssDrawStream(new SimpleDrawStream(Technology.MEDIA_RSS, new ByteArrayOutputStream()));
37        // buffer = (ByteArrayOutputStream) ((SimpleDrawStream) super.proxied).out;
38        // ((SimpleDrawStream) proxied).writeBytes(UpnpUtils.DIDL_BEG.getBytes());
39//        res.renderObjectToStream(RSS_BEGIN);
40        res
41    }
42}
43
44/**
45 * a drawing stream for DIDL lists, used in UPNP. Will use UPNP as the rendering technology and add
46 * DIDL header/footer.
47 *
48 * to stream to an http socket use new DIDLDrawStream (new HttpDrawStream(socket)) to stream
49 * directly to a socket use new DIDLDrawStream (new SimpleDrawStream(socket.getOutputStream)) to
50 * stream to string use new DIDLDrawStream () and toString() at the end
51 *
52 * @author razvanc
53 * @version $Id$
54 *
55 */
56class MediaRssDrawStream (wrapped:DrawStream) extends razie.draw.DrawStream.DrawStreamWrapper(wrapped) {
57
58    var closed:Boolean = false;
59
60    override def close() = {
61        // TODO not correct, since BG threads may still produce stuff...
62        if (!closed)
63            renderObjectToStream(MediaRssDrawStream.RSS_END);
64        // ((SimpleDrawStream) proxied).writeBytes(UpnpUtils.DIDL_END.getBytes());
65        closed = true;
66    }
67
68    override def toString() = {
69        proxied.toString();
70    }
71}