use of org.restcomm.smpp.SmppEncoding in project smscgateway by RestComm.
the class RxSmppServerSbb method recodeShortMessage.
protected byte[] recodeShortMessage(int dataCoding, String msg, byte[] udhPart) {
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dataCoding);
byte[] textPart;
if (msg != null) {
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM8) {
textPart = msg.getBytes(isoCharset);
} else {
SmppEncoding enc;
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
enc = smscPropertiesManagement.getSmppEncodingForGsm7();
} else {
enc = smscPropertiesManagement.getSmppEncodingForUCS2();
}
if (enc == SmppEncoding.Utf8) {
textPart = msg.getBytes(utf8Charset);
} else if (enc == SmppEncoding.Unicode) {
textPart = msg.getBytes(ucs2Charset);
} else {
GSMCharsetEncoder encoder = (GSMCharsetEncoder) gsm7Charset.newEncoder();
encoder.setGSMCharsetEncodingData(new GSMCharsetEncodingData(Gsm7EncodingStyle.bit8_smpp_style, null));
ByteBuffer bb = null;
try {
bb = encoder.encode(CharBuffer.wrap(msg));
} catch (CharacterCodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
textPart = new byte[bb.limit()];
bb.get(textPart);
}
}
} else {
textPart = new byte[0];
}
if (udhPart == null) {
return textPart;
} else {
byte[] res = new byte[textPart.length + udhPart.length];
System.arraycopy(udhPart, 0, res, 0, udhPart.length);
System.arraycopy(textPart, 0, res, udhPart.length, textPart.length);
return res;
}
}
use of org.restcomm.smpp.SmppEncoding in project smscgateway by RestComm.
the class TxSmppServerSbb method parseShortMessageText.
private String parseShortMessageText(BaseSm event) {
byte[] data = event.getShortMessage();
if (event.getShortMessageLength() == 0) {
// Probably the message_payload Optional Parameter is being used
Tlv messagePaylod = event.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
if (messagePaylod != null) {
data = messagePaylod.getValue();
}
}
if (data == null) {
data = new byte[0];
}
boolean udhPresent = (event.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
byte[] udhData;
byte[] textPart;
String msg;
udhData = null;
textPart = data;
if (udhPresent && data.length > 2) {
// UDH exists
int udhLen = (textPart[0] & 0xFF) + 1;
if (udhLen <= textPart.length) {
textPart = new byte[textPart.length - udhLen];
udhData = new byte[udhLen];
System.arraycopy(data, udhLen, textPart, 0, textPart.length);
System.arraycopy(data, 0, udhData, 0, udhLen);
}
}
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(event.getDataCoding());
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM8) {
msg = new String(textPart, isoCharset);
} else {
SmppEncoding enc;
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
enc = smscPropertiesManagement.getSmppEncodingForGsm7();
} else {
enc = smscPropertiesManagement.getSmppEncodingForUCS2();
}
switch(enc) {
case Utf8:
default:
msg = new String(textPart, utf8Charset);
break;
case Unicode:
msg = new String(textPart, ucs2Charset);
break;
case Gsm7:
GSMCharsetDecoder decoder = (GSMCharsetDecoder) gsm7Charset.newDecoder();
decoder.setGSMCharsetDecodingData(new GSMCharsetDecodingData(Gsm7EncodingStyle.bit8_smpp_style, Integer.MAX_VALUE, 0));
ByteBuffer bb = ByteBuffer.wrap(textPart);
CharBuffer bf = null;
try {
bf = decoder.decode(bb);
} catch (CharacterCodingException e) {
// this can not be
}
msg = bf.toString();
break;
}
}
return msg;
}
use of org.restcomm.smpp.SmppEncoding in project smscgateway by RestComm.
the class RxSipServerSbb method recodeShortMessage.
private byte[] recodeShortMessage(int dataCoding, String msg, byte[] udhPart) {
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dataCoding);
byte[] textPart;
if (msg != null) {
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM8) {
textPart = msg.getBytes(isoCharset);
} else {
SmppEncoding enc;
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
enc = smscPropertiesManagement.getSmppEncodingForGsm7();
} else {
enc = smscPropertiesManagement.getSmppEncodingForUCS2();
}
if (enc == SmppEncoding.Utf8) {
textPart = msg.getBytes(utf8Charset);
} else if (enc == SmppEncoding.Unicode) {
textPart = msg.getBytes(ucs2Charset);
} else {
GSMCharsetEncoder encoder = (GSMCharsetEncoder) gsm7Charset.newEncoder();
encoder.setGSMCharsetEncodingData(new GSMCharsetEncodingData(Gsm7EncodingStyle.bit8_smpp_style, null));
ByteBuffer bb = null;
try {
bb = encoder.encode(CharBuffer.wrap(msg));
} catch (CharacterCodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
textPart = new byte[bb.limit()];
bb.get(textPart);
}
}
} else {
textPart = new byte[0];
}
return textPart;
}
Aggregations