ie.omk.smpp.util
Class DefaultAlphabetEncoding

java.lang.Object
  extended by ie.omk.smpp.util.MessageEncoding
      extended by ie.omk.smpp.util.AlphabetEncoding
          extended by ie.omk.smpp.util.DefaultAlphabetEncoding

public class DefaultAlphabetEncoding
extends AlphabetEncoding

This class encodes and decodes Java Strings to and from the SMS default alphabet. It also supports the default extension table. The default alphabet and it's extension table is defined in GSM 03.38.


Field Summary
static int EXTENDED_ESCAPE
           
static int PAGE_BREAK
          Page break (extended table).
 
Constructor Summary
DefaultAlphabetEncoding()
           
 
Method Summary
 String decodeString(byte[] b)
          Decode an SMS default alphabet-encoded octet string into a Java String.
 byte[] encodeString(String s)
          Encode a Java String into a byte array using the SMS Default alphabet.
 int getEncodingLength()
          Get the number of bits each encoded message byte represents.
static DefaultAlphabetEncoding getInstance()
          Deprecated.  
 byte[] pack(byte[] unpacked)
          Pack a byte array according to the GSM bit-packing algorithm.
 String toString()
           
 byte[] unpack(byte[] packed)
          Unpack a byte array according to the GSM bit-packing algorithm.
 
Methods inherited from class ie.omk.smpp.util.AlphabetEncoding
getCharset, setCharset
 
Methods inherited from class ie.omk.smpp.util.MessageEncoding
getDataCoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EXTENDED_ESCAPE

public static final int EXTENDED_ESCAPE
See Also:
Constant Field Values

PAGE_BREAK

public static final int PAGE_BREAK
Page break (extended table).

See Also:
Constant Field Values
Constructor Detail

DefaultAlphabetEncoding

public DefaultAlphabetEncoding()
Method Detail

getInstance

public static DefaultAlphabetEncoding getInstance()
Deprecated. 

Get the singleton instance of DefaultAlphabetEncoding.


decodeString

public String decodeString(byte[] b)
Decode an SMS default alphabet-encoded octet string into a Java String.

Overrides:
decodeString in class AlphabetEncoding

encodeString

public byte[] encodeString(String s)
Encode a Java String into a byte array using the SMS Default alphabet.

Overrides:
encodeString in class AlphabetEncoding

getEncodingLength

public int getEncodingLength()
Description copied from class: MessageEncoding
Get the number of bits each encoded message byte represents. This method will almost always return 8. The only known situation at this time where the value should be different is in DefaultAlphabetEncoding. The reason is that, although the DefaultAlphabetEncoding will generate encoded message byte arrays with one character in each byte location, in reality each byte actually represents only 7-bits. When the message is re-encoded at the SMSC, it will be compressed. This is how the GSM default alphabet can fit 160 characters into a 140-byte payload. Most SMSCs, however, accept the message in its uncompressed form.

It is not correct to return a value of 16 from an AlphabetEncoding which encodes characters in 2 or more bytes. The reason that, although a character is encoding as 2 bytes, in the encoded form each byte location still represents 8 bits . This is an important distinction.

Overrides:
getEncodingLength in class MessageEncoding

pack

public byte[] pack(byte[] unpacked)
Pack a byte array according to the GSM bit-packing algorithm. The GSM specification defines a simple compression mechanism for its default alphabet to pack more message characters into a smaller space. Since the alphabet only contains 128 symbols, each one can be represented in 7 bits. The packing algorithm squeezes the bits for each symbol "down" into the preceeding byte (so bit 7 of the first byte actually contains bit 0 of the second symbol in a default alphabet string, bits 6 and 7 in the second byte contain bits 0 and 1 of the third symbol etc.) Since the maximum short message length is 140 bytes, you save one bit per byte using the default alphabet giving you a total of 140 + (140 / 8) = 160 characters to use. This is where the 160 character limit comes from in SMPP packets.

Having said all that, most SMSCs do NOT use the packing algorithm when communicating over TCP/IP. They either use a full 8-bit alphabet such as ASCII or Latin-1, or they accept the default alphabet in its unpacked form. As such, you will be unlikely to need this method.

Parameters:
unpacked - The unpacked byte array.
Returns:
A new byte array containing the bytes in their packed form.

unpack

public byte[] unpack(byte[] packed)
Unpack a byte array according to the GSM bit-packing algorithm. Read the full description in the documentation of the pack method.

Parameters:
packed - The packed byte array.
Returns:
A new byte array containing the unpacked bytes.
See Also:
pack(byte[])

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011 smppapi at Sourceforge. All Rights Reserved.