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