1 | package fr.sii.ogham.sms; | |
2 | ||
3 | public final class SmsConstants { | |
4 | /** | |
5 | * Default constant values for splitting messages. | |
6 | * | |
7 | * | |
8 | * @author Aurélien Baudet | |
9 | * | |
10 | */ | |
11 | public static final class SmppSplitConstants { | |
12 | /** | |
13 | * A single SMS GSM message has a maximum size of 140 octets. | |
14 | */ | |
15 | public static final int MAXIMUM_BYTES_PER_MESSAGE = 140; | |
16 | ||
17 | /** | |
18 | * Smpp message size is 140 octets. UCS-2 encoding uses 2 octets per | |
19 | * character. Therefore the original Java {@link String} can completely | |
20 | * fit in one segment if its length is lower or equal to 70 characters | |
21 | * (140 octets / 2). If the original Java {@link String} can't fit, then | |
22 | * each part must have a maximum length of 67 characters ((140 octetes - | |
23 | * 6 octets for header) / 2). | |
24 | * | |
25 | * <hr> | |
26 | * <strong>Explanation:</strong> | |
27 | * <p> | |
28 | * UCS-2 Encoding This encoding allows use of a greater range of | |
29 | * characters and languages. UCS-2 can represent the most commonly used | |
30 | * Latin and eastern characters at the cost of a greater space expense. | |
31 | * Strictly speaking, UCS-2 is limited to characters in the Basic | |
32 | * Multilingual Plane. However, since modern programming environments do | |
33 | * not provide encoders or decoders for UCS-2, some cell phones (e.g. | |
34 | * iPhones) use UTF-16 instead of UCS-2.[4] This works, because for | |
35 | * characters in the Basic Multilingual Plane (including full alphabets | |
36 | * of most modern human languages) UCS-2 and UTF-16 encodings are | |
37 | * identical. To encode characters outside of the BMP (unreachable in | |
38 | * plain UCS-2), such as Emoji, UTF-16 uses surrogate pairs, which when | |
39 | * decoded with UCS-2 would appear as two valid but unmapped code | |
40 | * points. | |
41 | * | |
42 | * <p> | |
43 | * A single SMS GSM message using this encoding can have at most 70 | |
44 | * characters (140 octets). | |
45 | * | |
46 | * <p> | |
47 | * Note that on many GSM cell phones, there's no specific preselection | |
48 | * of the UCS-2 encoding. The default is to use the 7-bit encoding | |
49 | * described above, until one enters a character that is not present in | |
50 | * the GSM 7-bit table (for example the lowercase 'a' with acute: 'á'). | |
51 | * In that case, the whole message gets reencoded using the UCS-2 | |
52 | * encoding, and the maximum length of the message sent in a single SMS | |
53 | * is immediately reduced to 70 characters, instead of 160. Others vary | |
54 | * based on the choice and configuration of SMS application, and the | |
55 | * length of the message. | |
56 | * | |
57 | */ | |
58 | public static final SegmentSizes SEGMENT_SIZE_UCS2 = new SegmentSizes(70, 67); | |
59 | ||
60 | /** | |
61 | * Smpp message size is 140 octets. GSM 8-bit encoding uses one octet | |
62 | * per character. Therefore the original Java {@link String} can | |
63 | * completely fit in one segment if its length is lower or equal to 140 | |
64 | * characters (140 octets = 140 characters). If the original Java | |
65 | * {@link String} can't fit, then each part must have a maximum length | |
66 | * of 134 characters (140 octets - 6 octets for header = 134 octets for | |
67 | * message {@literal ->} 134 characters). | |
68 | */ | |
69 | public static final SegmentSizes SEGMENT_SIZE_GSM_8BIT = new SegmentSizes(140, 134); | |
70 | ||
71 | /** | |
72 | * Smpp message size is 140 octets. GSM 7-bit encoding uses 7 bits per | |
73 | * character. Therefore the original Java {@link String} can completely | |
74 | * fit in one segment if its length is lower or equal to 160 characters | |
75 | * (140 octets * 8 bits / 7 bits). If the original Java {@link String} | |
76 | * can't fit, then each part must have a maximum length of 153 | |
77 | * characters ((140 octets - 6 octets for header) * 8 / 7). | |
78 | * | |
79 | * <hr> | |
80 | * <strong>Explanation:</strong> | |
81 | * <p> | |
82 | * The standard encoding for GSM messages is the 7-bit default alphabet | |
83 | * as defined in the 23.038 recommendation. | |
84 | * | |
85 | * <p> | |
86 | * Seven-bit characters must be encoded into octets following one of | |
87 | * three packing modes: | |
88 | * | |
89 | * <ul> | |
90 | * <li>CBS: using this encoding, it is possible to send up to 93 | |
91 | * characters (packed in up to 82 octets) in one SMS message in a Cell | |
92 | * Broadcast Service.</li> | |
93 | * <li><strong>SMS</strong>: using this encoding, it is possible to send | |
94 | * up to 160 characters (packed in up to 140 octets) in one SMS message | |
95 | * in the GSM network.</li> | |
96 | * <li>USSD: using this encoding, it is possible to send up to 182 | |
97 | * characters (packed in up to 160 octets) in one SMS message of | |
98 | * Unstructured Supplementary Service Data.</li> | |
99 | * </ul> | |
100 | * | |
101 | * <p> | |
102 | * In a standard GSM text message, all characters are encoded using | |
103 | * 7-bit code units, packed together to fill all bits of octets. So, for | |
104 | * example, the 140-octet envelope of an SMS, with no other language | |
105 | * indicator but only the standard class prefix, can transport up to | |
106 | * (140*8)/7=160, that is 160 GSM 7-bit characters (but note that the | |
107 | * ESC code counts for one of them, if characters in the high part of | |
108 | * the table are used). | |
109 | * | |
110 | * <p> | |
111 | * Longer messages may be sent, but will require a continuation prefix | |
112 | * and a sequence number on subsequent SMS messages (these prefix octets | |
113 | * and sequence number are counted within the maximum length of the | |
114 | * 140-octet payload of the envelope format). | |
115 | * | |
116 | * <p> | |
117 | * When there are 1 to 6 spare bits in the last octet of a message, | |
118 | * these bits are set to zero (these bits do not count as a character | |
119 | * but only as a filler). When there are 7 spare bits in the last octet | |
120 | * of a message, these bits are set to the 7-bit code of the CR control | |
121 | * (also used as a padding filler) instead of being set to zero (where | |
122 | * they would be confused with the 7-bit code of an '@' character). | |
123 | */ | |
124 | public static final SegmentSizes SEGMENT_SIZE_GSM_7BIT_SMS_PACKING_MODE = new SegmentSizes(160, 153); | |
125 | ||
126 | /** | |
127 | * Represents maximum sizes for segments: | |
128 | * <ul> | |
129 | * <li>maximumStringLengthToFitInASingleSegment: This is the maximum | |
130 | * length of the original string (Java {@link String}) that can | |
131 | * completely fit in only one segment.</li> | |
132 | * <li>maximumStringLengthPerSegment: If the original string (Java | |
133 | * {@link String}) can't completely fit in only one segment, then the | |
134 | * string is split in several segments with this value as maximum size. | |
135 | * Each resulting segment may contain a header or some control | |
136 | * characters. This size only represents the maximum length of the | |
137 | * payload.</li> | |
138 | * </ul> | |
139 | * | |
140 | * @author Aurélien Baudet | |
141 | * | |
142 | */ | |
143 | public static class SegmentSizes { | |
144 | /** | |
145 | * This is the maximum length of the original string (Java | |
146 | * {@link String}) that can completely fit in only one segment. | |
147 | */ | |
148 | private final int maximumStringLengthToFitInASingleSegment; | |
149 | /** | |
150 | * If the original string (Java {@link String}) can't completely fit | |
151 | * in only one segment, then the string is split in several segments | |
152 | * with this value as maximum size. Each resulting segment may | |
153 | * contain a header or some control characters. This size only | |
154 | * represents the maximum length of the payload. | |
155 | */ | |
156 | private final int maximumStringLengthPerSegment; | |
157 | ||
158 | /** | |
159 | * Initializes with maximum segment sizes | |
160 | * | |
161 | * @param maximumStringLengthToFitInASingleSegment | |
162 | * This is the maximum length of the original string | |
163 | * (Java {@link String}) that can completely fit in only | |
164 | * one segment. | |
165 | * @param maximumStringLengthPerSegment | |
166 | * If the original string (Java {@link String}) can't | |
167 | * completely fit in only one segment, then the string is | |
168 | * split in several segments with this value as maximum | |
169 | * size. Each resulting segment may contain a header or | |
170 | * some control characters. This size only represents the | |
171 | * maximum length of the payload. | |
172 | */ | |
173 | public SegmentSizes(int maximumStringLengthToFitInASingleSegment, int maximumStringLengthPerSegment) { | |
174 | super(); | |
175 | this.maximumStringLengthToFitInASingleSegment = maximumStringLengthToFitInASingleSegment; | |
176 | this.maximumStringLengthPerSegment = maximumStringLengthPerSegment; | |
177 | } | |
178 | ||
179 | /** | |
180 | * Get the maximum string length that can fit in only one segment. | |
181 | * | |
182 | * @return the maximum length of the Java {@link String} that can | |
183 | * fit in only one segment | |
184 | */ | |
185 | public int getMaximumStringLengthToFitInASingleSegment() { | |
186 |
5
1. getMaximumStringLengthToFitInASingleSegment : replaced int return with 0 for fr/sii/ogham/sms/SmsConstants$SmppSplitConstants$SegmentSizes::getMaximumStringLengthToFitInASingleSegment → NO_COVERAGE 2. getMaximumStringLengthToFitInASingleSegment : replaced int return with 0 for fr/sii/ogham/sms/SmsConstants$SmppSplitConstants$SegmentSizes::getMaximumStringLengthToFitInASingleSegment → TIMED_OUT 3. getMaximumStringLengthToFitInASingleSegment : replaced int return with 0 for fr/sii/ogham/sms/SmsConstants$SmppSplitConstants$SegmentSizes::getMaximumStringLengthToFitInASingleSegment → KILLED 4. getMaximumStringLengthToFitInASingleSegment : replaced int return with 0 for fr/sii/ogham/sms/SmsConstants$SmppSplitConstants$SegmentSizes::getMaximumStringLengthToFitInASingleSegment → KILLED 5. getMaximumStringLengthToFitInASingleSegment : replaced int return with 0 for fr/sii/ogham/sms/SmsConstants$SmppSplitConstants$SegmentSizes::getMaximumStringLengthToFitInASingleSegment → KILLED |
return maximumStringLengthToFitInASingleSegment; |
187 | } | |
188 | ||
189 | /** | |
190 | * Get the maximum string length for each segment. | |
191 | * | |
192 | * If the original string (Java {@link String}) can't completely fit | |
193 | * in only one segment, then the string is split in several segments | |
194 | * with this value as maximum size. Each resulting segment may | |
195 | * contain a header or some control characters. This size only | |
196 | * represents the maximum length of the payload. | |
197 | * | |
198 | * @return the maximum string length of Java {@link String} for each | |
199 | * segment | |
200 | */ | |
201 | public int getMaximumStringLengthPerSegment() { | |
202 |
1
1. getMaximumStringLengthPerSegment : replaced int return with 0 for fr/sii/ogham/sms/SmsConstants$SmppSplitConstants$SegmentSizes::getMaximumStringLengthPerSegment → NO_COVERAGE |
return maximumStringLengthPerSegment; |
203 | } | |
204 | } | |
205 | ||
206 | private SmppSplitConstants() { | |
207 | super(); | |
208 | } | |
209 | } | |
210 | ||
211 | private SmsConstants() { | |
212 | super(); | |
213 | } | |
214 | } | |
Mutations | ||
186 |
1.1 2.2 3.3 4.4 5.5 |
|
202 |
1.1 |