コード例 #1
0
  /**
   * Messages will be read from the given filepath and stored in the array list (messagesList)
   *
   * @param filePath Text file to be read
   */
  public static List<String> readFile(String filePath) {
    BufferedReader bufferedReader = null;
    StringBuffer message = new StringBuffer("");
    final String asterixLine = "*****";
    List<String> messagesList = new ArrayList<String>();
    try {

      String line;
      bufferedReader = new BufferedReader(new FileReader(filePath));
      while ((line = bufferedReader.readLine()) != null) {
        if ((line.equals(asterixLine.trim()) && !"".equals(message.toString().trim()))) {
          messagesList.add(message.toString());
          message = new StringBuffer("");
        } else {
          message = message.append(String.format("\n%s", line));
        }
      }
      if (!"".equals(message.toString().trim())) {
        messagesList.add(message.toString());
      }
    } catch (FileNotFoundException e) {
      log.error("Error in reading file " + filePath, e);
    } catch (IOException e) {
      log.error("Error in reading file " + filePath, e);
    } finally {
      try {
        if (bufferedReader != null) {
          bufferedReader.close();
        }
      } catch (IOException e) {
        log.error("Error occurred when closing the file : " + e.getMessage(), e);
      }
    }
    return messagesList;
  }
コード例 #2
0
ファイル: QLender.java プロジェクト: feuyeux/airfactory
  public static void main(String argv[]) {
    String queuecf = null;
    String requestq = null;
    if (argv.length == 2) {
      queuecf = argv[0];
      requestq = argv[1];
    } else {
      System.out.println("Invalid arguments. Should be: ");
      System.out.println("java QLender factory request_queue");
      System.exit(0);
    }

    QLender lender = new QLender(queuecf, requestq);

    try {
      // Run until enter is pressed
      BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("QLender application started");
      System.out.println("Press enter to quit application");
      stdin.readLine();
      lender.exit();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }
コード例 #3
0
ファイル: QLender.java プロジェクト: feuyeux/airfactory
 private static void enter4quit(QLender lender) {
   try {
     // Run until enter is pressed
     BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
     System.out.println("QLender application started");
     System.out.println("Press enter to quit application");
     stdin.readLine();
     lender.exit();
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }