18
18
19
19
import java .io .BufferedReader ;
20
20
import java .io .File ;
21
- import java .io .FileInputStream ;
22
21
import java .io .FileNotFoundException ;
23
- import java .io .FilenameFilter ;
24
22
import java .io .IOException ;
25
23
import java .io .InputStream ;
26
24
import java .io .InputStreamReader ;
27
25
import java .net .MalformedURLException ;
28
26
import java .net .URL ;
27
+ import java .nio .charset .StandardCharsets ;
28
+ import java .nio .file .Files ;
29
+ import java .nio .file .Paths ;
29
30
import java .util .Properties ;
30
31
31
32
import org .codehaus .plexus .classworlds .realm .DuplicateRealmException ;
@@ -76,9 +77,9 @@ public ConfigurationParser( ConfigurationHandler handler, Properties systemPrope
76
77
public void parse ( InputStream is )
77
78
throws IOException , ConfigurationException , DuplicateRealmException , NoSuchRealmException
78
79
{
79
- BufferedReader reader = new BufferedReader ( new InputStreamReader ( is , "UTF-8" ) );
80
+ BufferedReader reader = new BufferedReader ( new InputStreamReader ( is , StandardCharsets . UTF_8 ) );
80
81
81
- String line = null ;
82
+ String line ;
82
83
83
84
int lineNo = 0 ;
84
85
@@ -181,7 +182,7 @@ else if ( line.startsWith( SET_PREFIX ) )
181
182
182
183
try
183
184
{
184
- properties .load ( new FileInputStream ( propertiesFileName ) );
185
+ properties .load ( Files . newInputStream ( Paths . get ( propertiesFileName ) ) );
185
186
186
187
value = properties .getProperty ( property );
187
188
}
@@ -247,7 +248,7 @@ else if ( line.startsWith( LOAD_PREFIX ) )
247
248
248
249
constituent = filter ( constituent );
249
250
250
- if ( constituent .indexOf ( "*" ) >= 0 )
251
+ if ( constituent .contains ( "*" ) )
251
252
{
252
253
loadGlob ( constituent , false /*not optionally*/ );
253
254
}
@@ -278,7 +279,7 @@ else if ( line.startsWith( OPTIONALLY_PREFIX ) )
278
279
279
280
constituent = filter ( constituent );
280
281
281
- if ( constituent .indexOf ( "*" ) >= 0 )
282
+ if ( constituent .contains ( "*" ) )
282
283
{
283
284
loadGlob ( constituent , true /*optionally*/ );
284
285
}
@@ -350,23 +351,18 @@ protected void loadGlob( String line,
350
351
351
352
final String suffix = localName .substring ( starLoc + 1 );
352
353
353
- File [] matches = dir .listFiles ( new FilenameFilter ()
354
- {
355
- public boolean accept ( File dir ,
356
- String name )
354
+ File [] matches = dir .listFiles ( ( dir1 , name ) -> {
355
+ if ( !name .startsWith ( prefix ) )
357
356
{
358
- if ( !name .startsWith ( prefix ) )
359
- {
360
- return false ;
361
- }
362
-
363
- if ( !name .endsWith ( suffix ) )
364
- {
365
- return false ;
366
- }
357
+ return false ;
358
+ }
367
359
368
- return true ;
360
+ if ( !name .endsWith ( suffix ) )
361
+ {
362
+ return false ;
369
363
}
364
+
365
+ return true ;
370
366
} );
371
367
372
368
for ( File match : matches )
@@ -386,16 +382,16 @@ public boolean accept( File dir,
386
382
protected String filter ( String text )
387
383
throws ConfigurationException
388
384
{
389
- String result = "" ;
385
+ StringBuilder result = new StringBuilder () ;
390
386
391
387
int cur = 0 ;
392
388
int textLen = text .length ();
393
389
394
- int propStart = - 1 ;
395
- int propStop = - 1 ;
390
+ int propStart ;
391
+ int propStop ;
396
392
397
- String propName = null ;
398
- String propValue = null ;
393
+ String propName ;
394
+ String propValue ;
399
395
400
396
while ( cur < textLen )
401
397
{
@@ -406,7 +402,7 @@ protected String filter( String text )
406
402
break ;
407
403
}
408
404
409
- result += text . substring ( cur , propStart );
405
+ result . append ( text , cur , propStart );
410
406
411
407
propStop = text .indexOf ( "}" , propStart );
412
408
@@ -430,14 +426,14 @@ protected String filter( String text )
430
426
{
431
427
throw new ConfigurationException ( "No such property: " + propName );
432
428
}
433
- result += propValue ;
429
+ result . append ( propValue ) ;
434
430
435
431
cur = propStop + 1 ;
436
432
}
437
433
438
- result += text .substring ( cur );
434
+ result . append ( text .substring ( cur ) );
439
435
440
- return result ;
436
+ return result . toString () ;
441
437
}
442
438
443
439
/**
0 commit comments