1 |
| |
2 |
| |
3 |
| |
4 |
| package net.sourceforge.pmd; |
5 |
| |
6 |
| import java.io.File; |
7 |
| import java.io.FileInputStream; |
8 |
| import java.io.IOException; |
9 |
| import java.io.InputStream; |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| public class FileDataSource implements DataSource { |
15 |
| |
16 |
| private static final String fileSeparator = System.getProperty("file.separator"); |
17 |
| |
18 |
| private File file; |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
0
| public FileDataSource(File file) {
|
24 |
0
| this.file = file;
|
25 |
| } |
26 |
| |
27 |
0
| public InputStream getInputStream() throws IOException {
|
28 |
0
| return new FileInputStream(file);
|
29 |
| } |
30 |
| |
31 |
0
| public String getNiceFileName(boolean shortNames, String inputFileName) {
|
32 |
0
| return glomName(shortNames, inputFileName, file);
|
33 |
| } |
34 |
| |
35 |
0
| private String glomName(boolean shortNames, String inputFileName, File file) {
|
36 |
0
| if (shortNames && inputFileName.indexOf(',') == -1) {
|
37 |
0
| if ((new File(inputFileName)).isDirectory()) {
|
38 |
0
| return trimAnyPathSep(file.getAbsolutePath().substring(inputFileName.length()));
|
39 |
| } else { |
40 |
0
| if (inputFileName.indexOf(fileSeparator.charAt(0)) == -1) {
|
41 |
0
| return inputFileName;
|
42 |
| } |
43 |
0
| return trimAnyPathSep(inputFileName.substring(inputFileName.lastIndexOf(System.getProperty("file.separator"))));
|
44 |
| } |
45 |
| } |
46 |
| |
47 |
0
| return file.getAbsolutePath();
|
48 |
| } |
49 |
| |
50 |
0
| private String trimAnyPathSep(String name) {
|
51 |
| |
52 |
0
| return name.startsWith(fileSeparator) ?
|
53 |
| name.substring(1) : |
54 |
| name; |
55 |
| } |
56 |
| } |