@Test public void parseCharset() { headers.put("Content-Type", "text/plain; charset=utf-8"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "text/plain; charset=utf-8"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "ISO-8859-1")); headers.put("Content-Type", "text/plain; charset=utf-8 "); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "text/plain; charset=utf-8; frozzle=bar"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); headers.clear(); assertEquals("UTF-8", HttpHeaderParser.parseCharset(headers)); headers.clear(); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); headers.put("Content-Type", "text/plain; charset="); assertEquals("UTF-8", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "text/plain"); assertEquals("UTF-8", HttpHeaderParser.parseCharset(headers)); headers.put("Content-Type", "application/json"); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); headers.put("Content-Type", "text/plain;"); assertEquals("UTF-8", HttpHeaderParser.parseCharset(headers)); }
public static String parseCharset(Map<String, String> headers, String defaultCharset) { String contentType = headers.get(HTTP.CONTENT_TYPE); if (contentType != null) { String[] params = contentType.split(";"); for (int i = 1; i < params.length; i++) { String[] pair = params[i].trim().split("="); if (pair.length == 2) { if (pair[0].equals("charset")) { return pair[1]; } } } } return defaultCharset; }
HttpHeaderParser { public static String parseCharset(Map<String, String> headers, String defaultCharset) { String contentType = headers.get(HTTP.CONTENT_TYPE); if (contentType != null) { String[] params = contentType.split(";"); for (int i = 1; i < params.length; i++) { String[] pair = params[i].trim().split("="); if (pair.length == 2) { if (pair[0].equals("charset")) { return pair[1]; } } } } return defaultCharset; } }
HttpHeaderParser { public static String parseCharset(Map<String, String> headers, String defaultCharset) { String contentType = headers.get(HTTP.CONTENT_TYPE); if (contentType != null) { String[] params = contentType.split(";"); for (int i = 1; i < params.length; i++) { String[] pair = params[i].trim().split("="); if (pair.length == 2) { if (pair[0].equals("charset")) { return pair[1]; } } } } return defaultCharset; }  }
HttpHeaderParser { public static String parseCharset(Map<String, String> headers, String defaultCharset) { String contentType = headers.get(HTTP.CONTENT_TYPE); if (contentType != null) { String[] params = contentType.split(";"); for (int i = 1; i < params.length; i++) { String[] pair = params[i].trim().split("="); if (pair.length == 2) { if (pair[0].equals("charset")) { return pair[1]; } } } } return defaultCharset; }  static Cache.Entry parseCacheHeaders(NetworkResponse response); static long parseDateAsEpoch(String dateStr); static String parseCharset(Map<String, String> headers, String defaultCharset); static String parseCharset(Map<String, String> headers); }
HttpHeaderParser { public static String parseCharset(Map<String, String> headers, String defaultCharset) { String contentType = headers.get(HTTP.CONTENT_TYPE); if (contentType != null) { String[] params = contentType.split(";"); for (int i = 1; i < params.length; i++) { String[] pair = params[i].trim().split("="); if (pair.length == 2) { if (pair[0].equals("charset")) { return pair[1]; } } } } return defaultCharset; }  static Cache.Entry parseCacheHeaders(NetworkResponse response); static long parseDateAsEpoch(String dateStr); static String parseCharset(Map<String, String> headers, String defaultCharset); static String parseCharset(Map<String, String> headers);  }