Search in sources :

Example 1 with GSMCharsetEncodingData

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

Example 2 with GSMCharsetEncodingData

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

Aggregations

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