01: // $Id: UdpHeader.java,v 1.8 2005/04/20 09:10:09 belaban Exp $
02:
03: package org.jgroups.protocols;
04:
05: import org.jgroups.Header;
06: import org.jgroups.util.Streamable;
07:
08: import java.io.*;
09:
10: public class UdpHeader extends Header implements Streamable {
11: public String channel_name = null;
12: int size = 0;
13:
14: public UdpHeader() {
15: } // used for externalization
16:
17: public UdpHeader(String n) {
18: channel_name = n;
19: if (channel_name != null)
20: size = channel_name.length() + 2; // +2 for writeUTF()
21: }
22:
23: public String toString() {
24: return "[UDP:channel_name=" + channel_name + ']';
25: }
26:
27: public long size() {
28: return size;
29: }
30:
31: public void writeExternal(ObjectOutput out) throws IOException {
32: out.writeUTF(channel_name);
33: }
34:
35: public void readExternal(ObjectInput in) throws IOException,
36: ClassNotFoundException {
37: channel_name = in.readUTF();
38: }
39:
40: public void writeTo(DataOutputStream out) throws IOException {
41: out.writeUTF(channel_name);
42: }
43:
44: public void readFrom(DataInputStream in) throws IOException,
45: IllegalAccessException, InstantiationException {
46: channel_name = in.readUTF();
47: if (channel_name != null)
48: size = channel_name.length() + 2; // +2 for writeUTF()
49: }
50: }
|