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.ByteArrayInputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.nio.charset.StandardCharsets;
25
26
27
28
29
30
31 @Deprecated(since = "4.0.0")
32 public class StringSource implements Source {
33 private final String content;
34
35 private final String location;
36
37 private final int hashCode;
38
39
40
41
42
43
44 public StringSource(CharSequence content) {
45 this(content, null);
46 }
47
48
49
50
51
52
53
54 public StringSource(CharSequence content, String location) {
55 this.content = (content != null) ? content.toString() : "";
56 this.location = (location != null) ? location : "(memory)";
57 this.hashCode = this.content.hashCode();
58 }
59
60 @Override
61 public InputStream getInputStream() throws IOException {
62 return new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
63 }
64
65 @Override
66 public String getLocation() {
67 return location;
68 }
69
70
71
72
73
74
75 public String getContent() {
76 return content;
77 }
78
79 @Override
80 public String toString() {
81 return getLocation();
82 }
83
84 @Override
85 public int hashCode() {
86 return hashCode;
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94
95 if (obj == null) {
96 return false;
97 }
98
99 if (!StringSource.class.equals(obj.getClass())) {
100 return false;
101 }
102
103 StringSource other = (StringSource) obj;
104 return this.content.equals(other.content);
105 }
106 }