home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 1.5 KB | 38 lines |
- // A text message in the multi-user system
-
- // Written by Bernie Roehl, December 1996
-
- package multi;
-
- import java.io.*;
-
- public class TextMessage {
- short type; // 0 for public, 1 for group, 2 for private
- public final static int PUBLIC = 0, GROUP = 1, PRIVATE = 2;
- int ssrc; // synchronization source
- String message; // the actual message itself
-
- public short getType() { return type; }
- public int getTextId() { return ssrc; }
- public String getText() { return message; }
-
- public TextMessage(byte[] buffer) throws IOException {
- ByteArrayInputStream bin = new ByteArrayInputStream(buffer);
- DataInputStream in = new DataInputStream(bin);
- in.readByte(); // version, padding, extension, CSRC count
- if (in.readByte() != 80) // payload type, marker is zero
- throw new IOException("bad text payload type");
- in.readShort(); // sequence number
- in.readInt(); // timestamp
- ssrc = in.readInt(); // text SSRC
- type = in.readShort();
- int len = in.readShort();
- System.out.println("Length field claims" + len + " bytes");
- byte[] textbuffer = new byte[len];
- in.readFully(textbuffer);
- message = new String(textbuffer, 0, 0, len);
- System.out.println("Actual text message has length of " + message.length());
- }
- }
-
-