Advertisement
iPeer

Untitled

Sep 6th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. package com.ipeer.iutil.engine;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8.  
  9. public class Convert {
  10.  
  11. public static File logout, login;
  12. public static FileWriter fw;
  13.  
  14. public static void main(String[] args) throws IOException {
  15. if (args.length < 2) {
  16. System.err.println("Must supply 2 arguments: <file to convert> <output file>");
  17. System.exit(0);
  18. }
  19. logout = new File(args[1]);
  20. login = new File(args[0]);
  21. if (!login.exists()) {
  22. System.err.println("Source fil does not exist!");
  23. System.exit(0);
  24. }
  25. convert(login, logout);
  26. }
  27.  
  28. private static void convert(File login2, File logout2) throws IOException {
  29. System.out.println("Converting...");
  30. long now = System.currentTimeMillis();
  31. fw = new FileWriter(logout, true);
  32. BufferedReader a = new BufferedReader(new FileReader(login));
  33. String line = null;
  34. while ((line = a.readLine()) != null) {
  35. parseLine(line.replaceAll("\\[0m", ""));
  36. }
  37. fw.close();
  38. System.out.println("Done in "+(System.currentTimeMillis() - now)+"ms");
  39. }
  40.  
  41. private static void parseLine(String line) throws IOException {
  42. //System.err.println(line);
  43. if (line.contains("lost connection:")) {
  44. String u = line.split(" ")[3];
  45. writeToLog(line.split(" ")[0]+" "+line.split(" ")[1]+" "+u+" disconnected.");
  46. }
  47.  
  48. else if (line.contains("logged in with entity id")) {
  49. String u = line.split(" ")[3].replaceAll("\\[.*\\]", "");
  50. writeToLog(line.split(" ")[0]+" "+line.split(" ")[1]+" "+u+" connected.");
  51. }
  52. else if (line.contains("[INFO] <")) {
  53. String[] data = line.split(" ");
  54. String u = data[3].replaceAll("(<|>)", "");
  55. String message = data[4];
  56. for (int x = 5; x < data.length; x++)
  57. message = message+" "+data[x];
  58. if (!message.startsWith("P ")) {
  59. writeToLog(data[0]+" "+data[1]+" "+u+": "+message);
  60. }
  61. }
  62. // else
  63. // writeToLog(line);
  64. }
  65.  
  66. public static void writeToLog(String s) throws IOException {
  67. //RandomAccessFile a = new RandomAccessFile(new File(logout,"chat_"+c.toLowerCase()+".log"), "rw");
  68. fw.write(s+"\r\n");
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement