Converts a String SJIS or JIS URL encoded hex encoding to a Unicode String : URLEncoder « Network Protocol « Java






Converts a String SJIS or JIS URL encoded hex encoding to a Unicode String

    
/* Copyright 2004 Sun Microsystems, Inc.  All rights reserved.  You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: 
 http://adventurebuilder.dev.java.net/LICENSE.txt
 $Id: I18nUtil.java,v 1.2 2004/05/26 00:07:34 inder Exp $ */

import java.io.ByteArrayOutputStream;

/**
 * This utility class for internationalization. This class provides a central
 * location to do specialized formatting in both a default and a locale specfic
 * manner.
 */
public class Main {

  /**
   * Converts a String SJIS or JIS URL encoded hex encoding to a Unicode String
   * 
   */
  public static String convertJISEncoding(String target) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    if (target == null)
      return null;
    String paramString = target.trim();

    for (int loop = 0; loop < paramString.length(); loop++) {
      int i = (int) paramString.charAt(loop);
      bos.write(i);
    }
    String convertedString = null;
    try {
      convertedString = new String(bos.toByteArray(), "JISAutoDetect");
    } catch (java.io.UnsupportedEncodingException uex) {
    }
    return convertedString;
  }
}

   
    
    
    
  








Related examples in the same category

1.URL Encoder: similar to the java.net.URLEncoder class
2.Decoding and encoding URLs
3.Parse a x-www-form-urlencoded string
4.URL Encoder: Encode a string according to RFC 1738.
5.Encode a path as required by the URL specification
6.Calls java.net.URLEncoder.encode(String, String) via reflection, if we are running on JRE 1.4 or later, otherwise reverts to the deprecated URLEncoder.encode(String)method.
7.Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding.
8.Provides a method to encode any string into a URL-safe form
9.Request parsing and encoding utility methods