/*
 * Java SMPP API Copyright (C) 1998 - 2002 by Oran Kelly
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * A copy of the LGPL can be viewed at http://www.gnu.org/copyleft/lesser.html
 * Java SMPP API author: orank@users.sf.net Java SMPP API Homepage:
 * http://smppapi.sourceforge.net/ $Id: UCS2Encoding.java,v 1.6 2004/12/03
 * 17:49:47 orank Exp $
 */

package ie.omk.smpp.util;

public class UCS2Encoding extends ie.omk.smpp.util.AlphabetEncoding {
    private String encType = "UTF-16BE";

    private static final int DCS = 8;

    private static final UCS2Encoding beInstance = new UCS2Encoding(true);

    private static final UCS2Encoding leInstance = new UCS2Encoding(false);

    /**
     * Construct a new UCS2 encoding.
     * 
     * @param bigEndian
     *            true to use UTF-16BE, false to use UTF-16LE.
     */
    private UCS2Encoding(boolean bigEndian) {
        super(DCS);

        if (!bigEndian)
            encType = "UTF-16LE";
    }

    /**
     * Get the singleton instance of the big-endian UCS2Encoding.
     */
    public static UCS2Encoding getInstance() {
        return (beInstance);
    }

    /**
     * Get the singleton instance of either the big-endian or little-endian
     * instance of UCS2Encoding.
     * 
     * @param bigEndian
     *            true to get the big-endian instance, false to get the
     *            little-endian instance.
     */
    public static UCS2Encoding getInstance(boolean bigEndian) {
        if (bigEndian)
            return (beInstance);
        else
            return (leInstance);
    }

    /**
     * Decode SMS message text to a Java String. The SMS message is expected to
     * be in UCS2 format.
     */
    public String decodeString(byte[] b) {
        if (b == null)
            return ("");

        try {
            return (new String(b, encType));
        } catch (java.io.UnsupportedEncodingException x) {
            return ("");
        }
    }

    /**
     * Encode a Java String to bytes using UCS2 (UTF-16).
     */
    public byte[] encodeString(String s) {
        if (s == null)
            return (new byte[0]);

        try {
            return (s.getBytes(encType));
        } catch (java.io.UnsupportedEncodingException x) {
            return (new byte[0]);
        }
    }
}
@@ -1074,16 +1074,62 @@
 .util;%0A%0A
+import java.io.UnsupportedEncodingException;%0A%0A
 public c
@@ -1206,34 +1206,55 @@
 ate 
-String encType = %22UTF-16BE
+static final String ENCODING = %22ISO-10646-UCS-2
 %22;%0A%0A
@@ -1303,38 +1303,32 @@
  private static 
-final 
 UCS2Encoding beI
@@ -1324,19 +1324,17 @@
 ncoding 
-beI
+i
 nstance 
@@ -1340,248 +1340,319 @@
  = n
-ew UCS2Encoding(true);%0A%0A    private static final UCS2Encoding leInstance = new UCS2Encoding(false);%0A%0A    /**%0A     * Construct a new UCS2 encoding.%0A     * %0A     * @param bigEndian%0A   
+ull;%0A    %0A    static %7B%0A        try %7B%0A            instance = new UCS2Encoding();%0A        %7D catch (UnsupportedEncodingException x) %7B%0A        %7D%0A    %7D%0A%0A    /**%0A     * Construct a new UCS2 encoding.%0A     * @throws java.io.UnsupportedEncodingException if the ISO-10646-UCS-2%0A
   
-*
    
-         true to use UTF-16BE, false to use UTF-16LE
+* charset is not supported by the JVM
 .%0A  
@@ -1662,22 +1662,21 @@
 */%0A    p
-rivate
+ublic
  UCS2Enc
@@ -1685,270 +1685,172 @@
 ing(
-boolean bigEndian) %7B%0A        super(DCS);%0A%0A        if (!bigEndian)%0A            encType = %22UTF-16LE%22;%0A    %7D%0A%0A    /**%0A     * Get the singleton instance of the big-endian UCS2Encoding.%0A     */%0A    public static UCS2Encoding getInstance() %7B%0A        return (beInstance
+) throws UnsupportedEncodingException %7B%0A        super(DCS);%0A%0A        // Force an exception if the charset is not supported.%0A        new String(new byte%5B0%5D, ENCODING
 );%0A 
@@ -1878,20 +1878,9 @@
 Get 
-the singleto
+a
 n in
@@ -1893,371 +1893,236 @@
  of 
-ei
 the
-r the big-endian or little-endian%0A     * instance of UCS2Encoding.%0A     * %0A     * @param bigEndian%0A     *            true to get the big-endian instance, false to get the%0A     *            little-endian instance.%0A     */%0A    public static UCS2Encoding getInstance(boolean bigEndian) %7B%0A        if (bigEndian)%0A            return (beInstance);%0A        else%0A    
+ UCS2Encoding.%0A     * @throws java.io.UnsupportedEncodingException if the ISO-10646-UCS-2%0A     * charset is not supported by the JVM.%0A     */%0A    public static UCS2Encoding getInstance() throws UnsupportedEncodingException %7B%0A
     
@@ -2137,11 +2137,9 @@
 rn (
-leI
+i
 nsta
@@ -2413,23 +2413,24 @@
 ring(b, 
-encType
+ENCODING
 ));%0A    
@@ -2750,15 +2750,16 @@
 tes(
-encType
+ENCODING
 ));%0A

Use "ISO-10646-UCS-2" charset.