1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.oscar.entity;
20
21 import java.io.ByteArrayOutputStream;
22 import java.io.IOException;
23
24 import net.sf.dexterim.codec.HexPrinter;
25
26 import org.apache.commons.lang.builder.ToStringBuilder;
27
28 /***
29 * @author christoph
30 */
31 public class Snac {
32
33 private int family;
34 private int type;
35 private int flags;
36 private int request;
37
38 private byte data[];
39
40 public Snac() {
41 this.request = 0x0000;
42 }
43
44 public Snac(int family, int type, int flags) {
45 this();
46
47 this.family = family;
48 this.type = type;
49 this.flags = flags;
50 }
51
52 /***
53 * @return
54 */
55 public int getFamily() {
56 return family;
57 }
58
59 /***
60 * @return
61 */
62 public int getFlags() {
63 return flags;
64 }
65
66 /***
67 * @return
68 */
69 public int getRequest() {
70 return request;
71 }
72
73 /***
74 * @param request
75 */
76 public void setRequest(int request) {
77 this.request = request;
78 }
79
80 /***
81 * @return
82 */
83 public int getType() {
84 return type;
85 }
86
87 /***
88 * @return
89 */
90 public byte[] getData() {
91 return data;
92 }
93
94 /***
95 * @param data
96 */
97 public void setData(byte[] data) {
98 this.data = data;
99 }
100
101 public String toString() {
102 return new ToStringBuilder(this).append(
103 "family", family).append("type", type).append("falgs", flags).append(
104 "request id", request).append("data", HexPrinter.format(this.data))
105 .toString();
106 }
107
108 public byte[] toByteArray() {
109 ByteArrayOutputStream out = new ByteArrayOutputStream();
110
111 try {
112
113 out.write(new Word(getFamily()).toByteArray());
114 out.write(new Word(getType()).toByteArray());
115 out.write(new Word(getFlags()).toByteArray());
116 out.write(new DWord(request).toByteArray());
117
118 if (getData() != null) {
119 out.write(getData());
120 }
121 } catch (IOException e) {
122 e.printStackTrace();
123 }
124
125 return out.toByteArray();
126 }
127 }