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.EqualsBuilder;
27 import org.apache.commons.lang.builder.HashCodeBuilder;
28 import org.apache.commons.lang.builder.ToStringBuilder;
29
30 /***
31 * @author christoph
32 */
33 public class Flap {
34
35 private int id;
36 private int channel;
37 private int sequence;
38 private int length;
39 private byte data[];
40
41 /***
42 *
43 */
44 public Flap() {
45 }
46
47 public Flap(int id, int channel) {
48 this.id = id;
49 this.channel = channel;
50 }
51
52 /***
53 * @return
54 */
55 public int getChannel() {
56 return channel;
57 }
58
59 /***
60 * @param channel
61 */
62 public void setChannel(int channel) {
63 this.channel = channel;
64 }
65
66 /***
67 * @return
68 */
69 public int getId() {
70 return id;
71 }
72
73 /***
74 * @param id
75 */
76 public void setId(int id) {
77 this.id = id;
78 }
79
80 /***
81 * @return
82 */
83 public int getLength() {
84 return length;
85 }
86
87 /***
88 * @param length
89 */
90 public void setLength(int length) {
91 this.length = length;
92 }
93
94 /***
95 * @return
96 */
97 public int getSequence() {
98 return sequence;
99 }
100
101 /***
102 * @param sequence
103 */
104 public void setSequence(int sequence) {
105 this.sequence = sequence;
106 }
107
108 /***
109 * @return
110 */
111 public byte[] getData() {
112 return data;
113 }
114
115 /***
116 * @param data
117 */
118 public void setData(byte[] data) {
119 this.data = data;
120 }
121
122
123
124
125
126
127 public boolean equals(Object obj) {
128 if (!(obj instanceof Flap)) {
129 return false;
130 }
131
132 Flap other = (Flap) obj;
133
134 return new EqualsBuilder().append(id, other.id).append(channel,
135 other.channel).append(sequence, other.sequence)
136 .append(data, other.data).isEquals();
137 }
138
139 /***
140 * @see java.lang.Object#hashCode()
141 */
142 public int hashCode() {
143 return new HashCodeBuilder().append(this.id).append(this.channel).append(
144 this.sequence).toHashCode();
145 }
146
147 /***
148 * @see java.lang.Object#toString()
149 */
150 public String toString() {
151 return new ToStringBuilder(this).append("flap id", id).append("channel",
152 channel).append("sequence", sequence).append("data",
153 HexPrinter.format(data)).toString();
154 }
155
156 public byte[] toByteArray() {
157 ByteArrayOutputStream out = new ByteArrayOutputStream();
158
159 try {
160 out.write(getId());
161 out.write(getChannel());
162 out.write(new Word(getSequence()).toByteArray());
163 byte data[] = getData();
164
165 if (data != null) {
166 out.write(new Word(data.length).toByteArray());
167 out.write(data);
168 } else {
169 out.write(new Word(0).toByteArray());
170 }
171 } catch (IOException e) {
172 e.printStackTrace();
173 }
174
175 return out.toByteArray();
176 }
177 }