public HistoricDump(Historic h, String fn) {
   _h = h;
   try {
     _fw = new FileWriter(fn);
     _fw.append("ID,Created At,Username,Content\n");
   } catch (IOException e) {
     System.err.println("ERR: Failed to create and/or write to the CSV file: " + e.getMessage());
     System.exit(1);
   }
 }
  /** @param args */
  public static void main(String[] args) {
    if (args.length != 5) {
      System.err.println(
          "Usage: HistoricDump <keywords> <start_date> <end_date> <feeds> <csv_filename>");
      System.err.println("Where...");
      System.err.println("  <keywords>     comma separated list of keywords");
      System.err.println("  <start_date>   start date (yyyymmddhhmmss)");
      System.err.println("  <end_date>     end date (yyyymmddhhmmss)");
      System.err.println("  <feeds>        comma separated list of feeds (twitter,digg,etc)");
      System.err.println("  <csv_filename> filename for the csv output");
      System.exit(1);
    }

    // Config
    String csdl =
        "interaction.type == \"twitter\" and language.tag == \"en\" and interaction.content contains_any \""
            + args[0].replace("\"", "\\\"")
            + "\"";

    DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");

    try {
      // Authenticate
      System.err.println("Creating user...");
      User user = new User(Config.username, Config.api_key);

      // Create the definition
      System.err.println("Creating definition...");
      Definition d = user.createDefinition(csdl);

      // Create the historic
      System.err.println("Creating historic...");
      Historic h = d.createHistoric(df.parse(args[1]), df.parse(args[2]), args[3], 100);

      // Display the playback ID
      System.err.println("Playback ID: " + h.getHash());

      // Create the consumer
      System.err.println("Getting the consumer...");
      StreamConsumer consumer =
          h.getConsumer(StreamConsumer.TYPE_HTTP, new HistoricDump(h, args[4]));

      // And start consuming
      System.err.println("Consuming...");
      System.err.println("--");
      consumer.consume();
    } catch (EInvalidData e) {
      System.err.print("InvalidData: ");
      System.err.println(e.getMessage());
    } catch (ECompileFailed e) {
      System.err.print("CompileFailed: ");
      System.err.println(e.getMessage());
    } catch (EAccessDenied e) {
      System.err.print("AccessDenied: ");
      System.err.println(e.getMessage());
    } catch (EAPIError e) {
      System.err.print("EAPIError: ");
      System.err.println(e.getMessage());
    } catch (ParseException e) {
      System.err.print("ParseException: ");
      System.err.println(e.getMessage());
    }
  }