1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.maven.shared.tools.easymock; |
20 | |
|
21 | |
import java.io.BufferedReader; |
22 | |
import java.io.File; |
23 | |
import java.io.FileReader; |
24 | |
import java.io.FileWriter; |
25 | |
import java.io.IOException; |
26 | |
import java.io.PrintWriter; |
27 | |
import java.io.StringWriter; |
28 | |
|
29 | |
import org.codehaus.plexus.util.IOUtil; |
30 | |
|
31 | |
public final class TestUtils |
32 | |
{ |
33 | |
|
34 | |
private TestUtils() |
35 | 0 | { |
36 | 0 | } |
37 | |
|
38 | |
public static void writeToFile( File file, String testStr ) |
39 | |
throws IOException |
40 | |
{ |
41 | 0 | FileWriter fw = null; |
42 | |
try |
43 | |
{ |
44 | 0 | fw = new FileWriter( file ); |
45 | 0 | fw.write( testStr ); |
46 | |
} |
47 | |
finally |
48 | |
{ |
49 | 0 | IOUtil.close( fw ); |
50 | 0 | } |
51 | 0 | } |
52 | |
|
53 | |
public static String readFile( File file ) |
54 | |
throws IOException |
55 | |
{ |
56 | 0 | StringBuffer buffer = new StringBuffer(); |
57 | |
|
58 | 0 | BufferedReader reader = new BufferedReader( new FileReader( file ) ); |
59 | |
|
60 | 0 | String line = null; |
61 | |
|
62 | 0 | while ( ( line = reader.readLine() ) != null ) |
63 | |
{ |
64 | 0 | if ( buffer.length() > 0 ) |
65 | |
{ |
66 | 0 | buffer.append( '\n' ); |
67 | |
} |
68 | |
|
69 | 0 | buffer.append( line ); |
70 | |
} |
71 | |
|
72 | 0 | return buffer.toString(); |
73 | |
} |
74 | |
|
75 | |
public static String toString( Throwable error ) |
76 | |
{ |
77 | 0 | StringWriter sw = new StringWriter(); |
78 | 0 | PrintWriter pw = new PrintWriter( sw ); |
79 | |
|
80 | 0 | error.printStackTrace( pw ); |
81 | |
|
82 | 0 | return sw.toString(); |
83 | |
} |
84 | |
} |