code: public static void parse(SimpleXMLDocHandler doc, InputStream in) throws IOException {
          byte b4[] = new byte[4];
          int count = in.read(b4);
          if (count != 4)
              throw new IOException("Insufficient length.");
          String encoding = getEncodingName(b4);
          String decl = null;
          if (encoding.equals("UTF-8")) {
              StringBuffer sb = new StringBuffer();
              int c;
              while ((c = in.read()) != -1) {
                  if (c == '>')
                      break;
                  sb.append((char)c);
              }
              decl = sb.toString();
          }
          else if (encoding.equals("CP037")) {
              ByteArrayOutputStream bi = new ByteArrayOutputStream();
              int c;
              while ((c = in.read()) != -1) {
                  if (c == 0x6e) // that's '>' in ebcdic
                      break;
                  bi.write(c);
              }
              decl = new String(bi.toByteArray(), "CP037");
          }
          if (decl != null) {
              decl = getDeclaredEncoding(decl);
              if (decl != null)
                  encoding = decl;
          }
          parse(doc, new InputStreamReader(in, IanaEncodings.getJavaEncoding(encoding)));
      }
docs: Parses the XML document firing the events to the handler.
  @param doc the document handler
  @param in the document. The encoding is deduced from the stream. The stream is not closed
  @throws IOException on error