View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util;
8   
9   import java.io.ByteArrayOutputStream;
10  import java.io.OutputStreamWriter;
11  import java.lang.reflect.Method;
12  import java.nio.charset.Charset;
13  
14  public class CharSetUtils extends org.apache.commons.lang.CharSetUtils
15  {
16      public static String defaultCharsetName()
17      {
18          try
19          {
20              if (SystemUtils.IS_JAVA_1_4)
21              {
22                  return new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding();
23              }
24              else
25              {
26                  Class target = Charset.class;
27                  Method defaultCharset = target.getMethod("defaultCharset", ArrayUtils.EMPTY_CLASS_ARRAY);
28                  Charset cs = (Charset) defaultCharset.invoke(target, (Object[]) null);
29                  return cs.name();
30              }
31          }
32          catch (Exception ex)
33          {
34              throw new Error(ex);
35          }
36      }
37  }
38  
39