Skip to content

Commit 28a76a4

Browse files
committed
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). Signed-off-by: Patrick Strawderman <[email protected]>
1 parent 2a29e16 commit 28a76a4

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
@@ -240,7 +240,7 @@ public static OutputStream nonClosing(OutputStream out) {
240240
}
241241

242242

243-
private static class NonClosingInputStream extends FilterInputStream {
243+
private static final class NonClosingInputStream extends FilterInputStream {
244244

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

254274

255-
private static class NonClosingOutputStream extends FilterOutputStream {
275+
private static final class NonClosingOutputStream extends FilterOutputStream {
256276

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

0 commit comments

Comments
 (0)