Skip to content

Commit

Permalink
Using Files.write instead of OutputStream.write
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg authored and michael-o committed Jan 14, 2023
1 parent b8696fb commit c415448
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/main/java/org/codehaus/plexus/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,14 @@ public static void fileWrite( File file, String data )
public static void fileWrite( File file, String encoding, String data )
throws IOException
{
try ( Writer writer = getOutputStreamWriter( file, encoding ) )
{
writer.write( data );
}
fileWrite( file.toPath(), encoding, data );
}

private static OutputStreamWriter getOutputStreamWriter( File file, String encoding ) throws IOException

private static void fileWrite( Path path, String encoding, String data )
throws IOException
{
OutputStream out = Files.newOutputStream( file.toPath() );
if ( encoding != null )
{
return new OutputStreamWriter( out, encoding );
}
else
{
return new OutputStreamWriter( out );
}
byte[] bytes = encoding != null ? data.getBytes( encoding ) : data.getBytes();
Files.write( path, bytes );
}

/**
Expand Down

0 comments on commit c415448

Please sign in to comment.