Skip to content

Commit 62964ec

Browse files
committed
Simplified code
1 parent 0c05270 commit 62964ec

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/main/java/org/codehaus/plexus/util/BaseFileUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.nio.file.Files;
5+
import java.nio.file.OpenOption;
56
import java.nio.file.Path;
67
import java.nio.file.StandardOpenOption;
78

@@ -16,16 +17,14 @@ static String fileRead( Path path, String encoding ) throws IOException
1617
return encoding != null ? new String( bytes, encoding ) : new String( bytes );
1718
}
1819

19-
static void fileWrite( Path path, String encoding, String data ) throws IOException
20+
static void fileWrite( Path path, String encoding, String data, OpenOption... openOptions ) throws IOException
2021
{
2122
byte[] bytes = encoding != null ? data.getBytes( encoding ) : data.getBytes();
22-
Files.write( path, bytes );
23+
Files.write( path, bytes, openOptions );
2324
}
2425

2526
static void fileAppend( Path path, String encoding, String data ) throws IOException
2627
{
27-
byte[] bytes = encoding != null ? data.getBytes( encoding ) : data.getBytes();
28-
Files.write( path, bytes, StandardOpenOption.APPEND, StandardOpenOption.CREATE );
28+
fileWrite( path, encoding, data, StandardOpenOption.APPEND, StandardOpenOption.CREATE );
2929
}
30-
3130
}

src/main/java11/org/codehaus/plexus/util/BaseFileUtils.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.nio.charset.Charset;
55
import java.nio.file.Files;
6+
import java.nio.file.OpenOption;
67
import java.nio.file.Path;
78
import java.nio.file.StandardOpenOption;
89

@@ -16,28 +17,20 @@ static String fileRead( Path path, String encoding ) throws IOException
1617
return encoding != null ? Files.readString( path, Charset.forName( encoding ) ) : Files.readString( path );
1718
}
1819

19-
static void fileWrite( Path path, String encoding, String data ) throws IOException
20+
static void fileWrite( Path path, String encoding, String data, OpenOption... openOptions ) throws IOException
2021
{
2122
if ( encoding != null )
2223
{
23-
Files.writeString( path, data, Charset.forName( encoding ) );
24+
Files.writeString( path, data, Charset.forName( encoding ), openOptions );
2425
}
2526
else
2627
{
27-
Files.writeString( path, data );
28+
Files.writeString( path, data, openOptions );
2829
}
2930
}
3031

3132
static void fileAppend( Path path, String encoding, String data ) throws IOException
3233
{
33-
if ( encoding != null )
34-
{
35-
Files.writeString( path, data, Charset.forName( encoding ),
36-
StandardOpenOption.APPEND, StandardOpenOption.CREATE );
37-
}
38-
else
39-
{
40-
Files.writeString( path, data,StandardOpenOption.APPEND, StandardOpenOption.CREATE );
41-
}
34+
fileWrite( path, encoding, data, StandardOpenOption.APPEND, StandardOpenOption.CREATE );
4235
}
4336
}

0 commit comments

Comments
 (0)