Tests encoding of UTF-16 data with ruby-smpp
Usage example:
$ javac -cp .:smpp.jar SmppDecodeTest.java
$ ruby ./smpp-test.rb | java -Dfile.encoding=utf-8 -cp .:smpp.jar:log4j-1.2.8.jar SmppDecodeTest
Привет
$
#!/usr/bin/ruby | |
# encoding: utf-8 | |
require 'smpp' | |
message = "Привет".encode("UTF-16BE").force_encoding("BINARY") | |
submit_sm = Smpp::Pdu::SubmitSm.new("from", "to", message, data_coding: 8) | |
STDOUT << submit_sm.data |
import com.logica.smpp.pdu.PDU; | |
import com.logica.smpp.pdu.SubmitSM; | |
import com.logica.smpp.util.ByteBuffer; | |
public class SmppDecodeTest { | |
public static void main(String[] args) throws Exception { | |
PDU pdu = new SmppDecodeTest().decode(System.in); | |
SubmitSM sm = (SubmitSM) pdu; | |
System.out.println(sm.getShortMessage("UTF-16BE")); | |
} | |
public PDU decode(java.io.InputStream in) throws Exception { | |
ByteBuffer data = new ByteBuffer(); | |
byte[] buf = new byte[1024]; | |
int read = 0; | |
while ((read = in.read(buf)) != -1) { | |
data.appendBytes(buf, read); | |
} | |
buf = data.getBuffer(); | |
for (int i = 0; i < buf.length; i++) { System.err.print(Long.toHexString(buf[i]) + " "); } | |
System.err.println(); | |
return PDU.createPDU(data); | |
} | |
} |