You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/02/01 18:24:41 UTC

DO NOT REPLY [Bug 33336] New: - CountingInputStream.getCount() often returns invalid values.

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33336>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=33336

           Summary: CountingInputStream.getCount() often returns invalid
                    values.
           Product: Commons
           Version: 1.0 Final
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: IO
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: pawelstawicki@poczta.onet.pl


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.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org