21
21
22
22
import java .util .HashMap ;
23
23
import java .util .Map ;
24
+ import java .util .Optional ;
24
25
import java .util .stream .Collectors ;
25
26
import java .util .stream .Stream ;
26
27
@@ -58,26 +59,25 @@ public String getMessage() {
58
59
}
59
60
60
61
private String createMessage (String originalMessageString ) {
61
- String supportMessage = getSupportUrl () == null ?
62
- "" : "For documentation on this error, please visit: " + getSupportUrl ();
62
+ String supportMessage = Optional .ofNullable (getSupportUrl ())
63
+ .map (url -> String .format ("For documentation on this error, please visit: %s" , url ))
64
+ .orElse ("" );
63
65
64
66
return Stream .of (
65
- originalMessageString == null ? "" : originalMessageString ,
66
- supportMessage ,
67
- getBuildInformation ().toString (),
68
- getSystemInformation (),
69
- getAdditionalInformation ()
67
+ originalMessageString == null ? "" : originalMessageString ,
68
+ supportMessage ,
69
+ getBuildInformation ().toString (),
70
+ getSystemInformation (),
71
+ getAdditionalInformation ()
70
72
).filter (s -> !(s == null || s .equals ("" ))).collect (Collectors .joining ("\n " ));
71
73
}
72
74
73
75
public String getSystemInformation () {
74
- return String .format ("System info: host: '%s', ip: '%s', os.name: '%s', os.arch: '%s', os.version: '%s', java.version: '%s'" ,
75
- HOST_NAME ,
76
- HOST_ADDRESS ,
77
- System .getProperty ("os.name" ),
78
- System .getProperty ("os.arch" ),
79
- System .getProperty ("os.version" ),
80
- System .getProperty ("java.version" ));
76
+ return String .format (
77
+ "System info: host: '%s', ip: '%s', os.name: '%s', os.arch: '%s', os.version: '%s', java.version: '%s'" ,
78
+ HOST_NAME , HOST_ADDRESS ,
79
+ System .getProperty ("os.name" ), System .getProperty ("os.arch" ),
80
+ System .getProperty ("os.version" ), System .getProperty ("java.version" ));
81
81
}
82
82
83
83
public String getSupportUrl () {
@@ -90,13 +90,13 @@ public BuildInfo getBuildInformation() {
90
90
91
91
public static String getDriverName (StackTraceElement [] stackTraceElements ) {
92
92
return Stream .of (stackTraceElements )
93
- .filter (e -> e .getClassName ().endsWith ("Driver" ))
94
- .map (e -> {
95
- String [] bits = e .getClassName ().split ("\\ ." );
96
- return bits [bits .length - 1 ];
97
- })
98
- .reduce ((first , last ) -> last )
99
- .orElse ("unknown" );
93
+ .filter (e -> e .getClassName ().endsWith ("Driver" ))
94
+ .map (e -> {
95
+ String [] bits = e .getClassName ().split ("\\ ." );
96
+ return bits [bits .length - 1 ];
97
+ })
98
+ .reduce ((first , last ) -> last )
99
+ .orElse ("unknown" );
100
100
}
101
101
102
102
public void addInfo (String key , String value ) {
@@ -105,12 +105,12 @@ public void addInfo(String key, String value) {
105
105
106
106
public String getAdditionalInformation () {
107
107
extraInfo .computeIfAbsent (
108
- DRIVER_INFO , key -> "driver.version: " + getDriverName (getStackTrace ()));
108
+ DRIVER_INFO , key -> "driver.version: " + getDriverName (getStackTrace ()));
109
109
110
110
return extraInfo .entrySet ().stream ()
111
- .map (entry -> entry .getValue () != null && entry .getValue ().startsWith (entry .getKey ())
112
- ? entry .getValue ()
113
- : entry .getKey () + ": " + entry .getValue ())
114
- .collect (Collectors .joining ("\n " ));
111
+ .map (entry -> entry .getValue () != null && entry .getValue ().startsWith (entry .getKey ())
112
+ ? entry .getValue ()
113
+ : entry .getKey () + ": " + entry .getValue ())
114
+ .collect (Collectors .joining ("\n " ));
115
115
}
116
116
}
0 commit comments