Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IOUtils |
|
| 3.0;3 |
1 | package org.jbehave.core.io; | |
2 | ||
3 | import java.io.IOException; | |
4 | import java.io.InputStream; | |
5 | import java.io.Reader; | |
6 | ||
7 | /** | |
8 | * A collection of utility methods performing I/O operations, | |
9 | * complementing IOUtils methods provided by other libraries. | |
10 | */ | |
11 | 0 | public class IOUtils { |
12 | ||
13 | /** | |
14 | * Returns the content of the InputStream as a String, closing the stream afterwards if configured. | |
15 | * | |
16 | * @param input the InputStream | |
17 | * @param close the boolean to close the input afterwards | |
18 | * @return A String with the content | |
19 | * @throws IOException | |
20 | * @see {@link org.apache.commons.io.IOUtils.toString(InputStream)} | |
21 | */ | |
22 | public static String toString(InputStream input, boolean close) throws IOException { | |
23 | try { | |
24 | 21 | return org.apache.commons.io.IOUtils.toString(input, "UTF-8"); |
25 | } | |
26 | finally { | |
27 | 21 | if ( close ) { |
28 | 19 | input.close(); |
29 | } | |
30 | } | |
31 | } | |
32 | ||
33 | /** | |
34 | * Returns the content of the Reader as a String, closing the stream afterwards if configured. | |
35 | * | |
36 | * @param input the Reader | |
37 | * @param close the boolean to close the input afterwards | |
38 | * @return A String with the content | |
39 | * @throws IOException | |
40 | * @see {@link org.apache.commons.io.IOUtils.toString(Reader)} | |
41 | */ | |
42 | public static String toString(Reader input, boolean close) throws IOException { | |
43 | try { | |
44 | 58 | return org.apache.commons.io.IOUtils.toString(input); |
45 | } | |
46 | finally { | |
47 | 58 | if ( close ) { |
48 | 56 | input.close(); |
49 | } | |
50 | } | |
51 | } | |
52 | ||
53 | } |