Use InputStream's contracts instead of StreamUtils
Since Spring Framework 6.0 requires Java 17, we can now use `InputStream` new contracts when manipulating streams. Closes gh-27702
This commit is contained in:
committed by
Brian Clozel
parent
0770d86936
commit
fa1f7f6dc7
@@ -108,12 +108,10 @@ public abstract class FileCopyUtils {
|
||||
Assert.notNull(in, "No InputStream specified");
|
||||
Assert.notNull(out, "No OutputStream specified");
|
||||
|
||||
try {
|
||||
return StreamUtils.copy(in, out);
|
||||
}
|
||||
finally {
|
||||
close(in);
|
||||
close(out);
|
||||
try (in; out) {
|
||||
int count = (int) in.transferTo(out);
|
||||
out.flush();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,9 +64,7 @@ public abstract class StreamUtils {
|
||||
return EMPTY_CONTENT;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
|
||||
copy(in, out);
|
||||
return out.toByteArray();
|
||||
return in.readAllBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,15 +150,9 @@ public abstract class StreamUtils {
|
||||
Assert.notNull(in, "No InputStream specified");
|
||||
Assert.notNull(out, "No OutputStream specified");
|
||||
|
||||
int byteCount = 0;
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
byteCount += bytesRead;
|
||||
}
|
||||
int count = (int) in.transferTo(out);
|
||||
out.flush();
|
||||
return byteCount;
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user