1 package com.proalpha.pds.paconnector.utils;
3 import java.io.UnsupportedEncodingException;
4 import java.nio.charset.Charset;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
11 private static final Logger logger = LoggerFactory.getLogger(
CharsetConverter.class);
22 public static String
encode(
final String codepage,
final String str) {
28 if (codepage !=
null) {
30 if (Charset.isSupported(codepage)) {
31 retval = doEncoding(codepage, str);
32 }
else if (Charset.isSupported(
"cp" + codepage)) {
33 retval = doEncoding(
"cp" + codepage, str);
35 throw new UnsupportedEncodingException(String.format(
"Codepage %s is not supported.", codepage));
38 }
catch (UnsupportedEncodingException e) {
39 logger.error(e.getMessage(), e);
49 private static String doEncoding(
final String codepage,
final String str) {
50 return new String(Charset.forName(codepage).encode(str).array());
static String encode(final String codepage, final String str)