groovy

Can readLine from FileReader

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-3, 1.0-JSR-4, 1.0-JSR-5, 1.0-JSR-6, 1.0-RC-1, 1.0-RC-2, 1.0, 1.1-beta-1, 1.1-beta-2
  • Fix Version/s: 1.5.5, 1.5.6
  • Component/s: None
  • Labels:
    None
  • Environment:
    Win XP - j2sdk-1.4.2_08
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

The code below only read the first line of a file

fr = new FileReader('test2E2R.pr03')

String line1 = ""
while (line1 != null) {
  line1 = fr.readLine()
  println line1
}
fr.close()

Activity

Hide
Per Arneng added a comment -

I got the same problem.. only the first line.

groovy bug.groovy bug.groovy

ins = (new File(args[0])).newInputStream()

while(true) {
        line = ins.readLine()
        if(line == null) break
        println line

}
Show
Per Arneng added a comment - I got the same problem.. only the first line. groovy bug.groovy bug.groovy
ins = (new File(args[0])).newInputStream()

while(true) {
        line = ins.readLine()
        if(line == null) break
        println line

}
Hide
Per Arneng added a comment -

Addition to the above comment:
Groovy Version: 1.0 JVM: 1.6.0_01-b06 on ubuntu 7.0.4
Linux 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux
ubuntu 7.04

Show
Per Arneng added a comment - Addition to the above comment: Groovy Version: 1.0 JVM: 1.6.0_01-b06 on ubuntu 7.0.4 Linux 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux ubuntu 7.04
Hide
Joachim Baumann added a comment -

InputStream.readLine() is still broken, and we might remove it from 1.1.

Reader.readLine() should work with the current version in SVN.

Show
Joachim Baumann added a comment - InputStream.readLine() is still broken, and we might remove it from 1.1. Reader.readLine() should work with the current version in SVN.
Hide
Per Arneng added a comment -

> Reader.readLine() should work with the current version in SVN.

It seems like this method will only work as specified if the Reader is a BufferedReader or if mark is supported or if mark is not supported and the line endings are not 2 chars. In short: There are cases that will cause the readLine to behave strange.

A buffer, mark or look ahed is needed to handle \r\n i think so without that it is pretty hard to solve this problem. So the question is the if it is acceptable for the method to behave differently depending on if mark is supported or not.

To bad that there is not an interface called MarkSupported because then the readLine method could be attached to that interface

Show
Per Arneng added a comment - > Reader.readLine() should work with the current version in SVN. It seems like this method will only work as specified if the Reader is a BufferedReader or if mark is supported or if mark is not supported and the line endings are not 2 chars. In short: There are cases that will cause the readLine to behave strange. A buffer, mark or look ahed is needed to handle \r\n i think so without that it is pretty hard to solve this problem. So the question is the if it is acceptable for the method to behave differently depending on if mark is supported or not. To bad that there is not an interface called MarkSupported because then the readLine method could be attached to that interface
Hide
Paul King added a comment -

add code tags

Show
Paul King added a comment - add code tags
Hide
Paul King added a comment -

Hi Joachim, I think this is as fixed as we are planning to do right now. Should we close this?

Show
Paul King added a comment - Hi Joachim, I think this is as fixed as we are planning to do right now. Should we close this?
Hide
Paul King added a comment -

Some fixes are in place. Please reopen if you have any further issues.

Show
Paul King added a comment - Some fixes are in place. Please reopen if you have any further issues.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: