1 package hudson.remoting; 2 3 import java.io.IOException ; 4 import java.io.ObjectInputStream ; 5 import java.io.ObjectOutputStream ; 6 import java.io.Serializable ; 7 import java.io.Writer ; 8 9 28 public final class RemoteWriter extends Writer implements Serializable { 29 36 private transient Writer core; 37 38 public RemoteWriter(Writer core) { 39 this.core = core; 40 } 41 42 private void writeObject(ObjectOutputStream oos) throws IOException { 43 int id = Channel.current().export(core); 44 oos.writeInt(id); 45 } 46 47 private void readObject(ObjectInputStream ois) throws IOException , ClassNotFoundException { 48 final Channel channel = Channel.current(); 49 assert channel !=null; 50 51 this.core = new ProxyWriter(channel, ois.readInt()); 52 } 53 54 private static final long serialVersionUID = 1L; 55 56 57 public void write(int c) throws IOException { 63 core.write(c); 64 } 65 66 public void write(char[] cbuf) throws IOException { 67 core.write(cbuf); 68 } 69 70 public void write(char[] cbuf, int off, int len) throws IOException { 71 core.write(cbuf, off, len); 72 } 73 74 public void write(String str) throws IOException { 75 core.write(str); 76 } 77 78 public void write(String str, int off, int len) throws IOException { 79 core.write(str, off, len); 80 } 81 82 public Writer append(CharSequence csq) throws IOException { 83 return core.append(csq); 84 } 85 86 public Writer append(CharSequence csq, int start, int end) throws IOException { 87 return core.append(csq, start, end); 88 } 89 90 public Writer append(char c) throws IOException { 91 return core.append(c); 92 } 93 94 public void flush() throws IOException { 95 core.flush(); 96 } 97 98 public void close() throws IOException { 99 core.close(); 100 } 101 } 102 | Popular Tags |