-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataLoaderBuffer.java
More file actions
32 lines (29 loc) · 1.08 KB
/
DataLoaderBuffer.java
File metadata and controls
32 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package ie.atu.sw;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
/**
* Abstract base class for data loaders that utilise buffered reading.
*
* This class provides utility methods in order to reuse the method
*
* @param <T> generic data type
*/
public abstract class DataLoaderBuffer<T> implements DataLoader<T> {
/**
* Reads all lines from a file then returns list of strings.
*
* Uses a buffered reader to read the file efficiently
*
* @param filePath The location of the file to load
* @return List of String, one string represent one line
* @throws RuntimeException If issue finding or loading the file
*/
public List<String> readFileLines(String filePath) { // Big O = O(n)
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)))) {
return br.lines().collect(Collectors.toList());
} catch (Exception e) {
throw new RuntimeException("Ops.. Reading error file: " + filePath, e);
}
}
}