コード例 #1
0
 /**
  * ½ØÈ¡Ò»¸ö×Ö·û´®ÖпªÍ·µ½Ö¸¶¨³¤¶ÈµÄ×Ö·û´®
  *
  * @param full ÍêÕûµÄ×Ö·û´®
  * @param end ÐÂ×Ö·û´®µÄ³¤¶È
  * @return
  */
 public static String cutString(String full, int end, String endStr) {
   try {
     if (end >= full.length()) {
       return full;
     } else {
       return full.substring(0, end) + endStr;
     }
   } catch (IndexOutOfBoundsException e) {
     e.printStackTrace();
     return null;
   }
 }
コード例 #2
0
  public void writeList() {
    PrintWriter out = null;

    try {
      System.out.println("Entering try statement");
      out = new PrintWriter(new FileWriter("OutFile.txt"));

      for (int i = 0; i < SIZE; i++) out.println("Value at: " + i + " = " + list.get(i));
    } catch (IndexOutOfBoundsException e) {
      System.err.println("Caught IndexOutOfBoundsException: " + e.getMessage());
    } catch (IOException e) {
      System.err.println("Caught IOException: " + e.getMessage());
    } finally {
      if (out != null) {
        System.out.println("Closing PrintWriter");
        out.close();
      } else {
        System.out.println("PrintWriter not open");
      }
    }
  }
コード例 #3
0
ファイル: TextViewHybrid.java プロジェクト: zukov/Jpicedt
  protected void getDimensionsFromLogFile(BufferedReader reader, PicText text) {
    if (reader == null) {
      return;
    }
    String line = ""; // il rale si j'initialise pas ...
    boolean finished = false;
    while (!finished) {
      try {
        line = reader.readLine();
      } catch (IOException ioex) {
        ioex.printStackTrace();
        return;
      }
      if (line == null) {
        System.out.println("Size of text not found in log file...");
        return;
      }

      System.out.println(line);
      Matcher matcher = LogFilePattern.matcher(line);

      if (line != null && matcher.find()) {
        System.out.println("FOUND :" + line);
        finished = true;
        try {
          text.setDimensions(
              0.3515 * Double.parseDouble(matcher.group(1)), // height, pt->mm (1pt=0.3515 mm)
              0.3515 * Double.parseDouble(matcher.group(2)), // width
              0.3515 * Double.parseDouble(matcher.group(3))); // depth
          areDimensionsComputed = true;
        } catch (NumberFormatException e) {
          System.out.println("Logfile number format problem: $line" + e.getMessage());
        } catch (IndexOutOfBoundsException e) {
          System.out.println("Logfile regexp problem: $line" + e.getMessage());
        }
      }
    }
    return;
  }