Source code: plugins/IcqEngine/protocol/ByteMessage.java
1 /*
2 * ByteMessage.java
3 *
4 * Created on October 31, 2002, 6:39 PM
5 */
6
7 package plugins.IcqEngine.protocol;
8
9 /**
10 *
11 * @author Tobias Riemer
12 */
13 public class ByteMessage {
14
15 // icq messages could not be longer than 450
16 static final int MAX_BYTES = 450;
17
18 //ByteArray bytes = new ByteArray();
19 private byte[] bytes = new byte[MAX_BYTES];
20 private int length = 0;
21 /** Creates a new instance of ByteMessage */
22 public ByteMessage() {
23 }
24
25 public ByteMessage(byte[] bytes, int length) {
26 this.bytes = bytes;
27 this.length = length;
28 }
29
30 public byte[] getBytes() {
31 return bytes;
32 };
33
34 public void concat(byte[] b,int len) {
35 for(int j=0;j<len;j++) {
36 bytes[length+j] = b[j];
37 }
38 length += len;
39 }
40
41 public void concat(int i, int len) {
42 byte[] b = ByteEncoder.encode(i,len);
43 concat(b,len);
44 }
45
46 public void concatHex(String hex) {
47 byte[] b = ByteEncoder.encodeHex(hex);
48 concat(b,b.length);
49 }
50
51 public void concat(String str) {
52 byte[] b = ByteEncoder.encode(str);
53 concat(b,b.length);
54 }
55
56 public void concatIp(String ip) {
57 byte[] b = ByteEncoder.encodeIp(ip);
58 concat(b,b.length);
59 }
60
61
62 public String toString() {
63 String str = "";
64 for (int i=0;i<length;i++) {
65 String hex = "00";
66 if ((int)bytes[i] >= 0)
67 hex = Integer.toHexString((int)bytes[i]);
68 else
69 hex = Integer.toHexString((int)(256+bytes[i]));
70 if (hex.length() == 1) hex = "0" + hex;
71 str += hex + " ";
72 //System.out.println("i: " + i + "b: " + (int)bytes[i] + "h: " + hex);
73 }
74 return str;
75 }
76
77 public int length() {
78 return length;
79 }
80
81 }