1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package de.tudarmstadt.informatik.hostage.logging;
- import java.io.FileOutputStream;
- import java.util.ArrayList;
- import android.content.Context;
- public class SQLLogger{
- Context context;
- DatabaseHandler dbh;
- private FileOutputStream log = null;
-
- public SQLLogger(Context context){
- this.context = context;
- dbh = new DatabaseHandler(context);
- }
- public void addRecord(SQLRecord record) {
- dbh.addRecord(record);
- }
-
- public void exportDatabase(){
- try {
- log = context.openFileOutput("hostage.log", Context.MODE_APPEND);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- ArrayList<SQLRecord> records = dbh.getAllRecords();
- for(SQLRecord record : records){
- writeLine(record);
- }
- }
-
- private void writeLine(SQLRecord record){
- if (log != null) {
- try {
- log.write((record.toString() + "\n").getBytes());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- public void exportDatabaseJson(){
- //TODO JSON implementieren, beachten dass nur jeder Angriff nicht jeder Record geloggt wird
- }
-
- public int getAttackCount(){
- return dbh.getAttackCount();
- }
-
- public int getAttackPerProtokollCount(String protocol){
- return dbh.getAttackPerProtokolCount(protocol);
- }
-
- public void clearLog(){
- dbh.clearData();
- }
- }
|