Skip to content

Commit

Permalink
Multiple attacks logging for Hpfeeds.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed Aug 13, 2020
1 parent 96b77e4 commit df02055
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Expand Up @@ -8,6 +8,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

import de.tudarmstadt.informatik.hostage.logging.RecordAll;
import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
Expand All @@ -18,15 +19,17 @@ public class JSONHelper {
File file = new File("/data/data/" + MainActivity.getContext().getPackageName() + "/" + PERSIST_FILENAME);


public void persistData(RecordAll record){
public void persistData(ArrayList<RecordAll> records){
try {
int BUFFER_SIZE = 8192;
String UTF8 = "utf8";
FileOutputStream fout = new FileOutputStream(file);
BufferedWriter fnw = new BufferedWriter(new OutputStreamWriter(fout, UTF8), BUFFER_SIZE);

JSONArray arr = new JSONArray();
arr.put(record.toJSON());
for(RecordAll record: records) {
arr.put(record.toJSON());
}
fnw.write(arr.toString());
fnw.close();
fout.close();
Expand All @@ -37,7 +40,6 @@ public void persistData(RecordAll record){
}

public String getFilePath(){
System.out.println("Filepath!!! "+file.getAbsolutePath());
return file.getAbsolutePath();
}
}
@@ -1,7 +1,7 @@
package de.tudarmstadt.informatik.hostage.hpfeeds.publisher;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import de.tudarmstadt.informatik.hostage.HostageApplication;
import de.tudarmstadt.informatik.hostage.commons.JSONHelper;
Expand All @@ -14,9 +14,9 @@ public class PublishHelper {
private DaoSession dbSession;
private DAOHelper daoHelper;
private int offset=0;
private int limit=10;
private int limit=20;
private int attackRecordOffset=0;
private int attackRecordLimit=9999;
private int attackRecordLimit=999;
LogFilter filter = null;
JSONHelper jsonHelper = new JSONHelper();

Expand Down Expand Up @@ -49,8 +49,7 @@ private void publisher() throws Hpfeeds.ReadTimeOutException, Hpfeeds.EOSExcepti

}

private RecordAll getLastInsertedRecord(){
RecordAll recordAll = daoHelper.getAttackRecordDAO().getRecordsForFilter(filter,offset,limit,attackRecordOffset,attackRecordLimit).get(0);
return recordAll;
private ArrayList<RecordAll> getLastInsertedRecord(){
return daoHelper.getAttackRecordDAO().getRecordsForFilter(filter,offset,limit,attackRecordOffset,attackRecordLimit);
}
}

0 comments on commit df02055

Please sign in to comment.