1 package org.codehaus.mojo.fitnesse;
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }