public static String getJSPEncoding(InputStream is) throws IOException {
String encoding = null;
String contentType = null;
Tokenizer jspTokenizer = new Tokenizer();
jspTokenizer.addSymbol("\n", true);
jspTokenizer.addSymbol(" ", true);
jspTokenizer.addSymbol("\t", true);
jspTokenizer.addSymbol(new TokenizerSymbol("dir", "<%@", "%>", false, false, true, false));
StringTokenizer directiveTokenizer = new StringTokenizer();
directiveTokenizer.addSymbol("\n", true);
directiveTokenizer.addSymbol(" ", true);
directiveTokenizer.addSymbol("\t", true);
directiveTokenizer.addSymbol("=");
directiveTokenizer.addSymbol("\"", "\"", false);
directiveTokenizer.addSymbol("'", "'", false);
StringTokenizer contentTypeTokenizer = new StringTokenizer();
contentTypeTokenizer.addSymbol(" ", true);
contentTypeTokenizer.addSymbol(";", true);
Reader reader = new InputStreamReader(is, "ISO-8859-1");
try {
jspTokenizer.setReader(reader);
while (jspTokenizer.hasMore()) {
Token token = jspTokenizer.nextToken();
if ("dir".equals(token.getName())) {
directiveTokenizer.setString(token.getInnerText());
if (directiveTokenizer.hasMore() && directiveTokenizer.nextToken().getText().equals("page")) {
while (directiveTokenizer.hasMore()) {
Token dTk = directiveTokenizer.nextToken();