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
33 @Deprecated(since = "4.0.0")
34 public class FileSource implements Source {
35 private final Path path;
36
37 private final int hashCode;
38
39
40
41
42
43
44
45 @Deprecated
46 public FileSource(File file) {
47 this(Objects.requireNonNull(file, "file cannot be null").toPath());
48 }
49
50
51
52
53
54
55
56 public FileSource(Path path) {
57 this.path = Objects.requireNonNull(path, "path cannot be null").toAbsolutePath();
58 this.hashCode = Objects.hash(path);
59 }
60
61 @Override
62 public InputStream getInputStream() throws IOException {
63 return Files.newInputStream(path);
64 }
65
66 @Override
67 public String getLocation() {
68 return path.toString();
69 }
70
71
72
73
74
75
76
77 @Deprecated
78 public File getFile() {
79 return path.toFile();
80 }
81
82
83
84
85
86
87
88 public Path getPath() {
89 return path;
90 }
91
92 @Override
93 public String toString() {
94 return getLocation();
95 }
96
97 @Override
98 public int hashCode() {
99 return hashCode;
100 }
101
102 @Override
103 public boolean equals(Object obj) {
104 if (this == obj) {
105 return true;
106 }
107
108 if (obj == null) {
109 return false;
110 }
111
112 if (!FileSource.class.equals(obj.getClass())) {
113 return false;
114 }
115
116 FileSource other = (FileSource) obj;
117 return this.path.equals(other.path);
118 }
119 }