1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.building;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.util.Objects;
27
28
29
30
31
32 public class FileSource implements Source {
33 private final Path path;
34
35 private final int hashCode;
36
37
38
39
40
41
42
43 @Deprecated
44 public FileSource(File file) {
45 this(Objects.requireNonNull(file, "file cannot be null").toPath());
46 }
47
48
49
50
51
52
53
54 public FileSource(Path path) {
55 this.path = Objects.requireNonNull(path, "path cannot be null").toAbsolutePath();
56 this.hashCode = Objects.hash(path);
57 }
58
59 @Override
60 public InputStream getInputStream() throws IOException {
61 return Files.newInputStream(path);
62 }
63
64 @Override
65 public String getLocation() {
66 return path.toString();
67 }
68
69
70
71
72
73
74
75 @Deprecated
76 public File getFile() {
77 return path.toFile();
78 }
79
80
81
82
83
84
85
86 public Path getPath() {
87 return path;
88 }
89
90 @Override
91 public String toString() {
92 return getLocation();
93 }
94
95 @Override
96 public int hashCode() {
97 return hashCode;
98 }
99
100 @Override
101 public boolean equals(Object obj) {
102 if (this == obj) {
103 return true;
104 }
105
106 if (obj == null) {
107 return false;
108 }
109
110 if (!FileSource.class.equals(obj.getClass())) {
111 return false;
112 }
113
114 FileSource other = (FileSource) obj;
115 return this.path.equals(other.path);
116 }
117 }