You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/02/06 13:03:00 UTC

[jira] [Comment Edited] (GROOVY-8467) IOGroovyMethods class readLine method works unexpected in

    [ https://issues.apache.org/jira/browse/GROOVY-8467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16353849#comment-16353849 ] 

Paul King edited comment on GROOVY-8467 at 2/6/18 1:02 PM:
-----------------------------------------------------------

Workaround: use readLines() or eachLine {{{ ... } }}(but they won't give you the same level of streaming capability) or a reader with mark supported. The comment on that method indicates that this is a known design limitation:
{code:java}
    /*
    * This method reads without a buffer.
    * It returns too many empty lines if \r\n combinations
    * are used. Nothing can be done because we can't push
    * back the character we have just read.
    */
    private static String readLineFromReaderWithoutMark(Reader input)
{code}


was (Author: paulk):
Workaround: use readLines() or eachLine{ ... } (but they won't give you the same level of streaming capability) or a reader with mark supported. The comment on that method indicates that this is a known design limitation:
{code}
    /*
    * This method reads without a buffer.
    * It returns too many empty lines if \r\n combinations
    * are used. Nothing can be done because we can't push
    * back the character we have just read.
    */
    private static String readLineFromReaderWithoutMark(Reader input)
{code}

> IOGroovyMethods class readLine method works unexpected in  
> -----------------------------------------------------------
>
>                 Key: GROOVY-8467
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8467
>             Project: Groovy
>          Issue Type: Bug
>         Environment: windows 7
>            Reporter: zhuxiaobing
>            Priority: Major
>         Attachments: Screenshot from 2018-02-05 13-30-03.png, groovy_test_linux.zip, groovy_test_win.zip
>
>
> i have a android aapt dump file
> i try to read the file use the code below:
>  
> {code:java}
> InputStreamReader inputReader = new InputStreamReader(dumpFile)
> String line = null
> while ((line = inputReader.readLine()) != null){
>     println(line)
> }
> {code}
> the dumpfile uses \r\n to start a new line, while the IOGroovyMethods
> readLineFromReaderWithoutMark method which called by readLine  method  is : 
> {code:java}
>  private static String readLineFromReaderWithoutMark(Reader input) throws IOException {
>     int c = input.read();
>     if(c == -1) {
>         return null;
>     } else {
>         StringBuilder line;
>         for(line = new StringBuilder(expectedLineLength); c != EOF && c != 10 && c != 13; c = input.read()) {
>             char ch = (char)c;
>             line.append(ch);
>         }
>         return line.toString();
>     }
> }{code}
>  this casues an extra empty line read.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)