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