Construct an Encoding for a given JVM encoding.

@param jvmEncoding the name of the JVM encoding
@return an Encoding instance for the specified encoding, or an Encoding instance for the
default JVM encoding if the specified encoding is unavailable.
762482
public static Encoding getJVMEncoding(String jvmEncoding) {
    if ("UTF-8".equals(jvmEncoding)) {
      return new UTF8Encoding();
    }
    if (Charset.isSupported(jvmEncoding)) {
      return new Encoding(jvmEncoding);
    } else {
      return DEFAULT_ENCODING;
    }
  }
1294714
@Nonnull
  public QValue getQValueOfEncoding (@Nonnull final String sEncoding)
  {
    ValueEnforcer.notNull (sEncoding, "Encoding");

    // Direct search encoding
    QValue aQuality = m_aMap.get (_unify (sEncoding));
    if (aQuality == null)
    {
      // If not explicitly given, check for "*"
      aQuality = m_aMap.get (AcceptEncodingHandler.ANY_ENCODING);
      if (aQuality == null)
      {
        // Neither encoding nor "*" is present
        // -> assume minimum quality
        return QValue.MIN_QVALUE;
      }
    }
    return aQuality;
  }
1071425
public static byte[] getBytes(String string, String encoding) {
        try {
            return string.getBytes(encoding);
        } catch(UnsupportedEncodingException e) {
            throw new IllegalArgumentException(encoding + " is not a known encoding name.", e);
        }
    }
596312
public static EncodingReader getReadFactory(final String encoding)
    throws UnsupportedEncodingException
  {
    String encKey = encoding == null ? "iso-8859-1" : encoding;

    EncodingReader factory = _readEncodingFactories.get(encKey);

    if (factory == null) {
      try {
        String javaEncoding = Encoding.getJavaName(encoding);

        if (javaEncoding == null)
          javaEncoding = "ISO8859_1";

        String className = "com.caucho.v5.vfs.i18n." + javaEncoding + "Reader";

        Class<?> cl = Class.forName(className);

        factory = (EncodingReader) cl.newInstance();
        factory.setJavaEncoding(javaEncoding);
      } catch (Throwable e) {
      }

      if (factory == null) {
        String javaEncoding = Encoding.getJavaName(encoding);

        if (javaEncoding == null)
          javaEncoding = "ISO8859_1";

        factory = new JDKReader();
        factory.setJavaEncoding(javaEncoding);
      }

      _readEncodingFactories.put(encKey, factory);
    }

    return factory;
  }
302389
public void setInputEncoding(String encoding) {
        if (StringUtils.isNotEmpty(encoding)) {
            Charset.forName(encoding);
            this.encoding = encoding;
        }
    }
621836
public String encodeForWebClient() throws MessageEncodeFailedException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "encodeForWebClient");
    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "Encoding Web Message", ((MessageImpl)jmsMsg).debugMsg());

    // Make sure any transients necessary are written back to the message
    ((JsJmsMessageImpl)jmsMsg).updateDataFields(MfpConstants.UDF_ENCODE);

    StringBuffer result = new StringBuffer();

    // Version number
    result.append(1);

    // Message Id
    result.append('~');
    byte[] id = jmsMsg.getCorrelationIdAsBytes();
    if (id != null)
      HexString.binToHex(id, 0, id.length, result);

    // Message type
    result.append('~');
    String type = jmsMsg.getJmsxAppId();
    if (type == null || type.equals(MfpConstants.WPM_JMSXAPPID_VALUE))
      type = "SIB";
    URLEncode(result, type);

    // Message format
    result.append('~');
    result.append(jmsMsg.getFormat());

    // Topic
    result.append('~');
    String topic = jmsMsg.getDiscriminator();
    if (topic != null)
      URLEncode(result, topic);

    // Properties
    result.append('~');
    Set<String> names = jmsMsg.getPropertyNameSet();
    boolean first = true;
    for (Iterator<String> i = names.iterator(); i.hasNext(); ) {
      String name = i.next();

      // JMSXAppID is stored in the header field instead so ignore it here
      if (!name.equals(SIProperties.JMSXAppID)) {

        // All objects
        Object value = jmsMsg.getObjectProperty(name);
        if (value != null) {
          encodePair(result, name, value, first);
          first = false;
        }
      }
    }

    // Body
    if (jmsMsg instanceof JsJmsTextMessage)
      encodeTextBody(result, (JsJmsTextMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsBytesMessage)
      encodeBytesBody(result, (JsJmsBytesMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsObjectMessage)
      encodeObjectBody(result, (JsJmsObjectMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsStreamMessage)
      encodeStreamBody(result, (JsJmsStreamMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsMapMessage)
      encodeMapBody(result, (JsJmsMapMessage)jmsMsg);

    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "Encoded as web data", result);
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "encodeForWebClient");
    return result.toString();
  }
858301
public static Writer getOutputStreamWriter(OutputStream out) {
    try {
      return new OutputStreamWriter(out, "UTF-8");
    }
    catch (UnsupportedEncodingException ex) {
      throw new RuntimeException(ex); // shouldn't happen since UTF-8 is supported by all JVMs per spec
    }
  }
389335
private static int acquireFileEncodingCcsid() {
        // Get the charset represented by file.encoding
        Charset charset = null;
        String fileEncoding = System.getProperty("file.encoding");
        try {
            charset = Charset.forName(fileEncoding);
        } catch (Throwable t) {
            // Problem with the JVM's file.encoding property
        }

        int ccsid = getCcsid(charset);
        if (ccsid == 0) {
            System.err.println(MessageFormat.format(BootstrapConstants.messages.getString("warn.fileEncodingNotFound"), fileEncoding));
        }
        return ccsid;
    }
167355
private String decode(byte[] data, String encoding) {

        try {
            return new String(data, encoding);
        } catch (UnsupportedEncodingException e) {
            LOG.warn(e.getLocalizedMessage(), e);
            return new String(data);
        }
    }
857430
private static final String encode(String s) {
    try {
      return URLEncoder.encode(s, UTF_8);
    } catch (UnsupportedEncodingException e) {
      throw new Error("JVM unable to handle UTF-8");
    }
  }
37285
public static boolean isValidJavaEncoding(String javaEncoding) {
        if (javaEncoding != null) {
            int length = javaEncoding.length();
            if (length > 0) {
                for (int i = 1; i < length; i++) {
                    char c = javaEncoding.charAt(i);
                    if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') &&
                        (c < '0' || c > '9') && c != '.' && c != '_' &&
                        c != '-') {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    }
198250
public static EncodingUtils getEncodingUtils() {
        HttpDispatcher f = instance.get().get();
        EncodingUtils svc = null;
        if (f != null) {
            svc = f.encodingSvc;
        }

        if (svc == null)
            svc = new EncodingUtilsImpl();

        return svc;
    }
378894
public Writer getWriter(String encoding)
        throws IOException
    {
        if (encoding==null ||
            StringUtil.__ISO_8859_1.equalsIgnoreCase(encoding)  ||
            "ISO8859_1".equalsIgnoreCase(encoding))
            return getISO8859Writer();

        if ("UTF-8".equalsIgnoreCase(encoding) ||
            "UTF8".equalsIgnoreCase(encoding))
            return getUTF8Writer();
        
        if ("US-ASCII".equalsIgnoreCase(encoding))
            return getASCIIWriter();

        return new OutputStreamWriter(this,encoding);
    }
1345866
public static boolean isRecognizedEncoding(String encoding)
    {
        EncodingInfo ei;

        String normalizedEncoding = encoding.toUpperCase();
        ei = (EncodingInfo) _encodingTableKeyJava.get(normalizedEncoding);
        if (ei == null)
            ei = (EncodingInfo) _encodingTableKeyMime.get(normalizedEncoding);
        if (ei != null)
            return true;
        return false;
    }
341424
public static String encodeString(String s) {

        try {
            return CODEC.encode(s.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // shouldn't happen
            return null;
        }
    }
626327
def htmlSetMetaEncoding(self, encoding):
        
        ret = libxml2mod.htmlSetMetaEncoding(self._o, encoding)
        return ret
1066069
private static String getEncodingToUse(String encoding)
    {
        //get encoding
        String updatedEncoding=encoding;
        if(updatedEncoding==null)
        {
            updatedEncoding=IOHelper.getDefaultEncoding();
        }
        
        return updatedEncoding;
    }