KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > protocols > UdpHeader


1 // $Id: UdpHeader.java,v 1.8 2005/04/20 09:10:09 belaban Exp $
2

3 package org.jgroups.protocols;
4
5
6 import org.jgroups.Header;
7 import org.jgroups.util.Streamable;
8
9 import java.io.*;
10
11
12
13
14 public class UdpHeader extends Header implements Streamable {
15     public String JavaDoc channel_name=null;
16     int size=0;
17
18     public UdpHeader() {
19     } // used for externalization
20

21     public UdpHeader(String JavaDoc n) {
22         channel_name=n;
23         if(channel_name != null)
24             size=channel_name.length()+2; // +2 for writeUTF()
25
}
26
27     public String JavaDoc toString() {
28         return "[UDP:channel_name=" + channel_name + ']';
29     }
30
31
32     public long size() {
33         return size;
34     }
35
36     public void writeExternal(ObjectOutput out) throws IOException {
37         out.writeUTF(channel_name);
38     }
39
40
41     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException JavaDoc {
42         channel_name=in.readUTF();
43     }
44
45
46     public void writeTo(DataOutputStream out) throws IOException {
47         out.writeUTF(channel_name);
48     }
49
50     public void readFrom(DataInputStream in) throws IOException, IllegalAccessException JavaDoc, InstantiationException JavaDoc {
51         channel_name=in.readUTF();
52         if(channel_name != null)
53             size=channel_name.length()+2; // +2 for writeUTF()
54
}
55 }
56
Popular Tags