예제 #1
0
  public BoardList() {
    URL url = null;
    HttpURLConnection http_url_connection = null;
    int response_code;
    String response_message;
    InputStreamReader in = null;
    BufferedReader reader = null;
    ParserDelegator pd = null;
    try {
      // httpでhtmlファイルを取得する一連の処理
      url = new URL("http://menu.2ch.net/bbsmenu.html");
      http_url_connection = (HttpURLConnection) url.openConnection();
      http_url_connection.setRequestMethod("GET");
      http_url_connection.setInstanceFollowRedirects(false);
      http_url_connection.setRequestProperty("User-Agent", "Monazilla/1.00");
      response_code = http_url_connection.getResponseCode();
      response_message = http_url_connection.getResponseMessage();
      in = new InputStreamReader(http_url_connection.getInputStream(), "SJIS");
      reader = new BufferedReader(in);

      pd = new ParserDelegator();
      pd.parse(reader, cb, true);
      in.close();
      reader.close();
      http_url_connection.disconnect();
    } catch (IOException e1) {
      e1.printStackTrace();
    }
  }
예제 #2
0
파일: FlocImporter.java 프로젝트: rgo/jDip
  /**
   * Get the game information.
   *
   * <p>Returns the imported text.
   */
  private String getGameInfo() throws IOException {
    final StringBuffer gameInformation = new StringBuffer(16384);

    URL u = null;
    BufferedReader reader = null;
    try {
      u =
          new URL(
              "http://www.floc.net/observer.py?judge="
                  + judgeName
                  + "&game="
                  + gameName
                  + "&page=history&history_from=0&history_to=999999");

      fic.flocImportMessage(Utils.getLocalString(READING_CONTACT));

      // output is in HTML, so using the HTML editor kit parser removes
      // HTML cruft.
      //
      reader = new BufferedReader(new InputStreamReader(u.openStream()));

      if (!isInProgress) {
        return "";
      }

      ParserDelegator parser = new ParserDelegator();
      parser.parse(
          reader,
          new HTMLEditorKit.ParserCallback() {
            public void handleText(char[] text, int pos) {
              if (!isInProgress) {
                gameInformation.setLength(0); // abort!
                return;
              }

              fic.flocImportMessage(Utils.getLocalString(READING_FROM_NET));
              gameInformation.append(text);
              gameInformation.append("\n");
            } // handleText()
          },
          false);
    } finally {
      if (reader != null) {
        reader.close();
      }
    }

    return gameInformation.toString();
  } // getGameInfo()