Here you can find the source of getReader(InputStream is)
private static Reader getReader(InputStream is) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class Main { private final static int LOOKAHEAD = 1024; private static Reader getReader(InputStream is) throws IOException { Reader reader = new BufferedReader(new InputStreamReader(is)); char c[] = "<?".toCharArray(); int pos = 0; reader.mark(LOOKAHEAD);//from w w w. j a va 2s.c o m while (true) { int value = reader.read(); // Check to see if we hit the end of the stream. if (value == -1) { throw new IOException("Encounter end of stream before start of XML."); } else if (value == c[pos]) { pos++; } else { if (pos > 0) { pos = 0; } reader.mark(LOOKAHEAD); } if (pos == c.length) { // We found the character set we were looking for. reader.reset(); break; } } return reader; } }