Java tutorial
//package com.java2s; public class Main { /** * @brief get charset value from one full html buffer * * @param buffer [IN] html buffer * * @return Return charset value */ public static String getCharSet(byte[] buffer) { final int MAX_HEADER_LENGTH = 512; String tmpStr = new String(buffer, 0, MAX_HEADER_LENGTH); boolean bHasCharSet = false; if (tmpStr.contains("charset")) { int start = tmpStr.indexOf("charset"); int end1 = tmpStr.indexOf(";", start); int end2 = tmpStr.indexOf("\"", start); int end = end1 < end2 && end1 != -1 ? end1 : end2; tmpStr = (String) tmpStr.subSequence(start + 7, end); tmpStr = tmpStr.replace("=", ""); tmpStr = tmpStr.trim(); bHasCharSet = true; } if (!bHasCharSet) { tmpStr = "utf-8"; } return tmpStr; } }