/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. */
  5. package com.razie.pub.playground
  6. import java.io.ByteArrayOutputStream;
  7. import java.io.IOException;
  8. import razie.draw.DrawStream;
  9. import razie.draw.Renderer;
  10. import razie.draw.SimpleDrawStream;
  11. import razie.draw.Technology;
  12. /**
  13. * TODO 2-2 complete and use
  14. */
  15. object MediaRssDrawStream {
  16. val RSS_BEGIN="<rss>"
  17. val RSS_END="</rss>"
  18. /** use this to stream to some other stream (http etc)...) */
  19. def make(wrapped:DrawStream): MediaRssDrawStream = {
  20. val res = new MediaRssDrawStream(wrapped)
  21. // res.switchTechnology(Renderer.Technology.HTML)
  22. wrapped.write(RSS_BEGIN)
  23. res
  24. }
  25. /**
  26. * use this to stream into a string..use toString at the end
  27. *
  28. * @throws IOException
  29. */
  30. def make() : MediaRssDrawStream = {
  31. val res = new MediaRssDrawStream(new SimpleDrawStream(Technology.MEDIA_RSS, new ByteArrayOutputStream()));
  32. // buffer = (ByteArrayOutputStream) ((SimpleDrawStream) super.proxied).out;
  33. // ((SimpleDrawStream) proxied).writeBytes(UpnpUtils.DIDL_BEG.getBytes());
  34. // res.renderObjectToStream(RSS_BEGIN);
  35. res
  36. }
  37. }
  38. /**
  39. * a drawing stream for DIDL lists, used in UPNP. Will use UPNP as the rendering technology and add
  40. * DIDL header/footer.
  41. *
  42. * to stream to an http socket use new DIDLDrawStream (new HttpDrawStream(socket)) to stream
  43. * directly to a socket use new DIDLDrawStream (new SimpleDrawStream(socket.getOutputStream)) to
  44. * stream to string use new DIDLDrawStream () and toString() at the end
  45. *
  46. * @author razvanc
  47. * @version $Id$
  48. *
  49. */
  50. class MediaRssDrawStream (wrapped:DrawStream) extends razie.draw.DrawStream.DrawStreamWrapper(wrapped) {
  51. var closed:Boolean = false;
  52. override def close() = {
  53. // TODO not correct, since BG threads may still produce stuff...
  54. if (!closed)
  55. renderObjectToStream(MediaRssDrawStream.RSS_END);
  56. // ((SimpleDrawStream) proxied).writeBytes(UpnpUtils.DIDL_END.getBytes());
  57. closed = true;
  58. }
  59. override def toString() = {
  60. proxied.toString();
  61. }
  62. }