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