diff --git a/spring-core/src/main/java/org/springframework/util/StreamUtils.java b/spring-core/src/main/java/org/springframework/util/StreamUtils.java index 354e7b2cf2..36fd4de5ad 100644 --- a/spring-core/src/main/java/org/springframework/util/StreamUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StreamUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,14 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.nio.charset.Charset; -import org.springframework.lang.Contract; import org.springframework.lang.Nullable; /** - * Simple utility methods for dealing with streams. The copy methods of this class are - * similar to those defined in {@link FileCopyUtils} except that all affected streams are - * left open when done. All copy methods use a block size of 8192 bytes. + * Simple utility methods for dealing with streams. + * + *
The copy methods of this class are similar to those defined in + * {@link FileCopyUtils} except that all affected streams are left open when done. + * All copy methods use a block size of {@value #BUFFER_SIZE} bytes. * *
Mainly for use within the framework, but also useful for application code. * @@ -190,14 +191,14 @@ public abstract class StreamUtils { } /** - * Drain the remaining content of the given InputStream. - *
Leaves the InputStream open when done. - * @param in the InputStream to drain - * @return the number of bytes read + * Drain the remaining content of the given {@link InputStream}. + *
Leaves the {@code InputStream} open when done. + * @param in the {@code InputStream} to drain + * @return the number of bytes read, or {@code 0} if the supplied + * {@code InputStream} is {@code null} or empty * @throws IOException in case of I/O errors * @since 4.3 */ - @Contract("null -> fail") public static int drain(@Nullable InputStream in) throws IOException { if (in == null) { return 0;