Search in sources :

Example 1 with GSMCharsetEncodingData

use of org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData 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;
    }
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) GSMCharsetEncoder(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncoder) SmppEncoding(org.restcomm.smpp.SmppEncoding) CharacterCodingException(java.nio.charset.CharacterCodingException) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) GSMCharsetEncodingData(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData)

Example 2 with GSMCharsetEncodingData

use of org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData 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;
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) GSMCharsetEncoder(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncoder) SmppEncoding(org.restcomm.smpp.SmppEncoding) CharacterCodingException(java.nio.charset.CharacterCodingException) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) GSMCharsetEncodingData(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 DataCodingScheme (org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme)2 GSMCharsetEncoder (org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncoder)2 GSMCharsetEncodingData (org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData)2 DataCodingSchemeImpl (org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)2 SmppEncoding (org.restcomm.smpp.SmppEncoding)2