public void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException {
        //Ensure the specified encoding is valid
        byte[] buffer = new byte[1];
        buffer[0] = (byte) 'a';
        new String(buffer, enc); // dummy to check encoding