Merge branch '5.2.x'

This commit is contained in:
Juergen Hoeller
2020-09-18 19:14:57 +02:00
3 changed files with 32 additions and 37 deletions

View File

@@ -97,8 +97,6 @@ public abstract class StreamUtils {
/**
* Copy the contents of the given {@link ByteArrayOutputStream} into a {@link String}.
* <p>This is a more effective equivalent of {@code new String(baos.toByteArray(), charset)}.
* <p>As long as the {@code charset} is already available at the point of
* invocation, no exception is expected to be thrown by this method.
* @param baos the {@code ByteArrayOutputStream} to be copied into a String
* @param charset the {@link Charset} to use to decode the bytes
* @return the String that has been copied to (possibly empty)
@@ -108,10 +106,12 @@ public abstract class StreamUtils {
Assert.notNull(baos, "No ByteArrayOutputStream specified");
Assert.notNull(charset, "No Charset specified");
try {
// Can be replaced with toString(Charset) call in Java 10+
return baos.toString(charset.name());
}
catch (UnsupportedEncodingException ex) {
throw new RuntimeException("Failed to copy contents of ByteArrayOutputStream into a String", ex);
// Should never happen
throw new IllegalArgumentException("Invalid charset name: " + charset, ex);
}
}
@@ -262,6 +262,7 @@ public abstract class StreamUtils {
return new NonClosingOutputStream(out);
}
private static class NonClosingInputStream extends FilterInputStream {
public NonClosingInputStream(InputStream in) {