org.marre.sms
Class SmsPduUtil

java.lang.Object
  extended byorg.marre.sms.SmsPduUtil

public final class SmsPduUtil
extends java.lang.Object

Various functions to encode and decode strings

Author:
Markus Eriksson

Field Summary
static char EXT_TABLE_PREFIX
           
static char[] GSM_DEFAULT_ALPHABET_ALTERNATIVES
          Some alternative character encodings.
static char[] GSM_DEFAULT_ALPHABET_TABLE
          Default alphabet table according to GSM 03.38.
 
Method Summary
static void arrayCopy(byte[] theSrc, int theSrcStart, byte[] theDest, int theDestStart, int theLength)
           
static void arrayCopy(byte[] theSrc, int theSrcStart, byte[] theDest, int theDestStart, int theDestBitOffset, int theBitLength)
           
static char fromGsmCharset(byte gsmChar)
          Convert from the GSM charset to a unicode char
static byte[] getSeptets(java.lang.String theMsg)
          Pack the given string into septets
static java.lang.String readBcdNumber(byte[] arr, int offset, int theLength)
          Converts bytes to BCD format
static java.lang.String readBcdNumber(java.io.InputStream theIs, int theLength)
          Converts bytes to BCD format
static java.lang.String readSeptets(byte[] theArray, int theLength)
          Decodes a 7-bit encoded string from the given byte array
static java.lang.String readSeptets(java.io.InputStream theIs, int theLength)
          Decodes a 7-bit encoded string from the stream
static byte toGsmCharset(char theUnicodeCh)
          Convert a unicode char to a GSM char
static byte[] toGsmCharset(java.lang.String str)
          Converts a unicode string to GSM charset
static void writeBcdNumber(java.io.OutputStream theOs, java.lang.String theNumber)
          Writes the given phonenumber to the stream (BCD coded)
static void writeSeptets(java.io.OutputStream theOs, java.lang.String theMsg)
          Pack the given string into septets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXT_TABLE_PREFIX

public static final char EXT_TABLE_PREFIX
See Also:
Constant Field Values

GSM_DEFAULT_ALPHABET_TABLE

public static final char[] GSM_DEFAULT_ALPHABET_TABLE
Default alphabet table according to GSM 03.38. See http://www.unicode.org/Public/MAPPINGS/ETSI/GSM0338.TXT


GSM_DEFAULT_ALPHABET_ALTERNATIVES

public static final char[] GSM_DEFAULT_ALPHABET_ALTERNATIVES
Some alternative character encodings. The table is encoded as pairs with unicode value and gsm charset value.
Ex:
 char unicode = GSM_DEFAULT_ALPHABET_ALTERNATIVES[i * 2];char gsm = GSM_DEFAULT_ALPHABET_ALTERNATIVES[i*2+1];
  
 
See http://www.unicode.org/Public/MAPPINGS/ETSI/GSM0338.TXT

Method Detail

getSeptets

public static byte[] getSeptets(java.lang.String theMsg)
Pack the given string into septets


writeSeptets

public static void writeSeptets(java.io.OutputStream theOs,
                                java.lang.String theMsg)
                         throws java.io.IOException
Pack the given string into septets.

Parameters:
theOs - Write the septets into this stream
theMsg - The message to encode
Throws:
java.io.IOException - Thrown when failing to write to theOs

readSeptets

public static java.lang.String readSeptets(byte[] theArray,
                                           int theLength)
Decodes a 7-bit encoded string from the given byte array

Parameters:
theArray - The byte array to read from
theLength - Number of decoded chars to read from the stream
Returns:
The decoded string

readSeptets

public static java.lang.String readSeptets(java.io.InputStream theIs,
                                           int theLength)
                                    throws java.io.IOException
Decodes a 7-bit encoded string from the stream

Parameters:
theIs - The stream to read from
theLength - Number of decoded chars to read from the stream
Returns:
The decoded string
Throws:
java.io.IOException - when failing to read from theIs

writeBcdNumber

public static void writeBcdNumber(java.io.OutputStream theOs,
                                  java.lang.String theNumber)
                           throws java.io.IOException
Writes the given phonenumber to the stream (BCD coded)

Parameters:
theOs - Stream to write to
theNumber - Number to convert
Throws:
java.io.IOException - when failing to write to theOs

readBcdNumber

public static java.lang.String readBcdNumber(java.io.InputStream theIs,
                                             int theLength)
                                      throws java.io.IOException
Converts bytes to BCD format

Parameters:
theIs - The byte InputStream
theLength - how many
Returns:
Decoded number
Throws:
java.io.IOException

readBcdNumber

public static java.lang.String readBcdNumber(byte[] arr,
                                             int offset,
                                             int theLength)
Converts bytes to BCD format

Parameters:
arr - bytearray
theLength - how many
offset -
Returns:
Decoded number

fromGsmCharset

public static char fromGsmCharset(byte gsmChar)
Convert from the GSM charset to a unicode char

Parameters:
gsmChar - The gsm char to convert
Returns:
Unicode representation of the given gsm char

toGsmCharset

public static byte[] toGsmCharset(java.lang.String str)
Converts a unicode string to GSM charset

Parameters:
str - String to convert
Returns:
The string GSM encoded

toGsmCharset

public static byte toGsmCharset(char theUnicodeCh)
Convert a unicode char to a GSM char

Parameters:
theUnicodeCh - The unicode char to convert
Returns:
GSM representation of the given unicode char

arrayCopy

public static void arrayCopy(byte[] theSrc,
                             int theSrcStart,
                             byte[] theDest,
                             int theDestStart,
                             int theLength)

arrayCopy

public static void arrayCopy(byte[] theSrc,
                             int theSrcStart,
                             byte[] theDest,
                             int theDestStart,
                             int theDestBitOffset,
                             int theBitLength)
Parameters:
theSrc -
theSrcStart -
theDest -
theDestStart -
theDestBitOffset -
theBitLength - In bits


Copyright © 2002-2005 Markus Eriksson. All Rights Reserved.