From c41544820537cc0ab39791f65baa1cb518a33879 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Wed, 11 Jan 2023 17:33:51 +0000 Subject: [PATCH] Using Files.write instead of OutputStream.write --- .../org/codehaus/plexus/util/FileUtils.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index 95b939e0..d7e61f83 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -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 ); } /**