diff --git a/pom.xml b/pom.xml
index 1965e5ab..efad18f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@ limitations under the License.
org.codehaus.plexus
plexus
- 6.5
+ 7
plexus-utils
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index f18eac34..cac82ba3 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -60,8 +60,6 @@
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -70,6 +68,7 @@
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
@@ -2252,16 +2251,14 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[
{
if ( encoding == null || encoding.length() < 1 )
{
- fileReader = new BufferedReader( new FileReader( from ) );
- fileWriter = new FileWriter( to );
+ fileReader = Files.newBufferedReader( from.toPath() );
+ fileWriter = Files.newBufferedWriter( to.toPath() );
}
else
{
- InputStream instream = Files.newInputStream( from.toPath() );
-
OutputStream outstream = Files.newOutputStream( to.toPath() );
- fileReader = new BufferedReader( new InputStreamReader( instream, encoding ) );
+ fileReader = Files.newBufferedReader( from.toPath(), Charset.forName( encoding ) );
fileWriter = new OutputStreamWriter( outstream, encoding );
}
@@ -2311,7 +2308,7 @@ public static List loadFile( File file )
if ( file.exists() )
{
- try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) )
+ try ( BufferedReader reader = Files.newBufferedReader( file.toPath() ) )
{
for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
diff --git a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
index d593bbf0..a469a2c7 100644
--- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
+++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
@@ -18,7 +18,6 @@
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -154,13 +153,13 @@ public static Reader newPlatformReader( InputStream in )
*
* @param file not null file.
* @return a reader instance for the input file using the default platform charset.
- * @throws FileNotFoundException if any.
+ * @throws IOException if any.
* @see Charset#defaultCharset()
*/
public static Reader newPlatformReader( File file )
- throws FileNotFoundException
+ throws IOException
{
- return new FileReader( file );
+ return Files.newBufferedReader( file.toPath() );
}
/**
diff --git a/src/main/java/org/codehaus/plexus/util/WriterFactory.java b/src/main/java/org/codehaus/plexus/util/WriterFactory.java
index fce68943..cf8326c4 100644
--- a/src/main/java/org/codehaus/plexus/util/WriterFactory.java
+++ b/src/main/java/org/codehaus/plexus/util/WriterFactory.java
@@ -17,8 +17,6 @@
*/
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@@ -145,7 +143,7 @@ public static Writer newPlatformWriter( OutputStream out )
public static Writer newPlatformWriter( File file )
throws IOException
{
- return new FileWriter( file );
+ return Files.newBufferedWriter( file.toPath() );
}
/**
diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java
index 0bbd7b0e..40f2846c 100644
--- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java
+++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java
@@ -22,8 +22,6 @@
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -179,7 +177,7 @@ public void testInputStreamToWriter()
{
File destination = newFile( "copy2.txt" );
InputStream fin = Files.newInputStream( testFile.toPath() );
- FileWriter fout = new FileWriter( destination );
+ Writer fout = Files.newBufferedWriter( destination.toPath() );
IOUtil.copy( fin, fout );
@@ -210,7 +208,7 @@ public void testReaderToOutputStream()
throws Exception
{
File destination = newFile( "copy3.txt" );
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
OutputStream fout = Files.newOutputStream( destination.toPath() );
IOUtil.copy( fin, fout );
// Note: this method *does* flush. It is equivalent to:
@@ -232,8 +230,8 @@ public void testReaderToWriter()
throws Exception
{
File destination = newFile( "copy4.txt" );
- FileReader fin = new FileReader( testFile );
- FileWriter fout = new FileWriter( destination );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
+ Writer fout = Files.newBufferedWriter( destination.toPath() );
IOUtil.copy( fin, fout );
fout.flush();
@@ -248,7 +246,7 @@ public void testReaderToWriter()
public void testReaderToString()
throws Exception
{
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
String out = IOUtil.toString( fin );
assertNotNull( out );
assertTrue( "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE, out.length() == FILE_SIZE );
@@ -260,7 +258,7 @@ public void testStringToOutputStream()
throws Exception
{
File destination = newFile( "copy5.txt" );
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
// Create our String. Rely on testReaderToString() to make sure this is valid.
String str = IOUtil.toString( fin );
OutputStream fout = Files.newOutputStream( destination.toPath() );
@@ -284,10 +282,10 @@ public void testStringToWriter()
throws Exception
{
File destination = newFile( "copy6.txt" );
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
// Create our String. Rely on testReaderToString() to make sure this is valid.
String str = IOUtil.toString( fin );
- FileWriter fout = new FileWriter( destination );
+ Writer fout = Files.newBufferedWriter( destination.toPath() );
IOUtil.copy( str, fout );
fout.flush();
@@ -316,7 +314,7 @@ public void testInputStreamToByteArray()
public void testStringToByteArray()
throws Exception
{
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
// Create our String. Rely on testReaderToString() to make sure this is valid.
String str = IOUtil.toString( fin );
@@ -331,7 +329,7 @@ public void testByteArrayToWriter()
throws Exception
{
File destination = newFile( "copy7.txt" );
- FileWriter fout = new FileWriter( destination );
+ Writer fout = Files.newBufferedWriter( destination.toPath() );
InputStream fin = Files.newInputStream( testFile.toPath() );
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
index 28ec8297..97073d60 100644
--- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
+++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
@@ -21,9 +21,10 @@
import static org.junit.Assert.fail;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.Os;
@@ -443,10 +444,10 @@ public void testDollarSignInArgumentPath()
assertTrue( "Can't create dir:" + dir.getAbsolutePath(), dir.mkdirs() );
}
- FileWriter writer = null;
+ Writer writer = null;
try
{
- writer = new FileWriter( new File( dir, "test$1.txt" ) );
+ writer = Files.newBufferedWriter( dir.toPath().resolve( "test$1.txt" ) );
IOUtil.copy( "Success", writer );
}
finally
@@ -568,7 +569,7 @@ private static void createAndCallScript( File dir, String content )
bat = new File( dir, "echo" );
}
- Writer w = new FileWriter( bat );
+ Writer w = Files.newBufferedWriter( bat.toPath() );
try
{
IOUtil.copy( content, w );