-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFileSourceProvider.java
More file actions
40 lines (36 loc) · 1.15 KB
/
Copy pathFileSourceProvider.java
File metadata and controls
40 lines (36 loc) · 1.15 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
33
34
35
36
37
38
39
40
package source;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
/**
* Implementation for loading content from local file system.
* This implementation supports absolute paths to local file system without specifying file:// protocol.
* Examples c:/1.txt or d:/pathToFile/file.txt
*/
public class FileSourceProvider implements SourceProvider {
@Override
public boolean isAllowed(String pathToSource) {
Path path = Paths.get(pathToSource);
if(Files.exists(path))
if(Files.isReadable(path))
return true;
return false;
}
@Override
public String load(String pathToSource) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(pathToSource));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line !=null) {
sb.append(line + "\n");
line = br.readLine();
}
return sb.toString();
}
finally {
br.close();
}
}
}