o Copied FileUtils.fileRead(file, encoding) over from plexus-utils to ease stabilization of ITs
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@705524 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/it/util/FileUtils.java b/src/main/java/org/apache/maven/it/util/FileUtils.java
index bebf4f5..4cf7f25 100644
--- a/src/main/java/org/apache/maven/it/util/FileUtils.java
+++ b/src/main/java/org/apache/maven/it/util/FileUtils.java
@@ -275,23 +275,36 @@
public static String fileRead( File file )
throws IOException
{
+ return fileRead( file, null );
+ }
+
+ public static String fileRead( File file, String encoding )
+ throws IOException
+ {
StringBuffer buf = new StringBuffer();
- FileInputStream in = null;
+ Reader reader = null;
try
{
- in = new FileInputStream( file );
- int count;
- byte[] b = new byte[512];
- while ( ( count = in.read( b ) ) > 0 ) // blocking read
+ if ( encoding != null && encoding.length() > 0 )
{
- buf.append( new String( b, 0, count ) );
+ reader = new InputStreamReader( new FileInputStream( file ), encoding );
+ }
+ else
+ {
+ reader = new InputStreamReader( new FileInputStream( file ) );
+ }
+ int count;
+ char[] b = new char[512];
+ while ( ( count = reader.read( b ) ) > 0 ) // blocking read
+ {
+ buf.append( b, 0, count );
}
}
finally
{
- IOUtil.close( in );
+ IOUtil.close( reader );
}
return buf.toString();