File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed 
spring-web/src/main/java/org/springframework/http/converter Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 11/* 
2-  * Copyright 2002-2013  the original author or authors. 
2+  * Copyright 2002-2014  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
1818
1919import  java .io .IOException ;
2020import  java .io .InputStream ;
21- 
2221import  javax .activation .FileTypeMap ;
2322import  javax .activation .MimetypesFileTypeMap ;
2423
2524import  org .springframework .core .io .ByteArrayResource ;
2625import  org .springframework .core .io .ClassPathResource ;
26+ import  org .springframework .core .io .InputStreamResource ;
2727import  org .springframework .core .io .Resource ;
2828import  org .springframework .http .HttpInputMessage ;
2929import  org .springframework .http .HttpOutputMessage ;
@@ -78,7 +78,9 @@ protected MediaType getDefaultContentType(Resource resource) {
7878
7979	@ Override 
8080	protected  Long  getContentLength (Resource  resource , MediaType  contentType ) throws  IOException  {
81- 		return  resource .contentLength ();
81+ 		// Don't try to determine contentLength on InputStreamResource - cannot be read afterwards... 
82+ 		// Note: custom InputStreamResource subclasses could provide a pre-calculated content length! 
83+ 		return  (InputStreamResource .class .equals (resource .getClass ()) ? null  : resource .contentLength ());
8284	}
8385
8486	@ Override 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments