if (val instanceof String) {
buffer.append((String)val);
}
else if (val.getClass() == byte[].class) {
buffer.append(new String((byte[]) val, context.getCharset()));
}
else {
throw new IOException(val.getClass() + " cannot be encoded as a String");
}
}