@@ -215,43 +215,31 @@ public ContentCachingInputStream(ServletInputStream is) {
215215
216216		@ Override 
217217		public  int  readLine (final  byte [] b , final  int  off , final  int  len ) throws  IOException  {
218- 			int  count  = super .readLine (b , off , len );
219- 			if  (!this .overflow  && count  > 0 ) {
220- 				if  (contentCacheLimit  != null  && cachedContent .size () == contentCacheLimit ) {
218+ 			int  count  = is .readLine (b , off , len );
219+ 			cache (b , off , count );
220+ 			return  count ;
221+ 		}
222+ 
223+ 		private  void  cache (final  byte [] b , final  int  off , final  int  count ) {
224+ 			if  (contentCacheLimit  != null  && cachedContent .size () == contentCacheLimit ) {
225+ 				this .overflow  = true ;
226+ 				handleContentOverflow (contentCacheLimit );
227+ 			} else  {
228+ 				int  sizeToCache  = contentCacheLimit  == null  || count  + cachedContent .size () < contentCacheLimit 
229+ 						? count 
230+ 						: contentCacheLimit  - cachedContent .size ();
231+ 				cachedContent .write (b , off , sizeToCache );
232+ 				if  (sizeToCache  < count ) {
221233					this .overflow  = true ;
222234					handleContentOverflow (contentCacheLimit );
223- 				} else  {
224- 					int  sizeToCache  = contentCacheLimit  == null  || count  + cachedContent .size () < contentCacheLimit 
225- 							? count 
226- 							: contentCacheLimit  - cachedContent .size ();
227- 					cachedContent .write (b , 0 , sizeToCache );
228- 					if  (sizeToCache  < count ) {
229- 						this .overflow  = true ;
230- 						handleContentOverflow (contentCacheLimit );
231- 					}
232235				}
233236			}
234- 			return  count ;
235237		}
236238
237239		@ Override 
238240		public  int  read (final  byte [] b , final  int  off , final  int  len ) throws  IOException  {
239- 			int  count  = super .read (b , off , len );
240- 			if  (!this .overflow  && count  > 0 ) {
241- 				if  (contentCacheLimit  != null  && cachedContent .size () == contentCacheLimit ) {
242- 					this .overflow  = true ;
243- 					handleContentOverflow (contentCacheLimit );
244- 				} else  {
245- 					int  sizeToCache  = contentCacheLimit  == null  || count  + cachedContent .size () < contentCacheLimit 
246- 							? count 
247- 							: contentCacheLimit  - cachedContent .size ();
248- 					cachedContent .write (b , off , sizeToCache );
249- 					if  (sizeToCache  < count ) {
250- 						this .overflow  = true ;
251- 						handleContentOverflow (contentCacheLimit );
252- 					}
253- 				}
254- 			}
241+ 			int  count  = is .read (b , off , len );
242+ 			cache (b , off , count );
255243			return  count ;
256244		}
257245
0 commit comments