1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.marre.sms;
36
37 import java.io.*;
38
39 /***
40 * Represents an User Data Header Element
41 *
42 * @author Markus Eriksson
43 * @version $Id: SmsUdhElement.java,v 1.5 2004/11/02 17:59:49 c95men Exp $
44 */
45 public class SmsUdhElement
46 {
47 protected int myUdhIei;
48 protected byte[] myUdhIeiData;
49
50 /***
51 * Creates an SmsUdhElement
52 *
53 * @param theUdhIei
54 * @param theUdhIeiData
55 */
56 public SmsUdhElement(int theUdhIei, byte[] theUdhIeiData)
57 {
58 myUdhIei = theUdhIei;
59 myUdhIeiData = theUdhIeiData;
60 }
61
62 /***
63 * Returns the total length of this UDH element.
64 * <p>
65 * The length is including the UDH data length and the UDH "header" (2 bytes)
66 * @return the length
67 */
68 public int getTotalSize()
69 {
70 return myUdhIeiData.length + 2;
71 }
72
73 /***
74 * Returns the length of the UDH iei data
75 * <p>
76 * The length returned is only the length of the data
77 * @return Length of data
78 */
79 public int getUdhIeiDataLength()
80 {
81 return myUdhIeiData.length;
82 }
83
84 /***
85 * Returns the Udh Iei Data excluding the UDH "header"
86 * @return Data
87 */
88 public byte[] getUdhIeiData()
89 {
90 return myUdhIeiData;
91 }
92
93 /***
94 * Return the UDH element including the UDH "header" (two bytes)
95 *
96 * @return Data
97 */
98 public byte[] getData()
99 {
100 byte[] allData = new byte[myUdhIeiData.length + 2];
101
102 allData[0] = (byte) (myUdhIei & 0xff);
103 allData[1] = (byte) (myUdhIeiData.length & 0xff);
104 System.arraycopy(myUdhIeiData, 0, allData, 2, myUdhIeiData.length);
105
106 return allData;
107 }
108
109 /***
110 * Writes the UDH element including UDH "header" to the given stream
111 *
112 * @param os Stream to write to
113 * @throws IOException
114 */
115 public void writeTo(OutputStream os)
116 throws IOException
117 {
118 os.write(myUdhIei);
119 os.write(myUdhIeiData.length);
120 os.write(myUdhIeiData);
121 }
122 }