View Javadoc

1   package org.codehaus.mojo.fitnesse;
2   
3   /*
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, version 2.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU General Public License for more details.
12   *
13   * You should have received a copy of the GNU General Public License
14   * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
15   */
16  
17  import java.io.File;
18  import java.io.FileInputStream;
19  import java.io.IOException;
20  import java.io.InputStream;
21  
22  public final class FileUtil
23  {
24  
25      private FileUtil()
26      {
27          super();
28      }
29  
30      public static String getString( File pIn )
31          throws IOException
32      {
33  
34          FileInputStream tFileInputStream = null;
35          try
36          {
37              tFileInputStream = new FileInputStream( pIn );
38              String tResult = getString( tFileInputStream );
39              return tResult;
40          }
41          finally
42          {
43              if ( tFileInputStream != null )
44              {
45                  tFileInputStream.close();
46              }
47          }
48      }
49  
50      public static String getString( InputStream pIn )
51          throws IOException
52      {
53          StringBuffer tBuf = new StringBuffer();
54          byte[] tbytes = new byte[512];
55          int tReadBytes = pIn.read( tbytes );
56          while ( tReadBytes >= 0 )
57          {
58              tBuf.append( new String( tbytes, 0, tReadBytes, "UTF-8" ) );
59              tReadBytes = pIn.read( tbytes );
60          }
61          return tBuf.toString();
62      }
63  
64  }