/razweb/src/com/razie/pubstage/comms/StrCommProxy.java

http://razpub.googlecode.com/ · Java · 51 lines · 27 code · 7 blank · 17 comment · 6 complexity · 086327e60a053e515aa2e6b4414cbc55 MD5 · raw file

  1. /**
  2. * Razvan's public code.
  3. * Copyright 2008 based on Apache license (share alike) see LICENSE.txt for details.
  4. */
  5. package com.razie.pubstage.comms;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import com.razie.pub.comms.Comms;
  9. /**
  10. * a two way STRING communication channel. Adds filtering functionality
  11. *
  12. * @author razvanc99
  13. *
  14. */
  15. public class StrCommProxy extends StrCommStream {
  16. List<IStrFilter> filters;
  17. private StrCommStream proxy;
  18. /** empty channel - is is null*/
  19. protected StrCommProxy(StrCommStream proxy) {
  20. this.proxy=proxy;
  21. }
  22. /** will read all incoming until the channel is empty */
  23. public String readAll() {
  24. String s = Comms.readStream(is);
  25. if (filters != null)
  26. for (IStrFilter f : filters)
  27. s = f.filter(s);
  28. return s;
  29. }
  30. /**
  31. * will read incoming until the end of line OR the channel is empty
  32. *
  33. * @return the next line in hte stream or NULL if empty
  34. */
  35. public String readLine() {
  36. return proxy.readLine();
  37. }
  38. public void setFilters(IStrFilter... f) {
  39. if (filters == null)
  40. filters = new ArrayList<IStrFilter>();
  41. for (IStrFilter fi : f)
  42. filters.add(fi);
  43. }
  44. }