18
18
19
19
import java .net .URL ;
20
20
import java .security .CodeSource ;
21
- import org . apache . logging . log4j . util .Lazy ;
21
+ import java . util .function . Consumer ;
22
22
23
23
/**
24
24
* Resource information (i.e., the enclosing JAR file and its version) of a class.
@@ -27,32 +27,35 @@ final class ClassResourceInfo {
27
27
28
28
static final ClassResourceInfo UNKNOWN = new ClassResourceInfo ();
29
29
30
- private final Lazy < String > textRef ;
30
+ private final Consumer < StringBuilder > consumer ;
31
31
32
32
final Class <?> clazz ;
33
33
34
34
/**
35
35
* Constructs an instance modelling an unknown class resource.
36
36
*/
37
37
private ClassResourceInfo () {
38
- this .textRef = Lazy . value ("~[?:?]" );
39
- this . clazz = null ;
38
+ this .consumer = ( buffer ) -> buffer . append ("~[?:?]" );
39
+ clazz = null ;
40
40
}
41
41
42
42
/**
43
43
* @param clazz the class
44
44
* @param exact {@code true}, if the class was obtained via reflection; {@code false}, otherwise
45
45
*/
46
46
ClassResourceInfo (final Class <?> clazz , final boolean exact ) {
47
- this .clazz = clazz ;
48
- this .textRef = Lazy .lazy (() -> getText (clazz , exact ));
49
- }
50
-
51
- private static String getText (final Class <?> clazz , final boolean exact ) {
52
47
final String exactnessPrefix = exact ? "" : "~" ;
53
48
final String location = getLocation (clazz );
54
49
final String version = getVersion (clazz );
55
- return String .format ("%s[%s:%s]" , exactnessPrefix , location , version );
50
+ this .consumer = (buffer ) -> {
51
+ buffer .append (exactnessPrefix );
52
+ buffer .append ("[" );
53
+ buffer .append (location );
54
+ buffer .append (":" );
55
+ buffer .append (version );
56
+ buffer .append ("]" );
57
+ };
58
+ this .clazz = clazz ;
56
59
}
57
60
58
61
private static String getLocation (final Class <?> clazz ) {
@@ -86,8 +89,7 @@ private static String getVersion(final Class<?> clazz) {
86
89
return "?" ;
87
90
}
88
91
89
- @ Override
90
- public String toString () {
91
- return textRef .get ();
92
+ public void render (final StringBuilder buffer ) {
93
+ this .consumer .accept (buffer );
92
94
}
93
95
}
0 commit comments