16
16
*/
17
17
package org .apache .logging .log4j .core .util ;
18
18
19
- import static org .apache .logging .log4j .util .Strings .toRootUpperCase ;
20
-
21
19
import java .io .InterruptedIOException ;
22
20
import java .util .ArrayList ;
23
21
import java .util .List ;
@@ -40,23 +38,12 @@ public final class OptionConverter {
40
38
private static final char DELIM_STOP = '}' ;
41
39
private static final int DELIM_START_LEN = 2 ;
42
40
private static final int DELIM_STOP_LEN = 1 ;
43
- private static final int ONE_K = 1024 ;
44
41
45
42
/**
46
43
* OptionConverter is a static class.
47
44
*/
48
45
private OptionConverter () {}
49
46
50
- public static String [] concatenateArrays (final String [] l , final String [] r ) {
51
- final int len = l .length + r .length ;
52
- final String [] a = new String [len ];
53
-
54
- System .arraycopy (l , 0 , a , 0 , l .length );
55
- System .arraycopy (r , 0 , a , l .length , r .length );
56
-
57
- return a ;
58
- }
59
-
60
47
public static String convertSpecialChars (final String s ) {
61
48
char c ;
62
49
final int len = s .length ();
@@ -114,49 +101,6 @@ public static Object instantiateByKey(
114
101
return OptionConverter .instantiateByClassName (className .trim (), superClass , defaultValue );
115
102
}
116
103
117
- /**
118
- * If <code>value</code> is "true", then {@code true} is
119
- * returned. If <code>value</code> is "false", then
120
- * {@code false} is returned. Otherwise, <code>default</code> is
121
- * returned.
122
- *
123
- * <p>Case of value is unimportant.</p>
124
- * @param value The value to convert.
125
- * @param defaultValue The default value.
126
- * @return true or false, depending on the value and/or default.
127
- */
128
- public static boolean toBoolean (final String value , final boolean defaultValue ) {
129
- if (value == null ) {
130
- return defaultValue ;
131
- }
132
- final String trimmedVal = value .trim ();
133
- if ("true" .equalsIgnoreCase (trimmedVal )) {
134
- return true ;
135
- }
136
- if ("false" .equalsIgnoreCase (trimmedVal )) {
137
- return false ;
138
- }
139
- return defaultValue ;
140
- }
141
-
142
- /**
143
- * Convert the String value to an int.
144
- * @param value The value as a String.
145
- * @param defaultValue The default value.
146
- * @return The value as an int.
147
- */
148
- public static int toInt (final String value , final int defaultValue ) {
149
- if (value != null ) {
150
- final String s = value .trim ();
151
- try {
152
- return Integer .parseInt (s );
153
- } catch (final NumberFormatException e ) {
154
- LOGGER .error ("[{}] is not in proper int form." , s , e );
155
- }
156
- }
157
- return defaultValue ;
158
- }
159
-
160
104
public static Level toLevel (String value , Level defaultValue ) {
161
105
if (value == null ) {
162
106
return defaultValue ;
@@ -220,40 +164,6 @@ public static Level toLevel(String value, Level defaultValue) {
220
164
return result ;
221
165
}
222
166
223
- /**
224
- *
225
- * @param value The size of the file as a String.
226
- * @param defaultValue The default value.
227
- * @return The size of the file as a long.
228
- */
229
- public static long toFileSize (final String value , final long defaultValue ) {
230
- if (value == null ) {
231
- return defaultValue ;
232
- }
233
-
234
- String str = toRootUpperCase (value .trim ());
235
- long multiplier = 1 ;
236
- int index ;
237
-
238
- if ((index = str .indexOf ("KB" )) != -1 ) {
239
- multiplier = ONE_K ;
240
- str = str .substring (0 , index );
241
- } else if ((index = str .indexOf ("MB" )) != -1 ) {
242
- multiplier = ONE_K * ONE_K ;
243
- str = str .substring (0 , index );
244
- } else if ((index = str .indexOf ("GB" )) != -1 ) {
245
- multiplier = ONE_K * ONE_K * ONE_K ;
246
- str = str .substring (0 , index );
247
- }
248
- try {
249
- return Long .parseLong (str ) * multiplier ;
250
- } catch (final NumberFormatException e ) {
251
- LOGGER .error ("[{}] is not in proper int form." , str );
252
- LOGGER .error ("[{}] not in expected format." , value , e );
253
- }
254
- return defaultValue ;
255
- }
256
-
257
167
/**
258
168
* Find the value corresponding to <code>key</code> in
259
169
* <code>props</code>. Then perform variable substitution on the
@@ -380,7 +290,7 @@ private static String substVars(final String val, final Properties props, final
380
290
j += DELIM_START_LEN ;
381
291
final String key = val .substring (j , k );
382
292
// first try in System properties
383
- String replacement = PropertyEnvironment .getGlobal ().getStringProperty (key , null );
293
+ String replacement = PropertyEnvironment .getGlobal ().getProperty (key );
384
294
// then try props parameter
385
295
if (replacement == null && props != null ) {
386
296
replacement = props .getProperty (key );
0 commit comments