Search in sources :

Example 1 with CsvParseException

use of org.spf4j.io.csv.CsvParseException in project spf4j by zolyfarkas.

the class RecorderFactory method buildStoreFromConfig.

/**
 * Configuration is a coma separated list of stores:
 * TSDB@/path/to/file.tsdb,TSDB_TXT@/path/to/file.tsdbtxt,GRAPHITE_UDP@1.1.1.1:8080,GRAPHITE_TCP@1.1.1.1:8080
 *
 * @param configuration
 * @return a measurement store.
 */
@Nonnull
// the config is not supplied by a user.
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
private static MeasurementStore buildStoreFromConfig(@Nullable final String configuration) throws IOException, ObjectCreationException {
    if (configuration == null || configuration.trim().isEmpty()) {
        return new TSDBMeasurementStore(new File(System.getProperty("spf4j.perf.ms.defaultTsdbFolderPath", System.getProperty("java.io.tmpdir")) + File.separator + CharSequences.validatedFileName(System.getProperty("spf4j.perf.ms.defaultTsdbFileNamePrefix", ManagementFactory.getRuntimeMXBean().getName() + ".tsdb2"))));
    }
    List<String> stores;
    try {
        stores = Csv.readRow(new StringReader(configuration));
    } catch (CsvParseException ex) {
        throw new IllegalArgumentException("Invalid configuration " + configuration, ex);
    }
    final int size = stores.size();
    if (size == 1) {
        return fromString(stores.get(0));
    } else {
        MeasurementStore[] mstores = new MeasurementStore[size];
        int i = 0;
        for (String config : stores) {
            mstores[i] = fromString(config);
            i++;
        }
        return new MultiStore(mstores);
    }
}
Also used : CsvParseException(org.spf4j.io.csv.CsvParseException) StringReader(java.io.StringReader) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) MeasurementStore(org.spf4j.perf.MeasurementStore) MultiStore(org.spf4j.perf.impl.ms.MultiStore) File(java.io.File) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with CsvParseException

use of org.spf4j.io.csv.CsvParseException in project spf4j by zolyfarkas.

the class CsvTest method testCsvReadWriteException.

@Test(expected = CsvParseException.class)
public void testCsvReadWriteException() throws IOException, CsvParseException {
    File testFile = createTestCsv();
    Csv.read(testFile, Charsets.UTF_8, new Csv.CsvHandler<Void>() {

        @Override
        public void element(final CharSequence elem) throws CsvParseException {
            throw new CsvParseException("Yohooo at " + elem);
        }

        @Override
        public Void eof() {
            return null;
        }
    });
}
Also used : UncheckedCsvParseException(org.spf4j.io.csv.UncheckedCsvParseException) CsvParseException(org.spf4j.io.csv.CsvParseException) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)2 CsvParseException (org.spf4j.io.csv.CsvParseException)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 StringReader (java.io.StringReader)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1 UncheckedCsvParseException (org.spf4j.io.csv.UncheckedCsvParseException)1 MeasurementStore (org.spf4j.perf.MeasurementStore)1 MultiStore (org.spf4j.perf.impl.ms.MultiStore)1 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)1