Search in sources :

Example 41 with LineNumberReader

use of java.io.LineNumberReader in project camel by apache.

the class ConnectorModel method loadFile.

private static List<String> loadFile(InputStream fis) throws Exception {
    List<String> lines = new ArrayList<>();
    LineNumberReader reader = new LineNumberReader(new InputStreamReader(fis));
    String line;
    do {
        line = reader.readLine();
        if (line != null) {
            lines.add(line);
        }
    } while (line != null);
    reader.close();
    return lines;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) LineNumberReader(java.io.LineNumberReader)

Example 42 with LineNumberReader

use of java.io.LineNumberReader in project hazelcast by hazelcast.

the class MapWordCountAggregationPerformanceTest method fillMapWithDataEachLineNewEntry.

private static void fillMapWithDataEachLineNewEntry(HazelcastInstance hazelcastInstance) throws Exception {
    IMap<String, String> map = hazelcastInstance.getMap(MAP_NAME);
    for (String file : DATA_RESOURCES_TO_LOAD) {
        InputStream is = MapWordCountAggregationPerformanceTest.class.getResourceAsStream("/wordcount/" + file);
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(is));
        int batchSize = 10000;
        int batchSizeCount = 0;
        Map<String, String> batch = new HashMap<String, String>(batchSize);
        String line;
        while ((line = reader.readLine()) != null) {
            batch.put(UuidUtil.newSecureUuidString(), line);
            batchSizeCount++;
            if (batchSizeCount == batchSize) {
                map.putAll(batch);
                batchSizeCount = 0;
                batch.clear();
            }
        }
        if (batchSizeCount > 0) {
            map.putAll(batch);
            batch.clear();
        }
        is.close();
        reader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LineNumberReader(java.io.LineNumberReader)

Example 43 with LineNumberReader

use of java.io.LineNumberReader in project hazelcast by hazelcast.

the class MapWordCountAggregationPerformanceTest method fillMapWithData.

private static void fillMapWithData(HazelcastInstance hazelcastInstance) throws Exception {
    IMap<String, String> map = hazelcastInstance.getMap(MAP_NAME);
    for (String file : DATA_RESOURCES_TO_LOAD) {
        InputStream is = MapWordCountAggregationPerformanceTest.class.getResourceAsStream("/wordcount/" + file);
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line).append("\n");
        }
        map.put(UuidUtil.newSecureUuidString(), sb.toString());
        is.close();
        reader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) LineNumberReader(java.io.LineNumberReader)

Example 44 with LineNumberReader

use of java.io.LineNumberReader in project gephi by gephi.

the class ImporterDOT method execute.

@Override
public boolean execute(ContainerLoader container) {
    this.container = container;
    this.report = new Report();
    LineNumberReader lineReader = ImportUtils.getTextReader(reader);
    try {
        importData(lineReader);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            lineReader.close();
        } catch (IOException ex) {
        }
    }
    return !cancel;
}
Also used : Report(org.gephi.io.importer.api.Report) IOException(java.io.IOException) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 45 with LineNumberReader

use of java.io.LineNumberReader in project gephi by gephi.

the class ImporterGDF method execute.

@Override
public boolean execute(ContainerLoader container) {
    this.container = container;
    this.report = new Report();
    LineNumberReader lineReader = ImportUtils.getTextReader(reader);
    try {
        importData(lineReader);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            lineReader.close();
        } catch (IOException ex) {
        }
    }
    return !cancel;
}
Also used : Report(org.gephi.io.importer.api.Report) IOException(java.io.IOException) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Aggregations

LineNumberReader (java.io.LineNumberReader)401 IOException (java.io.IOException)203 InputStreamReader (java.io.InputStreamReader)167 FileReader (java.io.FileReader)102 File (java.io.File)79 InputStream (java.io.InputStream)64 StringReader (java.io.StringReader)64 ArrayList (java.util.ArrayList)54 FileInputStream (java.io.FileInputStream)33 BufferedReader (java.io.BufferedReader)27 PrintWriter (java.io.PrintWriter)25 HashMap (java.util.HashMap)22 FileNotFoundException (java.io.FileNotFoundException)20 BufferedWriter (java.io.BufferedWriter)16 FileWriter (java.io.FileWriter)16 Pattern (java.util.regex.Pattern)16 Test (org.junit.jupiter.api.Test)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Reader (java.io.Reader)14