Source code: org/lucane/proxy/Forwarder.java
1 /*
2 * Lucane - a collaborative platform
3 * Copyright (C) 2002 Vincent Fiack <vincent@lucane.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 package org.lucane.proxy;
20
21 import org.lucane.common.*;
22
23 /**
24 * A forwarder simply writes to an OutputStream
25 * what it has read in an InputStream
26 */
27 public class Forwarder
28 extends Thread
29 {
30 ObjectConnection read;
31 ObjectConnection write;
32
33 /**
34 * Creates a new Forwarder object.
35 */
36 public Forwarder(ObjectConnection read, ObjectConnection write)
37 {
38 this.read = read;
39 this.write = write;
40 }
41
42 /**
43 * Usefull to be run as a new Thread.
44 * Copy a stream to another
45 */
46 public void run()
47 {
48 try
49 {
50 while(true)
51 {
52 write.writeObject(read.readObject());
53 }
54
55 }
56 catch(Exception e)
57 {
58 read.close();
59 write.close();
60 Logging.getLogger().warning("Forwarder Error : " + e);
61 }
62 }
63 }