Skip to content

Commit

Permalink
Added duplicate lines removing
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexer125 committed Apr 23, 2020
1 parent 65ce651 commit d06855a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Binary file modified out/production/SELinux Denials tool/com/dexer125/Main.class
Binary file not shown.
35 changes: 34 additions & 1 deletion src/com/dexer125/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dexer125;

import java.io.*;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
Expand All @@ -27,7 +28,7 @@ public static void main(String[] args) {
//Read file line by line
reader = new BufferedReader(new FileReader(path));
//Write to output file
BufferedWriter writer = new BufferedWriter(new FileWriter(outPath + "output.txt"));
BufferedWriter writer = new BufferedWriter(new FileWriter(outPath + "outputTemp.txt"));
String line = reader.readLine();
while (line != null) {

Expand Down Expand Up @@ -72,6 +73,38 @@ else if (line.contains("avc: denied")&& line.contains("tcontext=u:r:")){
e.printStackTrace();
}

try {
// Code for duplicate line removing
System.out.println("Removing duplicates...");
PrintWriter printWriter = new PrintWriter(outPath + "output.txt");
BufferedReader bufferedReader = new BufferedReader(new FileReader(outPath + "outputTemp.txt"));
String line = bufferedReader.readLine();

HashSet<String> hashSet = new HashSet<String>();

while (line != null){

// Write only if not present in hashset
if (hashSet.add(line)){
printWriter.println(line);
}
line = bufferedReader.readLine();
}

printWriter.flush();
bufferedReader.close();
printWriter.close();
File tempFile = new File(outPath + "outputTemp.txt");
if (tempFile.delete()){
System.out.println("Temporary file removed.");
}
System.out.println("Duplicates removed.");
}
catch (IOException e){
e.printStackTrace();
}

}

}
/* Coded by Dexer125 */

0 comments on commit d06855a

Please sign in to comment.