Skip to content

Commit 37ecdd1

Browse files
kilinkbclozel
authored andcommitted
Forward more methods to underlying InputStream in NonClosingInputStream
NonClosingInputStream extends FilterInputStream, which does not forward some newer InputStream methods such as transferTo and readAllBytes. Specific InputStream implementations may have more optimized methods (e.g., FileInputStream). Closes gh-34893 Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com>
1 parent 73f1c5a commit 37ecdd1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

spring-core/src/main/java/org/springframework/util/StreamUtils.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public static OutputStream nonClosing(OutputStream out) {
239239
}
240240

241241

242-
private static class NonClosingInputStream extends FilterInputStream {
242+
private static final class NonClosingInputStream extends FilterInputStream {
243243

244244
public NonClosingInputStream(InputStream in) {
245245
super(in);
@@ -248,10 +248,30 @@ public NonClosingInputStream(InputStream in) {
248248
@Override
249249
public void close() throws IOException {
250250
}
251+
252+
@Override
253+
public byte[] readAllBytes() throws IOException {
254+
return in.readAllBytes();
255+
}
256+
257+
@Override
258+
public byte[] readNBytes(int len) throws IOException {
259+
return in.readNBytes(len);
260+
}
261+
262+
@Override
263+
public int readNBytes(byte[] b, int off, int len) throws IOException {
264+
return in.readNBytes(b, off, len);
265+
}
266+
267+
@Override
268+
public long transferTo(OutputStream out) throws IOException {
269+
return in.transferTo(out);
270+
}
251271
}
252272

253273

254-
private static class NonClosingOutputStream extends FilterOutputStream {
274+
private static final class NonClosingOutputStream extends FilterOutputStream {
255275

256276
public NonClosingOutputStream(OutputStream out) {
257277
super(out);

0 commit comments

Comments
 (0)