You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/10/17 11:17:51 UTC

svn commit: r705524 - /maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/util/FileUtils.java

Author: bentmann
Date: Fri Oct 17 02:17:50 2008
New Revision: 705524

URL: http://svn.apache.org/viewvc?rev=705524&view=rev
Log:
o Copied FileUtils.fileRead(file, encoding) over from plexus-utils to ease stabilization of ITs

Modified:
    maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/util/FileUtils.java

Modified: maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/util/FileUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/util/FileUtils.java?rev=705524&r1=705523&r2=705524&view=diff
==============================================================================
--- maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/util/FileUtils.java (original)
+++ maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/util/FileUtils.java Fri Oct 17 02:17:50 2008
@@ -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 );
+            if ( encoding != null && encoding.length() > 0 )
+            {
+                reader = new InputStreamReader( new FileInputStream( file ), encoding );
+            }
+            else
+            {
+                reader = new InputStreamReader( new FileInputStream( file ) );
+            }
             int count;
-            byte[] b = new byte[512];
-            while ( ( count = in.read( b ) ) > 0 )  // blocking read
+            char[] b = new char[512];
+            while ( ( count = reader.read( b ) ) > 0 ) // blocking read
             {
-                buf.append( new String( b, 0, count ) );
+                buf.append( b, 0, count );
             }
         }
         finally
         {
-            IOUtil.close( in );
+            IOUtil.close( reader );
         }
 
         return buf.toString();