7
7
import java .io .BufferedReader ;
8
8
import java .io .Closeable ;
9
9
import java .io .File ;
10
- import java .io .FileWriter ;
10
+ import java .io .FileOutputStream ;
11
11
import java .io .IOException ;
12
12
import java .io .InputStream ;
13
13
import java .io .InputStreamReader ;
14
- import java .io .PrintWriter ;
14
+ import java .io .OutputStreamWriter ;
15
+ import java .nio .charset .StandardCharsets ;
15
16
import java .util .Collection ;
16
17
import java .util .LinkedList ;
17
18
import java .util .List ;
24
25
public final class IOUtil {
25
26
26
27
/**
27
- * Writes text to file
28
+ * Writes text to file in UTF-8.
28
29
*/
29
30
public static void writeText (String text , File output ) {
30
- PrintWriter pw = null ;
31
+ OutputStreamWriter pw = null ;
31
32
try {
32
- pw = new PrintWriter (new FileWriter (output ));
33
+ pw = new OutputStreamWriter (new FileOutputStream (output ), StandardCharsets . UTF_8 );
33
34
pw .write (text );
34
35
} catch (Exception e ) {
35
36
throw new MockitoException ("Problems writing text to file: " + output , e );
@@ -38,9 +39,12 @@ public static void writeText(String text, File output) {
38
39
}
39
40
}
40
41
42
+ /**
43
+ * Reads all lines from the given stream. Uses UTF-8.
44
+ */
41
45
public static Collection <String > readLines (InputStream is ) {
42
46
List <String > out = new LinkedList <>();
43
- BufferedReader r = new BufferedReader (new InputStreamReader (is ));
47
+ BufferedReader r = new BufferedReader (new InputStreamReader (is , StandardCharsets . UTF_8 ));
44
48
String line ;
45
49
try {
46
50
while ((line = r .readLine ()) != null ) {
0 commit comments