encoding method

Encoding encoding(
  1. MediaType contentType,
  2. [Encoding defaultValue = utf8]
)

Implementation

static Encoding encoding(
  MediaType contentType, [
  Encoding defaultValue = utf8,
]) {
  Encoding encoding;
  if (contentType != null && contentType.charset() != null) {
    encoding = Encoding.getByName(contentType.charset());
  }
  if (encoding == null) {
    encoding = defaultValue;
  }
  return encoding;
}