PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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