private void readtbltaetigkeit() {
    try {
      CSVReader reader =
          new CSVReader(
              new InputStreamReader(
                  ConverterExecutor.class.getResourceAsStream("tbltaetigkeit.csv")));
      List<String[]> input = reader.readAll();

      for (String[] values : input) {
        String id = values[0];
        String taetigkeit = values[1];

        Activity act = new Activity();
        act.setId(Long.parseLong(id));
        act.setActivity(taetigkeit);
        activityDao.persist(act);

        activityId_activity.put(act.getId(), act);
      }

      reader.close();
    } catch (RuntimeException e) {

    } catch (IOException ioe) {

    }
  }
 @Parameters(name = "{0}: {1}: {2}")
 public static Iterable<String[]> loadTestsFromFile2() {
   File tFile =
       loadGradleResource(
           System.getProperty("user.dir")
               + separator
               + "build"
               + separator
               + "resources"
               + separator
               + "test"
               + separator
               + "testdata2.csv");
   List<String[]> rows = null;
   if (tFile.exists()) {
     CSVReader reader = null;
     try {
       reader = new CSVReader(new FileReader(tFile), ',');
       rows = reader.readAll();
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   LOGGER.info("Finished loadTestsFromFile2()");
   return rows;
 }
 public boolean moveNext() {
   try {
     outer:
     for (; ; ) {
       final String[] strings = reader.readNext();
       if (strings == null) {
         current = null;
         reader.close();
         return false;
       }
       if (filterValues != null) {
         for (int i = 0; i < strings.length; i++) {
           String filterValue = filterValues[i];
           if (filterValue != null) {
             if (!filterValue.equals(strings[i])) {
               continue outer;
             }
           }
         }
       }
       current = rowConverter.convertRow(strings);
       return true;
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
示例#4
0
  public void loadGeo() {

    try {
      CSVReader reader = new CSVReader(new FileReader(GEOFILE));
      String[] nextLine;
      int lineCounter = 0;
      while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        if (lineCounter > 0) {
          GeoRecord newRecord = new GeoRecord(nextLine);
          double[] key = new double[1];

          // Keep track of trps
          int tripNumber = newRecord.getTripId();
          if (tripNumber > tripCounter) tripCounter = tripNumber;
          key[0] = newRecord.getSecondsSinceMidnight();

          // Key the time range
          if (key[0] < firstTime) firstTime = key[0];
          if (key[0] > lastTime) lastTime = key[0];

          System.err.println("trying sec " + newRecord.getSecondsSinceMidnight());
          geoRecords.insert(key, newRecord);
        }
        lineCounter++;
      }
    } catch (Exception e) {
      System.err.println(e);
    }
  }
  @Override
  public Object deserialize(final Writable blob) throws SerDeException {
    Text rowText = (Text) blob;

    CSVReader csv = null;
    try {
      csv =
          newReader(
              new CharArrayReader(rowText.toString().toCharArray()),
              separatorChar,
              quoteChar,
              escapeChar);
      final String[] read = csv.readNext();

      for (int i = 0; i < numCols; i++) {
        if (read != null && i < read.length) {
          row.set(i, read[i]);
        } else {
          row.set(i, null);
        }
      }

      return row;
    } catch (final Exception e) {
      throw new SerDeException(e);
    } finally {
      if (csv != null) {
        try {
          csv.close();
        } catch (final Exception e) {
          // ignore
        }
      }
    }
  }
 /**
  * Extract annotation group upload data.
  *
  * @return a list of AnnotationGroupUpload
  * @throws ValidationException validation exception
  * @throws IOException I/O exception
  */
 public List<AnnotationGroupUploadContent> extractUploadData()
     throws ValidationException, IOException {
   List<AnnotationGroupUploadContent> annotationGroupUploads =
       new ArrayList<AnnotationGroupUploadContent>();
   CSVReader reader = new CSVReader(new FileReader(uploadFile));
   try {
     String[] fields;
     int lineNum = 0;
     while ((fields = reader.readNext()) != null) {
       lineNum++;
       if (fields.length != FILE_NUMBER_COLUMNS) {
         throw new ValidationException(
             "File must have "
                 + FILE_NUMBER_COLUMNS
                 + " columns instead of "
                 + fields.length
                 + " on line number "
                 + lineNum);
       }
       readDataLine(annotationGroupUploads, fields);
     }
     return annotationGroupUploads;
   } finally {
     IOUtils.closeQuietly(reader);
   }
 }
  private void process(String[] folders) throws Exception {

    FileOutputStream fos = new FileOutputStream(_outPath);
    BufferedOutputStream x = new BufferedOutputStream(fos);
    OutputStreamWriter out = new OutputStreamWriter(x);

    for (int i = 0; i < folders.length; i++) {

      String filePath = _inPath + folders[i] + "/Memory.csv";
      System.out.println(filePath);
      String temp = filePath + "_Cleaned";
      GenerateThroughput.cleanUp(filePath, temp, true);

      CSVReader reader = new CSVReader(new FileReader(temp));
      String[] nextLine;
      double maxTime = -1;
      // Find the max time
      while ((nextLine = reader.readNext()) != null) {
        for (int j = 0; j < nextLine.length / 4; j++) {
          try {
            if (maxTime < Double.parseDouble(nextLine[4 * j + 3])) {
              maxTime = Double.parseDouble(nextLine[4 * j + 3]);
            }
          } catch (Exception e) {
          }
        }
      }
      reader.close();
      out.write(folders[i] + "," + maxTime + '\n');
    }
    out.close();
    x.close();
    fos.close();
  }
示例#8
0
 protected static int readNLines(String filename) throws IOException {
   CSVReader reader = new CSVReader(new FileReader(filename));
   int n = 0;
   while (reader.readNext() != null) n++;
   reader.close();
   return n;
 }
示例#9
0
文件: Okno.java 项目: jwarzocha/new
    public void actionPerformed(ActionEvent e) {

      for (int i = 0; i < tabKolCSV.length; i++) tabKolCSV[i] = new String();
      iloscKolumn = 0;

      sciezkaPliku = textfieldPoleTekstowe.getText();
      String str = "";
      CSVReader reader;
      try {
        reader = new CSVReader(new FileReader(sciezkaPliku));
        String[] row;
        try {
          while ((row = reader.readNext()) != null) {
            for (int i = 0; i < row.length; i++) {
              tabKolCSV[i] = row[i];
              str = str + row[i] + ", ";
              iloscKolumn = i;
            }
            iloscKolumn = iloscKolumn + 1;
            break;
          }
        } catch (IOException e1) {
          textfieldCSV.setText("Problem z plikem!!!");
        }
      } catch (FileNotFoundException e3) {
        textfieldCSV.setText("Plik nie istnieje!!!");
      }

      textfieldCSV.setText("Kolumny: " + str);
    }
示例#10
0
  /**
   * Public constructor of an AirportParser object. Reads a .csv file with airport information and
   * fills the airportMap with the mapping information.
   *
   * @param filename The path to the file to read from.
   */
  public AirportParser(String filename) {
    try {
      airportMap = new HashMap<String, Airport>();
      CSVReader reader = new CSVReader(new FileReader(filename), ',');
      String[] airportRecord = null;
      reader.readNext();
      while ((airportRecord = reader.readNext()) != null) {
        Airport airport = new Airport();
        airport.setId(Integer.parseInt(airportRecord[0]));
        airport.setIdent(airportRecord[1]);
        airport.setType(airportRecord[2]);
        airport.setName(airportRecord[3]);
        airport.setIso_country(airportRecord[8]);
        airportMap.put(airport.getIdent(), airport);
      }

      reader.close();

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
示例#11
0
 /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   // TODO Auto-generated method stub
   String appPath = request.getServletContext().getRealPath("");
   String filePath = "";
   for (Part part : request.getParts()) {
     String fileName = extractFileName(part);
     filePath = appPath + File.separator + fileName;
     part.write(filePath);
     System.out.println("Wrote file to " + appPath + File.separator + fileName);
   }
   CSVReader reader = new CSVReader(new FileReader(filePath));
   String[] nextLine;
   ArrayList<DataBean> data = new ArrayList<DataBean>();
   while ((nextLine = reader.readNext()) != null) {
     // nextLine[] is an array of values from the line
     System.out.println(nextLine[0] + nextLine[1]);
     DataBean bean = new DataBean();
     bean.setUsername(nextLine[0]);
     bean.setPassword(nextLine[1]);
     data.add(bean);
   }
   // Remove Username,password header
   data.remove(0);
   request.setAttribute("data", data);
   request.getRequestDispatcher("output.jsp").forward(request, response);
 }
  @Test
  public void testZeroRhoScoreWithoutPreviousCoverage() throws IOException {

    EvoSuite evosuite = new EvoSuite();

    String targetClass = Compositional.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;

    Properties.OUTPUT_VARIABLES = RuntimeVariable.RhoScore.name();
    Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;

    String[] command = new String[] {"-class", targetClass, "-generateTests"};

    Object result = evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);

    List<?> goals = RhoCoverageFactory.getGoals();
    assertEquals(11, goals.size());

    String statistics_file =
        System.getProperty("user.dir")
            + File.separator
            + Properties.REPORT_DIR
            + File.separator
            + "statistics.csv";

    CSVReader reader = new CSVReader(new FileReader(statistics_file));
    List<String[]> rows = reader.readAll();
    assertTrue(rows.size() == 2);
    reader.close();

    assertEquals("0.5", rows.get(1)[0]);
  }
  private void readtblabschluss() {
    try {
      CSVReader reader =
          new CSVReader(
              new InputStreamReader(
                  ConverterExecutor.class.getResourceAsStream("tblabschluss.csv")));
      List<String[]> input = reader.readAll();

      for (String[] values : input) {
        String id = values[0];
        String longname = values[1];
        String shortname = values[2];

        Degree deg = new Degree();
        deg.setId(Long.parseLong(id));
        deg.setShortForm(shortname);
        deg.setTitle(longname);
        degreeDao.persist(deg);

        degreeId_degree.put(deg.getId(), deg);
      }

      reader.close();

    } catch (RuntimeException e) {
      throw e;
    } catch (IOException ioe) {

    }
    // CSVReader reader = new CSVReader(new )

  }
  private void readtblfirma() {
    try {
      CSVReader reader =
          new CSVReader(
              new InputStreamReader(ConverterExecutor.class.getResourceAsStream("tblfirma.csv")));
      List<String[]> input = reader.readAll();

      for (String[] values : input) {
        String id = values[0];
        String firma = values[1];
        String brancheId = values[2];
        String size = values[3];

        Company comp = new Company();
        comp.setId(Long.parseLong(id));
        comp.setCompany(firma);
        comp.setSize(size);

        Sector sec = sectorDao.findById(Long.parseLong(brancheId));
        comp.setSector(sec);

        companyDao.persist(comp);

        companyId_company.put(comp.getId(), comp);
      }

      reader.close();
    } catch (RuntimeException e) {

    } catch (IOException ioe) {

    }
  }
  /**
   * Constructor with input stock symbol
   *
   * <p>TODO - This should be a multiton, one and only one instance per symbol
   *
   * @param i_stockSymbol Input stock symbol
   */
  public KeyStatisticsDataPsv(String i_stockSymbol) {
    super(i_stockSymbol);

    CSVReader l_psvFile = UtilPsv.getCSVReaderKeyStatistics(i_stockSymbol);
    String[] l_line;
    try {
      while ((l_line = l_psvFile.readNext()) != null) {

        if (l_line[0].contains("#")) continue;

        if (l_line[0].equalsIgnoreCase("Market Cap (intraday)")) {
          this.setMarketCap(getBigInteger(l_line[1]));
        } else if (l_line[0].equalsIgnoreCase("Enterprise Value")) {
          this.setEnterpriseVal(getBigInteger(l_line[1]));
        } else if (l_line[0].equalsIgnoreCase("Trailing P/E (ttm, intraday)")) {
          this.setTrailingPE(getBigDecimal(l_line[1]));
        }
        // logger.info("{}  {}",l_line[0],l_line[1]);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    // TODO - Parse and load the file into our base classes
    //        KeyStatisticsDataInstance

  }
示例#16
0
  public void printStock() throws NumberFormatException, IOException {
    Reader changed;

    InputStream input =
        new URL(
                "http://finance.yahoo.com/d/quotes.csv?s="
                    + this.name.toUpperCase()
                    + "&f=nsl1ocghjkr")
            .openStream();
    changed = new InputStreamReader(input, "UTF-8");

    CSVReader reader = new CSVReader(changed);
    String[] nextLine;

    while ((nextLine = reader.readNext()) != null) {
      System.out.println("\nCompany: " + nextLine[0] + "(" + nextLine[1] + ")\n");
      System.out.println("\tPrice: " + nextLine[2]);
      System.out.println("\tOpen: " + nextLine[3]);
      System.out.println("\tChange: " + nextLine[4]);
      System.out.println("\tDay's Low: " + nextLine[5]);
      System.out.println("\tDay's High: " + nextLine[6]);
      System.out.println("\t52 Week Low: " + nextLine[7]);
      System.out.println("\t52 Week High: " + nextLine[8]);
      System.out.println("\tP/E Ratio: " + nextLine[9]);
    }
    reader.close();

    System.out.println("\n\tBought at: $" + this.initialPrice);
    System.out.println("\n\tShares owned: " + this.shares);
    System.out.println("\n\tCurrent earnings: $" + this.earnings);
  }
  public String readPackageName(InputStream in) throws ServiceException {
    String packageName = null;

    CSVReader reader;
    try {
      reader = new CSVReader(new InputStreamReader(in));

      String[] firstLine = reader.readNext();

      if (firstLine != null) {

        String[] nextLine = null;

        while ((nextLine = reader.readNext()) != null) {

          packageName = nextLine[0];
        }
      }
      reader.close();

    } catch (FileNotFoundException e) {
      throw new ServiceException(e);
    } catch (IOException e) {
      throw new ServiceException(e);
    }

    return packageName;
  }
示例#18
0
  public void updateStock() throws MalformedURLException, IOException {
    Reader changed;

    InputStream input =
        new URL(
                "http://finance.yahoo.com/d/quotes.csv?s="
                    + this.name.toUpperCase()
                    + "&f=nsl1ocghjkr")
            .openStream();
    changed = new InputStreamReader(input, "UTF-8");

    CSVReader reader = new CSVReader(changed);
    String[] nextLine = reader.readNext();

    // Store the stock opening and last prices
    this.openPrice = Double.parseDouble(nextLine[3]);
    this.lastPrice = Double.parseDouble(nextLine[2]);

    double currprice = Double.parseDouble(nextLine[2]);
    this.earnings = this.shares * (currprice - initialPrice);

    // Calculate and store the percent change for the stock
    this.percentChanged = (this.lastPrice - this.openPrice) / this.openPrice;

    reader.close();
    input.close();
  }
  private Map<String, List<Entity>> getEntitiesByGeneSymbol() {
    if (entitiesByGeneSymbol == null) {
      Map<String, List<List<String>>> omimEntriesByGeneSymbol = new HashMap<>();
      entitiesByGeneSymbol = new LinkedHashMap<>();

      try (CSVReader csvReader =
          new CSVReader(
              new InputStreamReader(new FileInputStream(file), forName("UTF-8")),
              OmimAnnotator.SEPARATOR,
              DEFAULT_QUOTE_CHARACTER,
              1)) {

        String[] values = csvReader.readNext();
        while (values != null) {
          addLineToMap(omimEntriesByGeneSymbol, values);
          values = csvReader.readNext();
        }

        for (String geneSymbol : omimEntriesByGeneSymbol.keySet()) {
          addEntityToGeneEntityList(omimEntriesByGeneSymbol, geneSymbol);
        }
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    }
    return entitiesByGeneSymbol;
  }
示例#20
0
  public static void readReferenceFile(String fileName) throws IOException {
    @SuppressWarnings("resource")
    CSVReader reader = new CSVReader(new FileReader(fileName), ',', '\"', '\0');

    String[] line;

    // parse lines
    while ((line = reader.readNext()) != null) {

      if (line.length > 1) {
        String key = line[0];
        String value = line[1];

        if (!reference.containsKey(key)) {
          ArrayList<String> placer = new ArrayList<String>();
          placer.add(value);
          reference.put(key, placer);
        } else {
          if (!reference.get(key).contains(value)) {
            reference.get(key).add(value);
          }
        }
      }
    }
  }
示例#21
0
  /**
   * * Loads the pax file and does a nearest neighbor search to match the nearest geo record in time
   */
  public void loadPax() {
    // Open pax file
    // for each line
    // create a PeopleRecord
    // match it to a Geo record

    try {
      CSVReader reader = new CSVReader(new FileReader(PAXFILE));
      String[] nextLine;
      int lineCounter = 0;
      while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        if (lineCounter > 0) {
          int secSinceMidnight = Integer.parseInt(nextLine[8]);
          double[] key = new double[1];
          key[0] = TIME_SHIFT + 1.0 * secSinceMidnight;
          GeoRecord matchingGeo = (GeoRecord) geoRecords.nearest(key);
          if (matchingGeo != null) {
            PeopleRecord pr = new PeopleRecord(nextLine);
            pr.setTimeShiftSeconds(TIME_SHIFT);
            matchingGeo.addPeopleRecord(pr);
          } else {
            System.err.println("Null Geo Returned!!");
          }
        }
        lineCounter++;
      }
    } catch (Exception e) {
      System.err.println(e);
    }
  }
  private static List<HttpLink> readCustomActionUrls() {

    List<HttpLink> customActionUrls = new ArrayList<>();

    for (int i = 0; i < 1000; i++) {
      String customActionUrlKey = "custom_action_url_" + (i + 1);
      String customActionUrlValue =
          applicationConfiguration_.safeGetString(customActionUrlKey, null);

      if (customActionUrlValue == null) continue;

      try {
        CSVReader reader = new CSVReader(new StringReader(customActionUrlValue));
        List<String[]> csvValuesArray = reader.readAll();

        if ((csvValuesArray != null)
            && !csvValuesArray.isEmpty()
            && (csvValuesArray.get(0) != null)) {
          String[] csvValues = csvValuesArray.get(0);

          if (csvValues.length == 2) {
            String url = csvValues[0];
            String linkText = csvValues[1];

            HttpLink httpLink = new HttpLink(url, linkText);
            customActionUrls.add(httpLink);
          }
        }
      } catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
      }
    }

    return customActionUrls;
  }
  private void readtblbranche() {
    try {
      CSVReader reader =
          new CSVReader(
              new InputStreamReader(ConverterExecutor.class.getResourceAsStream("tblbranche.csv")));
      List<String[]> input = reader.readAll();

      for (String[] values : input) {
        String id = values[0];
        String branche = values[1];

        Sector sec = new Sector();
        sec.setId(Long.parseLong(id));
        sec.setSector(branche);
        sectorDao.persist(sec);

        sectorId_sector.put(sec.getId(), sec);
      }

      reader.close();
    } catch (RuntimeException e) {

    } catch (IOException ioe) {

    }
  }
  @Override
  protected String doInBackground(String... params) {
    // TODO Auto-generated method stub
    String strAddress = params[0];

    try {
      // Document document = Jsoup.connect( strAddress ).get();
      // Elements elements = document.select( "AAAK" );

      URL yahoofin =
          new URL(
              "http://download.finance.yahoo.com/d/quotes.csv?s=GEKTERNA.AT,TENERGY.AT,OPAP.AT&f=nsl1op&e=.csv");
      URLConnection yc = yahoofin.openConnection();

      BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));

      CSVReader reader = new CSVReader(in);
      // String inputLine;
      List<String[]> stocks = new ArrayList<String[]>();
      String inputLine[];

      // while ( (inputLine = in.readLine()) != null ) {
      while ((inputLine = reader.readNext()) != null) {
        stocks.add(inputLine);
        Log.d("", inputLine[0]);
      }

    } catch (Exception x) {
      x.printStackTrace();
    }

    return null;
  }
 /** Deduces the names and types of a table's columns by reading the first line of a CSV file. */
 static RelDataType deduceRowType(
     JavaTypeFactory typeFactory, File file, List<CsvFieldType> fieldTypes) {
   final List<RelDataType> types = new ArrayList<RelDataType>();
   final List<String> names = new ArrayList<String>();
   CSVReader reader = null;
   try {
     reader = openCsv(file);
     final String[] strings = reader.readNext();
     for (String string : strings) {
       final String name;
       final CsvFieldType fieldType;
       final int colon = string.indexOf(':');
       if (colon >= 0) {
         name = string.substring(0, colon);
         String typeString = string.substring(colon + 1);
         fieldType = CsvFieldType.of(typeString);
         if (fieldType == null) {
           System.out.println(
               "WARNING: Found unknown type: "
                   + typeString
                   + " in file: "
                   + file.getAbsolutePath()
                   + " for column: "
                   + name
                   + ". Will assume the type of column is string");
         }
       } else {
         name = string;
         fieldType = null;
       }
       final RelDataType type;
       if (fieldType == null) {
         type = typeFactory.createJavaType(String.class);
       } else {
         type = fieldType.toType(typeFactory);
       }
       names.add(name);
       types.add(type);
       if (fieldTypes != null) {
         fieldTypes.add(fieldType);
       }
     }
   } catch (IOException e) {
     // ignore
   } finally {
     if (reader != null) {
       try {
         reader.close();
       } catch (IOException e) {
         // ignore
       }
     }
   }
   if (names.isEmpty()) {
     names.add("line");
     types.add(typeFactory.createJavaType(String.class));
   }
   return typeFactory.createStructType(Pair.zip(names, types));
 }
 /*
    Account Id
    Account Value
    Account Date
    Account Label
    External Family Account Id
 */
 @Override
 public Map<String, Integer> importDepositAccounts(
     Long externalApplicationId, String broker, byte[] csvDatas)
     throws CvqModelException, CvqObjectNotFoundException {
   ExternalDepositAccountItem edai;
   ExternalHomeFolder ehf;
   ExternalApplication ea = getExternalApplicationById(externalApplicationId);
   Map<String, Integer> report = new HashMap<String, Integer>();
   report.put("created", 0);
   report.put("updated", 0);
   report.put("ignored", 0);
   try {
     CSVReader csvReader = new CSVReader(new StringReader(new String(csvDatas)), ',', '"', 1);
     for (Object o : csvReader.readAll()) {
       boolean updated = false;
       String[] line = (String[]) o;
       ehf =
           genericDAO
               .simpleSelect(ExternalHomeFolder.class)
               .and("externalId", line[4])
               .and("externalApplication", ea)
               .unique();
       if (ehf == null) {
         report.put("ignored", report.get("ignored") + 1);
         continue;
       }
       edai =
           genericDAO
               .simpleSelect(ExternalDepositAccountItem.class)
               .and("externalItemId", line[0])
               .and("externalApplicationId", String.valueOf(externalApplicationId))
               .unique();
       if (edai != null) {
         genericDAO.delete(edai);
         report.put("updated", report.get("updated") + 1);
         updated = true;
       }
       edai =
           new ExternalDepositAccountItem(
               line[3],
               Double.valueOf(line[1]),
               EXTERNAL_APPLICATION_LABEL,
               line[0],
               DateUtils.parseIso(line[2]),
               Double.valueOf(line[1]),
               broker);
       edai.setExternalApplicationId(ea.getId().toString());
       edai.setExternalHomeFolderId(ehf.getExternalId());
       genericDAO.create(edai);
       if (!updated) report.put("created", report.get("created") + 1);
     }
   } catch (Exception e) {
     logger.error(e.getMessage());
     e.printStackTrace();
     HibernateUtil.getSession().getTransaction().rollback();
     throw new CvqModelException("external.error.csvImport");
   }
   return report;
 }
  private static List<GraphiteOutputModule> readGraphiteOutputModules() {

    List<GraphiteOutputModule> graphiteOutputModules = new ArrayList<>();

    for (int i = -1; i < 10000; i++) {
      String graphiteOutputModuleKey = "graphite_output_module_" + (i + 1);
      String graphiteOutputModuleValue =
          applicationConfiguration_.safeGetString(graphiteOutputModuleKey, null);

      if (graphiteOutputModuleValue == null) continue;

      try {
        CSVReader reader = new CSVReader(new StringReader(graphiteOutputModuleValue));
        List<String[]> csvValuesArray = reader.readAll();

        if ((csvValuesArray != null)
            && !csvValuesArray.isEmpty()
            && (csvValuesArray.get(0) != null)) {
          String[] csvValues = csvValuesArray.get(0);

          if (csvValues.length >= 4) {
            boolean isOutputEnabled = Boolean.valueOf(csvValues[0]);
            String host = csvValues[1];
            int port = Integer.valueOf(csvValues[2]);
            int numSendRetryAttempts = Integer.valueOf(csvValues[3]);

            int maxMetricsPerMessage = 1000;
            if (csvValues.length > 4) maxMetricsPerMessage = Integer.valueOf(csvValues[4]);

            boolean sanitizeMetrics = false;
            if (csvValues.length > 5) sanitizeMetrics = Boolean.valueOf(csvValues[5]);

            boolean substituteCharacters = false;
            if (csvValues.length > 6) substituteCharacters = Boolean.valueOf(csvValues[6]);

            String uniqueId = "Graphite-" + (i + 1);

            GraphiteOutputModule graphiteOutputModule =
                new GraphiteOutputModule(
                    isOutputEnabled,
                    host,
                    port,
                    numSendRetryAttempts,
                    maxMetricsPerMessage,
                    sanitizeMetrics,
                    substituteCharacters,
                    uniqueId);

            graphiteOutputModules.add(graphiteOutputModule);
          }
        }
      } catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
      }
    }

    return graphiteOutputModules;
  }
示例#28
0
  private List<String[]> readCSV(String fileName) throws IOException {
    FileInputStream fstream = new FileInputStream(fileName);

    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));

    CSVReader reader = new CSVReader(br);
    return reader.readAll();
  }
 private static String[] csvToArray(final String csv) {
     try {
         final CSVReader reader = new CSVReader(new StringReader(csv), SEPARATOR_CHAR);
         final String[] line = reader.readNext();
         return (line != null) ? line : new String[0];
     } catch (Exception e) {
         return new String[0];
     }
 }
示例#30
0
  /** @param args */
  public static void main(String[] args) throws IOException {
    String[] ids;

    if (args.length == 2 || args.length == 3) {
      String server = "http://localhost:8888/";
      File csvFile = new File(args[0]);
      CSVReader csvReader;
      int index;

      if (!csvFile.exists()) {
        LOGGER.error(BUNDLE.get("TC_FILE_NOT_FOUND") + csvFile);
        printUsageAndExit();
      }

      // Make sure format of supplied server URL is what we expect
      if (args.length == 3) {
        if (!args[2].startsWith("http://")) {
          args[2] = "http://" + args[2];
        }

        if (!args[2].endsWith("/")) {
          args[2] = args[2] + "/";
        }

        server = args[2];
      }

      if (!isLive(server)) {
        LOGGER.error(BUNDLE.get("TC_SERVER_404"), server);
        printUsageAndExit();
      }

      try {
        csvReader = new CSVReader(new FileReader(csvFile));
        index = Integer.parseInt(args[1]) - 1; // columns 1-based

        while ((ids = csvReader.readNext()) != null) {
          if (LOGGER.isInfoEnabled()) {
            LOGGER.info(BUNDLE.get("TC_CACHE_ID"), ids[index]);
          }

          cacheImage(server, ids[index]);
        }
      } catch (NumberFormatException details) {
        LOGGER.error(details.getMessage());
        printUsageAndExit();
      }

    }
    // else if (args.length == 1) {} // TODO: descend through directories
    else {
      printUsageAndExit();
    }
  }