1818
1919import java .net .URL ;
2020import java .security .CodeSource ;
21- import org . apache . logging . log4j . util .Lazy ;
21+ import java . util .function . Consumer ;
2222
2323/**
2424 * Resource information (i.e., the enclosing JAR file and its version) of a class.
@@ -27,32 +27,35 @@ final class ClassResourceInfo {
2727
2828 static final ClassResourceInfo UNKNOWN = new ClassResourceInfo ();
2929
30- private final Lazy < String > textRef ;
30+ private final Consumer < StringBuilder > consumer ;
3131
3232 final Class <?> clazz ;
3333
3434 /**
3535 * Constructs an instance modelling an unknown class resource.
3636 */
3737 private ClassResourceInfo () {
38- this .textRef = Lazy . value ("~[?:?]" );
39- this . clazz = null ;
38+ this .consumer = ( buffer ) -> buffer . append ("~[?:?]" );
39+ clazz = null ;
4040 }
4141
4242 /**
4343 * @param clazz the class
4444 * @param exact {@code true}, if the class was obtained via reflection; {@code false}, otherwise
4545 */
4646 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 ) {
5247 final String exactnessPrefix = exact ? "" : "~" ;
5348 final String location = getLocation (clazz );
5449 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 ;
5659 }
5760
5861 private static String getLocation (final Class <?> clazz ) {
@@ -86,8 +89,7 @@ private static String getVersion(final Class<?> clazz) {
8689 return "?" ;
8790 }
8891
89- @ Override
90- public String toString () {
91- return textRef .get ();
92+ public void render (final StringBuilder buffer ) {
93+ this .consumer .accept (buffer );
9294 }
9395}
0 commit comments