Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0
-
None
-
None
-
Operating System: Linux
Platform: PC
-
33336
Description
In all read methods there is code like this:
int found = super.read(b);
this.count += found;
return found;
or like this:
this.count++;
return super.read();
It is ok until we will reach EOF. In this case super.read() returns -1, and
decreases count in the first case, and increases in the second. In such case
count should not be changed. So when we have something like this:
File file = new File("somefile.txt") //File with text "123" and no newlines
CountingInputStream cis = new CountingInputStream(new FileInputStream (file));
BufferedReader reader = new BufferedReader(new InputStreamReader(cis));
while(reader.read() != -1) {}
After this code when we call cis.getCount() it will return 2, while number of
bytes in read file is 3.