Skip to content

Commit

Permalink
Simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg committed Jan 21, 2023
1 parent 0c05270 commit 62964ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/codehaus/plexus/util/BaseFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

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

static void fileWrite( Path path, String encoding, String data ) throws IOException
static void fileWrite( Path path, String encoding, String data, OpenOption... openOptions ) throws IOException
{
byte[] bytes = encoding != null ? data.getBytes( encoding ) : data.getBytes();
Files.write( path, bytes );
Files.write( path, bytes, openOptions );
}

static void fileAppend( Path path, String encoding, String data ) throws IOException
{
byte[] bytes = encoding != null ? data.getBytes( encoding ) : data.getBytes();
Files.write( path, bytes, StandardOpenOption.APPEND, StandardOpenOption.CREATE );
fileWrite( path, encoding, data, StandardOpenOption.APPEND, StandardOpenOption.CREATE );
}

}
17 changes: 5 additions & 12 deletions src/main/java11/org/codehaus/plexus/util/BaseFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

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

static void fileWrite( Path path, String encoding, String data ) throws IOException
static void fileWrite( Path path, String encoding, String data, OpenOption... openOptions ) throws IOException
{
if ( encoding != null )
{
Files.writeString( path, data, Charset.forName( encoding ) );
Files.writeString( path, data, Charset.forName( encoding ), openOptions );
}
else
{
Files.writeString( path, data );
Files.writeString( path, data, openOptions );
}
}

static void fileAppend( Path path, String encoding, String data ) throws IOException
{
if ( encoding != null )
{
Files.writeString( path, data, Charset.forName( encoding ),
StandardOpenOption.APPEND, StandardOpenOption.CREATE );
}
else
{
Files.writeString( path, data,StandardOpenOption.APPEND, StandardOpenOption.CREATE );
}
fileWrite( path, encoding, data, StandardOpenOption.APPEND, StandardOpenOption.CREATE );
}
}

0 comments on commit 62964ec

Please sign in to comment.