// only encode if told to and this contains non-ASCII charactes.
if (encodeParameters && !ASCIIUtil.isAscii(value)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
RFC2231Encoder encoder = new RFC2231Encoder(HeaderTokenizer.MIME);
// extract the bytes using the given character set and encode
byte[] valueBytes = value.getBytes(MimeUtility.javaCharset(charset));
// the string format is charset''data
out.write(charset.getBytes());
out.write('\'');
out.write('\'');
encoder.encode(valueBytes, 0, valueBytes.length, out);
// default in case there is an exception
_parameters.put(name, new ParameterValue(name, value, new String(out.toByteArray())));
return;