From 4b85b44bbd501f6d9b5c5048616dfad7f8ae131d Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 20 Apr 2020 12:53:42 +0100 Subject: [PATCH] Update Javadoc of InputStreamResource#contentLength Closes gh-20990 --- .../org/springframework/core/io/AbstractResource.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java index b8fa7acc91..de327d7e1c 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -150,9 +150,11 @@ public abstract class AbstractResource implements Resource { } /** - * This implementation reads the entire InputStream to calculate the - * content length. Subclasses will almost always be able to provide - * a more optimal version of this, e.g. checking a File length. + * This method reads the entire InputStream to determine the content length. + *

For a custom sub-class of {@code InputStreamResource}, we strongly + * recommend overriding this method with a more optimal implementation, e.g. + * checking File length, or possibly simply returning -1 if the stream can + * only be read once. * @see #getInputStream() */ @Override