Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350453

Summary: Incorrect usage of InputStream.available in ReliableFile
Product: [Eclipse Project] Equinox Reporter: Thomas Watson <tjwatson>
Component: FrameworkAssignee: Thomas Watson <tjwatson>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.7   
Target Milestone: Juno M1   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
patch + test
none
updatec patch none

Description Thomas Watson CLA 2011-06-27 10:41:42 EDT
The implementation of ReliableFile assumes that InputStream.available returns the size of the input stream.  But this is clearly not the case.  I think we need to stop using the available method in this class altogether and simply use a BufferedInputStream to always get the mark support we need regardless of the size of the file.  Currently if the size of the file is "too big" the ReliableFile implementation will fail to read the contents correctly.
Comment 1 Thomas Watson CLA 2011-06-27 13:56:43 EDT
Created attachment 198670 [details]
patch + test

After more investigation the issue is that we use the available() method to incorrectly determine the size of the file and in the case where available() returns something bigger than our default maxInputStreamBuffer then we read the whole input stream to find the CRC and then try to continue to use that fully consumed input stream.  This patch fixes two issues:

1) it stops using available() to incorrectly determine the size of the file.  Instead we use File.length()

2) for files larger than maxInputStreamBuffer we correctly read the complete file to obtain the CRC and then close that fully consumed input stream and then open a new input stream to be consumed by the client of the API.  For smaller files < maxInputStreamBuffer we use a BufferedInputStream to correctly mark/reset after obtaining the CRC.
Comment 2 Thomas Watson CLA 2011-06-27 14:54:24 EDT
Created attachment 198676 [details]
updatec patch

Updated patch to make sure we don't try to use mark when the file length is longer than the integer max.
Comment 3 Thomas Watson CLA 2011-06-27 14:55:05 EDT
patch release.