/**
 * Copyright 2015 Nicolas Ferry <${email}>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.vsepml.storm.twitter;

import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichBolt;
import backtype.storm.tuple.Tuple;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.logging.Logger;

/**
 * Created by ferrynico on 10/01/15.
 */
public class StormTwitterHashTagIdentifier extends BaseRichBolt {

    private static final Logger journal = Logger.getLogger(StormTwitterStreamSpout.class.getName());

    private OutputCollector collector;
    private ArrayList<String> identifiers = new ArrayList<String>();

    public void addIdentifier(String filter){
        identifiers.add(filter.toLowerCase());
    }

    public void removeIdentifier(String filter){
        identifiers.remove(filter.toLowerCase());
    }

    public StormTwitterHashTagIdentifier(ArrayList<String> identifiers){
        super();
        this.identifiers=identifiers;
    }

    @Override
    public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) {
        this.collector = outputCollector;
    }

    @Override
    public void execute(Tuple tuple) {
        String hashtag = (String) tuple.getValueByField("hashtag");
        if(identifiers.contains(hashtag.toLowerCase())){
        }try {
            File file = new File("example.txt");
            BufferedWriter output = new BufferedWriter(new FileWriter(file));
            output.write((String)tuple.getValueByField("author"));
            output.close();
        } catch ( IOException e ) {
            e.printStackTrace();
        }
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {

    }
}

@@ -1376,16 +1376,74 @@
 ring%3E();
+%0A    private File file;%0A    private BufferedWriter output;
 %0A%0A    pu
@@ -1770,16 +1770,56 @@
 ifiers;%0A
+        file = new File(%22example.txt%22);%0A
     %7D%0A%0A 
@@ -2167,17 +2167,20 @@
         
-%7D
+    
 try %7B%0A  
@@ -2193,71 +2193,11 @@
     
-File file = new File(%22example.txt%22);%0A            BufferedWriter
+   
  out
@@ -2260,20 +2260,25 @@
     
+    
 output.
-write
+append
 ((St
@@ -2312,24 +2312,156 @@
 %22author%22));%0A
+%0A            %7D catch ( IOException e ) %7B%0A                e.printStackTrace();%0A            %7D finally %7B%0A                try %7B%0A        
             
@@ -2476,32 +2476,40 @@
 lose();%0A        
+  
+      
 %7D catch ( IOExce
@@ -2493,33 +2493,32 @@
        %7D catch (
- 
 IOException e ) 
@@ -2506,37 +2506,44 @@
 h (IOException e
- 
 ) %7B%0A
+        
             e.pr
@@ -2551,32 +2551,64 @@
 ntStackTrace();%0A
+                %7D%0A            %7D%0A
         %7D%0A    %7D%0A

Fix stupid bug