public class GsmAlphabet extends Object
Modifier and Type | Class and Description |
---|---|
static class |
GsmAlphabet.TextEncodingDetails
For a specific text string, this object describes protocol
properties of encoding it for transmission as message user
data.
|
Modifier and Type | Field and Description |
---|---|
static byte |
GSM_EXTENDED_ESCAPE
This escapes extended characters, and when present indicates that the
following character should be looked up in the "extended" table.
|
static int |
UDH_SEPTET_COST_CONCATENATED_MESSAGE
Multi-part messages require a user data header of 5 octets, or 6 septets,
plus UDH length.
|
static int |
UDH_SEPTET_COST_LENGTH
User data header requires one octet for length.
|
static int |
UDH_SEPTET_COST_ONE_SHIFT_TABLE
Using a non-default language locking shift table OR single shift table
requires a user data header of 3 octets, or 4 septets, plus UDH length.
|
static int |
UDH_SEPTET_COST_TWO_SHIFT_TABLES
Using a non-default language locking shift table AND single shift table
requires a user data header of 6 octets, or 7 septets, plus UDH length.
|
Modifier and Type | Method and Description |
---|---|
static int |
charToGsm(char c)
Converts a char to a GSM 7 bit table index.
|
static int |
charToGsm(char c,
boolean throwException)
Converts a char to a GSM 7 bit table index.
|
static int |
charToGsmExtended(char c)
Converts a char to an extended GSM 7 bit table index.
|
static int |
countGsmSeptets(char c)
Returns the count of 7-bit GSM alphabet characters
needed to represent this character.
|
static int |
countGsmSeptets(char c,
boolean throwsException)
Returns the count of 7-bit GSM alphabet characters
needed to represent this character using the default 7 bit GSM alphabet.
|
static GsmAlphabet.TextEncodingDetails |
countGsmSeptets(CharSequence s,
boolean use7bitOnly)
Returns the count of 7-bit GSM alphabet characters
needed to represent this string, and the language table and
language shift table used to achieve this result.
|
static int |
countGsmSeptetsUsingTables(CharSequence s,
boolean use7bitOnly,
int languageTable,
int languageShiftTable)
Returns the count of 7-bit GSM alphabet characters needed
to represent this string, using the specified 7-bit language table
and extension table (0 for GSM default tables).
|
static int |
findGsmSeptetLimitIndex(String s,
int start,
int limit,
int langTable,
int langShiftTable)
Returns the index into
s of the first character
after limit septets have been reached, starting at
index start . |
static int[] |
getEnabledLockingShiftTables()
Return the array of enabled national language locking shift tables for SMS
encoding.
|
static int[] |
getEnabledSingleShiftTables()
Return the array of enabled national language single shift tables for SMS
encoding.
|
static String |
gsm7BitPackedToString(byte[] pdu,
int offset,
int lengthSeptets)
Convert a GSM alphabet 7 bit packed string (SMS string) into a
String . |
static String |
gsm7BitPackedToString(byte[] pdu,
int offset,
int lengthSeptets,
int numPaddingBits,
int languageTable,
int shiftTable)
Convert a GSM alphabet 7 bit packed string (SMS string) into a
String . |
static String |
gsm8BitUnpackedToString(byte[] data,
int offset,
int length)
Convert a GSM alphabet string that's stored in 8-bit unpacked
format (as it often appears in SIM records) into a String
Field may be padded with trailing 0xff's.
|
static String |
gsm8BitUnpackedToString(byte[] data,
int offset,
int length,
String characterset)
Convert a GSM alphabet string that's stored in 8-bit unpacked
format (as it often appears in SIM records) into a String
Field may be padded with trailing 0xff's.
|
static char |
gsmExtendedToChar(int gsmChar)
Converts a character in the extended GSM alphabet into a char
if GSM_EXTENDED_ESCAPE is passed, ' ' is returned since no second
extension page has yet been defined (see Note 1 in table 6.2.1.1 of
TS 23.038 v7.00)
If an unmappable value is passed, the character from the GSM 7 bit
default table will be used (table 6.2.1.1 of TS 23.038).
|
static char |
gsmToChar(int gsmChar)
Converts a character in the GSM alphabet into a char.
|
static boolean |
isGsmSeptets(char c) |
static void |
setEnabledLockingShiftTables(int[] tables)
Modify the array of enabled national language locking shift tables for SMS
encoding.
|
static void |
setEnabledSingleShiftTables(int[] tables)
Modify the array of enabled national language single shift tables for SMS
encoding.
|
static byte[] |
stringToGsm7BitPacked(String data)
Converts a String into a byte array containing
the 7-bit packed GSM Alphabet representation of the string.
|
static byte[] |
stringToGsm7BitPacked(String data,
int startingSeptetOffset,
boolean throwException,
int languageTable,
int languageShiftTable)
Converts a String into a byte array containing
the 7-bit packed GSM Alphabet representation of the string.
|
static byte[] |
stringToGsm7BitPacked(String data,
int languageTable,
int languageShiftTable)
Converts a String into a byte array containing
the 7-bit packed GSM Alphabet representation of the string.
|
static byte[] |
stringToGsm7BitPackedWithHeader(String data,
byte[] header)
Converts a String into a byte array containing the 7-bit packed
GSM Alphabet representation of the string.
|
static byte[] |
stringToGsm7BitPackedWithHeader(String data,
byte[] header,
int languageTable,
int languageShiftTable)
Converts a String into a byte array containing the 7-bit packed
GSM Alphabet representation of the string.
|
static byte[] |
stringToGsm8BitPacked(String s)
Convert a string into an 8-bit unpacked GSM alphabet byte array.
|
static void |
stringToGsm8BitUnpackedField(String s,
byte[] dest,
int offset,
int length)
Write a String into a GSM 8-bit unpacked field of
Field is padded with 0xff's, string is truncated if necessary
|
public static final byte GSM_EXTENDED_ESCAPE
public static final int UDH_SEPTET_COST_LENGTH
public static final int UDH_SEPTET_COST_ONE_SHIFT_TABLE
public static final int UDH_SEPTET_COST_TWO_SHIFT_TABLES
public static final int UDH_SEPTET_COST_CONCATENATED_MESSAGE
public static int charToGsm(char c)
c
- the character to convertpublic static int charToGsm(char c, boolean throwException) throws EncodeException
c
- the character to convertthrowException
- If true, throws EncodeException on invalid char.
If false, returns GSM alphabet ' ' char.EncodeException
- encode error when throwException is truepublic static int charToGsmExtended(char c)
c
- the character to convertpublic static char gsmToChar(int gsmChar)
gsmChar
- the GSM 7 bit table index to convertpublic static char gsmExtendedToChar(int gsmChar)
gsmChar
- the GSM 7 bit extended table index to convertpublic static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header) throws EncodeException
data
- The text string to encode.header
- Optional header (including length byte) that precedes
the encoded data, padded to septet boundary.EncodeException
- if String is too large to encodestringToGsm7BitPackedWithHeader(String, byte[], int, int)
public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header, int languageTable, int languageShiftTable) throws EncodeException
data
- The text string to encode.header
- Optional header (including length byte) that precedes
the encoded data, padded to septet boundary.languageTable
- the 7 bit language table, or 0 for the default GSM alphabetlanguageShiftTable
- the 7 bit single shift language table, or 0 for the default
GSM extension tableEncodeException
- if String is too large to encodepublic static byte[] stringToGsm7BitPacked(String data) throws EncodeException
data
- the data string to encodeEncodeException
- if String is too large to encodepublic static byte[] stringToGsm7BitPacked(String data, int languageTable, int languageShiftTable) throws EncodeException
data
- the data string to encodelanguageTable
- the 7 bit language table, or 0 for the default GSM alphabetlanguageShiftTable
- the 7 bit single shift language table, or 0 for the default
GSM extension tableEncodeException
- if String is too large to encodepublic static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset, boolean throwException, int languageTable, int languageShiftTable) throws EncodeException
data
- the text to convert to septetsstartingSeptetOffset
- the number of padding septets to put before
the character data at the beginning of the arraythrowException
- If true, throws EncodeException on invalid char.
If false, replaces unencodable char with GSM alphabet space char.languageTable
- the 7 bit language table, or 0 for the default GSM alphabetlanguageShiftTable
- the 7 bit single shift language table, or 0 for the default
GSM extension tableEncodeException
- if String is too large to encodepublic static String gsm7BitPackedToString(byte[] pdu, int offset, int lengthSeptets)
String
.
See TS 23.038 6.1.2.1 for SMS Character Packingpdu
- the raw data from the pduoffset
- the byte offset oflengthSeptets
- string length in septets, not bytespublic static String gsm7BitPackedToString(byte[] pdu, int offset, int lengthSeptets, int numPaddingBits, int languageTable, int shiftTable)
String
.
See TS 23.038 6.1.2.1 for SMS Character Packingpdu
- the raw data from the pduoffset
- the byte offset oflengthSeptets
- string length in septets, not bytesnumPaddingBits
- the number of padding bits before the start of the
string in the first bytelanguageTable
- the 7 bit language table, or 0 for the default GSM alphabetshiftTable
- the 7 bit single shift language table, or 0 for the default
GSM extension tablepublic static String gsm8BitUnpackedToString(byte[] data, int offset, int length)
data
- the byte array to decodeoffset
- array offset for the first character to decodelength
- the number of bytes to decodepublic static String gsm8BitUnpackedToString(byte[] data, int offset, int length, String characterset)
public static byte[] stringToGsm8BitPacked(String s)
s
- the string to encodepublic static void stringToGsm8BitUnpackedField(String s, byte[] dest, int offset, int length)
s
- the string to encodedest
- the destination byte arrayoffset
- the starting offset for the encoded stringlength
- the maximum number of bytes to writepublic static int countGsmSeptets(char c)
c
- the character to examinepublic static int countGsmSeptets(char c, boolean throwsException) throws EncodeException
c
- the character to examinethrowsException
- If true, throws EncodeException if unencodable
char. Otherwise, counts invalid char as 1 septet.EncodeException
- the character can't be encoded and throwsException is truepublic static boolean isGsmSeptets(char c)
public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly, int languageTable, int languageShiftTable)
s
- the Unicode string that will be encodeduse7bitOnly
- allow using space in place of unencodable character if true,
otherwise, return -1 if any characters are unencodablelanguageTable
- the 7 bit language table, or 0 for the default GSM alphabetlanguageShiftTable
- the 7 bit single shift language table, or 0 for the default
GSM extension tablepublic static GsmAlphabet.TextEncodingDetails countGsmSeptets(CharSequence s, boolean use7bitOnly)
s
- the Unicode string that will be encodeduse7bitOnly
- allow using space in place of unencodable character if true,
using the language table pair with the fewest unencodable characterspublic static int findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable)
s
of the first character
after limit
septets have been reached, starting at
index start
. This is used when dividing messages
into units within the SMS message size limit.s
- source stringstart
- index of where to start counting septetslimit
- maximum septets to include,
e.g. MAX_USER_DATA_SEPTETS
langTable
- the 7 bit character table to use (0 for default GSM 7-bit alphabet)langShiftTable
- the 7 bit shift table to use (0 for default GSM extension table)public static void setEnabledSingleShiftTables(int[] tables)
tables
- the new list of enabled single shift tablespublic static void setEnabledLockingShiftTables(int[] tables)
tables
- the new list of enabled locking shift tablespublic static int[] getEnabledSingleShiftTables()
public static int[] getEnabledLockingShiftTables()