String (@Nullable CharSequence content) { if (content == null || content.length() == 0) { return null; } try (BufferedReader reader = new BufferedReader(new CharSequenceReader(content))) { for (int i = 0; i < MAX_CHARSET_ENCODING_LINE; i++) { final String line = reader.readLine(); if (line == null) { return null; } final Matcher matcher = ENCODING_PATTERN.matcher(line); if (matcher.find()) { final String charset = matcher.group(1); return normalizeCharset(charset); } } } catch (IOException ignored) { } return null; }