commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 33336] New: - CountingInputStream.getCount() often returns invalid values.
Date Tue, 01 Feb 2005 17:24:41 GMT
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


Mime
View raw message