Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. package com.intrallect.logfilter;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.nio.charset.Charset;
  6. import java.nio.file.Files;
  7. import java.nio.file.Path;
  8. import java.util.List;
  9. import java.util.regex.Matcher;
  10. import java.util.regex.Pattern;
  11.  
  12. public class Main {
  13.  
  14.     public static void main(final String[] args) throws IOException {
  15.         // TODO Auto-generated method stub
  16.         final Path filePath = new File("/home/bence/rndamat.catalina.out").toPath();
  17.         final Charset charset = Charset.defaultCharset();
  18.         final List<String> lines = Files.readAllLines(filePath, charset);
  19.         for (int i = 0; i < lines.size(); i++) {
  20.             final String currentLine = lines.get(i);
  21.             // check if line is Mission Control related
  22.             if (currentLine.contains("com.intrallect.amauthor.service.MissionControlService")) {
  23.                 if (currentLine.contains("Unpublishing")) {
  24.  
  25.                 }
  26.                 // check for overwrite
  27.                 if (currentLine.contains("Overwriting")) {
  28.                     try {
  29.                         final Pattern pattern = Pattern.compile("'(.+)'.\\(id: (\\d+)\\) with (.+) in (.+)");
  30.                         final Matcher matcher = pattern.matcher(currentLine);
  31.                         matcher.find();
  32.                         final String originalName = matcher.group(1).trim();
  33.                         final String newName = matcher.group(3).trim();
  34.                         if (!newName.equals(originalName)) {
  35.                             System.out.println(originalName + " was replaced by " + newName + " in " + matcher.group(4) + " Resource Id: " + matcher.group(2));
  36.                         }
  37.                     } catch (final IllegalStateException ise) {
  38.                         System.out.println(currentLine);
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement