Exemplo n.º 1
0
 private void closeQuietly(BufferedReader bf) {
   if (bf != null) {
     try {
       bf.close();
     } catch (IOException e) {
       log.error(e);
     }
   }
 }
Exemplo n.º 2
0
  /** @see Parser#process(java.io.File, String) */
  @Override
  public void process(File dataset, String identifier) throws ParserException {
    File file = findSingleFileOrComplain(dataset);

    SLALogItem slaLogItem =
        slaLogger.createLogItem(getHome() + ".process", "SDM4." + getHome() + ".process");
    slaLogItem.setMessageId(identifier);
    slaLogItem.addCallParameter(Parser.SLA_INPUT_NAME, dataset.getAbsolutePath());

    BufferedReader bf = null;
    String line = null;
    try {
      FileReader reader = new FileReader(file);
      bf = new BufferedReader(reader);

      long counter = 0;
      while ((line = bf.readLine()) != null) {
        if (!line.startsWith("#")) {
          LprAction action = LPRLineParser.parseLine(line);
          batch.add(action);
          counter++;
          if (counter % progressBatchSize == 0) {
            log.info("Progress: " + counter);
          }
          if (batch.size() == batchSize) {
            commitBatch();
          }
        }
      }

      commitBatch(); // commit den rest der kan være fra sidste gennemløb

      slaLogItem.addCallParameter(Parser.SLA_RECORDS_PROCESSED_MAME, "" + counter);
      slaLogItem.setCallResultOk();
      slaLogItem.store();
    } catch (Exception e) {
      slaLogItem.setCallResultError("LPRImporter failed - Cause: " + e.getMessage());
      slaLogItem.store();
      // This is potentially a security issue as the raw data is exposed (but it is hashed)
      throw new ParserException(
          e.getMessage() + " in line \"" + line + "\" of file " + file.getAbsolutePath(), e);
    } finally {
      closeQuietly(bf);
    }
  }