コード例 #1
0
  /** Adds the seached tweets to the file tweetsBase.csv */
  public void saveBase() {
    try {
      if (baseTweets == null) {
        baseTweets = new ArrayList<Tweet>();
      }
      CsvWriter csvOutput = new CsvWriter(new FileWriter(AppliSettings.filename, true), ';');
      for (Tweet tweet : listCleanTweets) {
        int index = alreadyIn(tweet.getId());
        if (index == -1) {
          csvOutput.write("" + tweet.getId());
          csvOutput.write(tweet.getUser());
          String text = cleanTweet(tweet.getTweet());
          csvOutput.write(text);
          csvOutput.write("" + tweet.getDate());
          csvOutput.write("" + tweet.getNote());
          csvOutput.endRecord();
          baseTweets.add(tweet);
        } else {
          updateCSV(tweet.getNote(), index);
        }
      }

      csvOutput.close();
    } catch (IOException e) {
      System.out.println("saveBase");
      System.out.println(e.getMessage());
    }
  }
コード例 #2
0
ファイル: PfTest.java プロジェクト: kluksa/SKZweb
  private void pisiCsv(CsvWriter csvWriter) {
    try {
      SortedMap<Date, Integer> vremena = new TreeMap<>();
      Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1"));
      cal.setTime(d1);
      int nrow = 0;
      while (!cal.getTime().after(d2)) {
        vremena.put(cal.getTime(), nrow);
        cal.add(Calendar.HOUR, 1);
        nrow++;
      }
      int size = selektiraniPodaci.keySet().size();

      csvWriter.write("Vrijeme");
      HashMap<ProgramMjerenja, Integer> komponente = new HashMap<>();
      Integer ncol = 0;
      for (ProgramMjerenja pm : selektiraniPodaci.keySet()) {
        try {
          komponente.put(pm, ncol);
          csvWriter.write(pm.getKomponentaId().getFormula());
          csvWriter.write("obuhvat");
          csvWriter.write("status");

          ncol++;
        } catch (IOException ex) {
          Logger.getLogger(PfTest.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      csvWriter.endRecord();
      Podatak[][] tablica = new Podatak[nrow][size];
      for (ProgramMjerenja pm : selektiraniPodaci.keySet()) {
        List<Podatak> podatak = podatakFacade.getPodatak(pm, d1, d2, true, true);
        for (Podatak p : podatak) {
          Integer i = komponente.get(pm);
          Integer j = vremena.get(p.getVrijeme());
          tablica[j][i] = p;
        }
      }
      for (Date d : vremena.keySet()) {
        try {

          csvWriter.write(sdf.format(d));
          for (int i = 0; i < ncol; i++) {
            Podatak p = tablica[vremena.get(d)][i];
            if (p != null) {
              csvWriter.write(p.getVrijednost().toString());
              csvWriter.write(p.getObuhvat().toString());
              csvWriter.write(Integer.toString(p.getStatus()));
            } else {

            }
          }
          csvWriter.endRecord();
        } catch (IOException ex) {
          Logger.getLogger(PfTest.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      csvWriter.flush();
    } catch (IOException ex) {
      Logger.getLogger(PfTest.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
コード例 #3
0
ファイル: IOStream.java プロジェクト: tama124/EPAV
  public void createCSVResultFile(RemoteHostList remoteHostList, String currentTime) {
    for (RemoteHost rh : remoteHostList.getListOfRemoteHost()) {
      String outpuCsvtFile =
          "./host/"
              + currentTime
              + "_"
              + rh.getIP()
              + "/"
              + currentTime
              + "_"
              + rh.getIP()
              + "_EPAV_Result.csv";

      try {
        CsvWriter csvOutput = new CsvWriter(new FileWriter(outpuCsvtFile, true), ' ');

        csvOutput.write("Remote host infomation:");
        csvOutput.endRecord();
        csvOutput.endRecord();

        csvOutput.write("IP Address:");
        csvOutput.write(rh.getIP());
        csvOutput.endRecord();

        csvOutput.write("MAC Address:");
        csvOutput.write(rh.getMAC());
        csvOutput.endRecord();

        csvOutput.write("Operating system details:");
        csvOutput.write(rh.getOS());
        csvOutput.endRecord();
        csvOutput.endRecord();

        csvOutput.write("List of Ports:");
        csvOutput.endRecord();

        csvOutput.write("Name");
        csvOutput.write("State");
        csvOutput.write("Service");
        csvOutput.write("Warning");
        csvOutput.write("Solution");
        csvOutput.endRecord();

        for (Port p : rh.getPorts().getListOfPort()) {
          csvOutput.write(p.getName());
          csvOutput.write(p.getState());
          csvOutput.write(p.getService());
          csvOutput.write(p.getWarning());
          csvOutput.write(p.getSolution());
          csvOutput.endRecord();
        }
        csvOutput.endRecord();

        csvOutput.write("List of Vulnerabilities:");
        csvOutput.endRecord();

        csvOutput.write("Name");
        csvOutput.write("State");
        csvOutput.write("Patches");
        csvOutput.endRecord();

        for (Vulnerability v : rh.getVulnerabilities().getListOfVulnerability()) {
          csvOutput.write(v.getName());
          csvOutput.write(v.getState());
          csvOutput.write(v.getPatchList().display());
          csvOutput.endRecord();
        }

        csvOutput.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #4
0
  public void exportarProspecto(String nombreArchivo) {

    String outputFile = nombreArchivo;

    // before we open the file check to see if it already exists
    boolean alreadyExists = new File(outputFile).exists();

    try {
      // use FileWriter constructor that specifies open for appending
      CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');

      // if the file didn't already exist then we need to write out the header line
      if (!alreadyExists) {
        csvOutput.write("Dni");
        csvOutput.write("Nombres");
        csvOutput.write("Apellido_Paterno");
        csvOutput.write("Apellido_Materno");
        csvOutput.write("Telefono");
        csvOutput.write("FechaContacto");
        csvOutput.write("Correo");
        csvOutput.write("Direccion");
        csvOutput.write("Distrito");
        csvOutput.write("Departamento");
        csvOutput.endRecord();
      }
      // else assume that the file already has the correct header line

      List<Prospecto> prospecto = new ArrayList<Prospecto>();
      prospecto = devolverListaProspecto();
      for (Prospecto prospectos : prospecto) {
        // write out a few records
        csvOutput.write(prospectos.getDni());
        csvOutput.write(prospectos.getNombres());
        csvOutput.write(prospectos.getApellido_Paterno());
        csvOutput.write(prospectos.getApellido_Materno());
        csvOutput.write(prospectos.getTelefono());
        csvOutput.write(prospectos.getFechaContacto());
        csvOutput.write(prospectos.getCorreo());
        csvOutput.write(prospectos.getDireccion());
        csvOutput.write(prospectos.getDistrito());
        csvOutput.write(prospectos.getDepartamento());

        csvOutput.endRecord();
      }

      csvOutput.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }