Read the entire #reader() into a String, for convenience. @throws IOException When something goes wrong creating a reader from this source.
()
| 437 | * source. |
| 438 | */ |
| 439 | @NotNull |
| 440 | public final String readString() throws IOException { |
| 441 | |
| 442 | // [#18817] Skip the allocations if we already have a string. |
| 443 | if (string != null && !resolve) |
| 444 | return string; |
| 445 | |
| 446 | StringWriter w = new StringWriter(); |
| 447 | Reader r = null; |
| 448 | |
| 449 | try { |
| 450 | r = reader(); |
| 451 | char[] buffer = new char[8192]; |
| 452 | int read; |
| 453 | while ((read = r.read(buffer, 0, 8192)) >= 0) |
| 454 | w.write(buffer, 0, read); |
| 455 | } |
| 456 | catch (java.io.IOException e) { |
| 457 | throw new IOException("Could not read source", e); |
| 458 | } |
| 459 | finally { |
| 460 | safeClose(r); |
| 461 | } |
| 462 | |
| 463 | return w.toString(); |
| 464 | } |
| 465 | |
| 466 | private final Reader inputStreamReader(InputStream is) throws UnsupportedEncodingException { |
| 467 | if (charsetName != null) |
no test coverage detected