|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ReaderUtil.java | 100% | 100% | 100% | 100% |
|
1 |
package com.diasparsoftware.java.io;
|
|
2 |
|
|
3 |
import java.io.*;
|
|
4 |
|
|
5 |
public class ReaderUtil { |
|
6 |
/**
|
|
7 |
* Obtain a string representation of the content that
|
|
8 |
* a reader reads.
|
|
9 |
*
|
|
10 |
* @param reader
|
|
11 |
* @return
|
|
12 |
* @throws IOException Thrown if an underlying read operation
|
|
13 |
* fails.
|
|
14 |
*/
|
|
15 | 16 |
public static String getContentAsString(Reader reader) |
16 |
throws IOException {
|
|
17 | 16 |
BufferedReader bufferedReader = new BufferedReader(reader);
|
18 | 16 |
StringBuffer contentBuffer = new StringBuffer();
|
19 |
|
|
20 | 16 |
while (true) { |
21 | 56 |
int readResult = bufferedReader.read();
|
22 | 56 |
if (readResult == -1) {
|
23 | 16 |
break;
|
24 |
} |
|
25 |
|
|
26 | 40 |
contentBuffer.append((char) readResult);
|
27 |
} |
|
28 |
|
|
29 | 16 |
return contentBuffer.toString();
|
30 |
} |
|
31 |
} |
|
32 |
|
|