{
// check the supplied encoding ...
// only Cp- encodings are supported ...
if (EncodingRegistry.getInstance().isSupportedEncoding(cp) == false)
{
throw new UnsupportedEncodingException("The encoding " + cp + "is not valid");
}
final String encodingName = cp.substring(2);
try
{
int i;
if (Character.isDigit(encodingName.charAt(encodingName.length() - 1)) == false)
{
i = Integer.parseInt(encodingName.substring(0, encodingName.length() - 1));
i += 10000;
}
else
{
i = Integer.parseInt(encodingName);
}
final byte[] retval = new byte[2];
retval[0] = (byte) (i >> 8);
retval[1] = (byte) (i & 0xff);
return retval;
}
catch (Exception e)
{
throw new UnsupportedEncodingException("The encoding " + cp + "is not valid");
}
}
throw new UnsupportedEncodingException("The encoding " + cp + " is no codepage encoding");
}