1 Reply Latest reply on Jan 23, 2008 10:30 AM by Marcos Carlevaro

    UnsupportedEncodingException when converting a String to a b

    Albert Smith Newbie

      Hi, I'm trying to get the byte array representation of a String using the Cp284 charset. When doing this in my local machine from a standalone program I have no problem. But when doing this inside my local JBoss a UnsupportedEncodingException raises.

      Anyone know how can I solve this?

      Thnx

       try {
       buffer = this.value.getBytes("Cp284");
       } catch (UnsupportedEncodingException uee) {
       throw uee;
       }
      


        • 1. Re: UnsupportedEncodingException when converting a String to
          Marcos Carlevaro Newbie

          I had the same problem.
          JBoss 4.0.4.GA, JDK 1.5

          The available charsets on your Java installation depend on the type of installation you performed (international or not). If you performed an "international" installation, you should have the "charsets.jar" file in <your_jdk_install_dir>\jre\lib (typically at C:\Program Files\jdk1.5.0). This jar contains the basic and extended charsets.

          However, this is not enough for it to work, since this file belongs to the "private" JRE installed by the JDK, and it is for use only by its tools. On the other hand, the public JRE can be used by other Java applications, and is contained outside the JDK (typically at C:\Program Files\Java\jre1.5.0).
          (Source: http://java.sun.com/j2se/1.5.0/install-windows.html, Private vs. public JRE)

          So the solution for me was to copy "charsets.jar" from the "private" JRE to the "public" JRE lib directory (tipically C:\Program Files\Java\jre1.5.0\lib). This made the extended international charsets available to my application.
          Copying charsets.jar to my web application's lib directory didn't help, adding the lib directory to the classpath didn't either.

          You may list the available charsets in your system this way:

          
          import java.nio.charset.Charset;
          
          Map<String, Charset> mapcharsets = Charset.availableCharsets();
          printMap(mapcharsets, "Available Charsets:");
          
           @SuppressWarnings("unchecked")
           public static void printMap(Map map, String message) {
           System.out.println(message);
           Set entries = map.entrySet();
           Iterator iterator = entries.iterator();
           while (iterator.hasNext()) {
           Map.Entry entry = (Map.Entry)iterator.next();
           System.out.println(entry.getKey() + " : "
           + entry.getValue());
           }
           System.out.println();
           }