bda-datastore/src/main/java/gr/ntua/ece/cslab/selis/bda/datastore/connectors/DatastoreLocalFSConnector.java
public String put(Message row) throws Exception {
        File evlog = new File(conn.getFS() + "/EventLog.csv");
        FileWriter fw;
        BufferedWriter bw;
        if (!evlog.exists()) {
            // Initialize eventLog by writing column names in first line
            fw = new FileWriter(evlog);
            bw = new BufferedWriter(fw);
            for (KeyValue fields : row.getEntries()){
                String key = fields.getKey();
                bw.write( key + "\t");
            }
            bw.newLine();
        }
        else {
            // Append message in csv
            BufferedReader reader = new BufferedReader(new FileReader(conn.getFS() + "/EventLog.csv"));
            String[] fields = reader.readLine().split("\t");
            reader.close();
            fw = new FileWriter(evlog, true);
            bw = new BufferedWriter(fw);
            List<KeyValue> entries = row.getEntries();
            for (String field : fields) {
                String value = "null";
                for (KeyValue entry : entries) {
                    if (entry.getKey().equalsIgnoreCase(field)) {
                        value = entry.getValue();
                        break;
                    }
                }
                bw.write(value+"\t");
            }
            bw.newLine();
        }
        bw.close();
        fw.close();

        LineNumberReader lnr = new LineNumberReader(new FileReader(evlog));
        lnr.skip(Long.MAX_VALUE);
        Integer num = lnr.getLineNumber();
        lnr.close();
        return num.toString();
    }
// Used to initialize or append a message in the EventLog which is a csv file
Used to initialize or append a message in the EventLog which is a csv file
Used to initialize or append a message in the EventLog which is a csv file
public String put(Message row) throws Exception {
        File evlog = new File(conn.getFS() + "/EventLog.csv");
        FileWriter fw;
        BufferedWriter bw;
        if (!evlog.exists()) {
            fw = new FileWriter(evlog);
            bw = new BufferedWriter(fw);
            for (KeyValue fields : row.getEntries()){
                String key = fields.getKey();
                bw.write( key + "\t");
            }
            bw.newLine();
        }
        else {
            BufferedReader reader = new BufferedReader(new FileReader(conn.getFS() + "/EventLog.csv"));
            String[] fields = reader.readLine().split("\t");
            reader.close();
            fw = new FileWriter(evlog, true);
            bw = new BufferedWriter(fw);
            List<KeyValue> entries = row.getEntries();
            for (String field : fields) {
                String value = "null";
                for (KeyValue entry : entries) {
                    if (entry.getKey().equalsIgnoreCase(field)) {
                        value = entry.getValue();
                        break;
                    }
                }
                bw.write(value+"\t");
            }
            bw.newLine();
        }
        bw.close();
        fw.close();
        LineNumberReader lnr = new LineNumberReader(new FileReader(evlog));
        lnr.skip(Long.MAX_VALUE);
        Integer num = lnr.getLineNumber();
        lnr.close();
        return num.toString();
    }
public String put ( Message row ) throws Exception { File evlog = new File ( conn . getFS ( ) + "/EventLog.csv" ) ; FileWriter fw ; BufferedWriter bw ; if ( ! evlog . exists ( ) ) { fw = new FileWriter ( evlog ) ; bw = new BufferedWriter ( fw ) ; for ( KeyValue fields : row . getEntries ( ) ) { String key = fields . getKey ( ) ; bw . write ( key + "\t" ) ; } bw . newLine ( ) ; } else { BufferedReader reader = new BufferedReader ( new FileReader ( conn . getFS ( ) + "/EventLog.csv" ) ) ; String [ ] fields = reader . readLine ( ) . split ( "\t" ) ; reader . close ( ) ; fw = new FileWriter ( evlog , true ) ; bw = new BufferedWriter ( fw ) ; List < KeyValue > entries = row . getEntries ( ) ; for ( String field : fields ) { String value = "null" ; for ( KeyValue entry : entries ) { if ( entry . getKey ( ) . equalsIgnoreCase ( field ) ) { value = entry . getValue ( ) ; break ; } } bw . write ( value + "\t" ) ; } bw . newLine ( ) ; } bw . close ( ) ; fw . close ( ) ; LineNumberReader lnr = new LineNumberReader ( new FileReader ( evlog ) ) ; lnr . skip ( Long . MAX_VALUE ) ; Integer num = lnr . getLineNumber ( ) ; lnr . close ( ) ; return num . toString ( ) ; }
Used to initialize or append a message in the EventLog which is a csv file
Used to initialize or append a message in the EventLog which is a csv file
// Initialize eventLog by writing column names in first line // Append message in csv