harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-6590) [classlib][luni]A issue about CharsetEncoder.flush() in the OutputStreamWriter.close()
Date Fri, 23 Jul 2010 13:08:49 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-6590?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12891580#action_12891580
] 

Tim Ellison commented on HARMONY-6590:
--------------------------------------

So I think this issue has been resolved by the fix to CharsetEncoder.

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;

public class OSWTest {

    static class MyCharsetEncoder extends CharsetEncoder {

        protected MyCharsetEncoder(Charset cs, float averageBytesPerChar,
                float maxBytesPerChar) {
            super(cs, averageBytesPerChar, maxBytesPerChar);
        }

        public MyCharsetEncoder() {
            this(Charset.forName("UTF-8"), 2.0f, 4.0f);
        }

        @Override
        protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
            int l = in.length();
            for (int i = 0; i < l; i++) {
                out.putChar(in.get());
            }
            return CoderResult.UNDERFLOW;
        }
        
        @Override
        protected CoderResult implFlush(ByteBuffer out) {
            System.out.println("Feeling flushed");
            return CoderResult.UNDERFLOW;
        }

    }

    public static void main(String[] args) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(bos, new MyCharsetEncoder());
        osw.flush();
        osw.write("Hello Harmony!");
        osw.flush();
        osw.close();
        System.out.println(bos.toString());
    }

}


> [classlib][luni]A issue about CharsetEncoder.flush() in the OutputStreamWriter.close()
> --------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6590
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6590
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M14
>            Reporter: deven you
>            Assignee: Tim Ellison
>         Attachments: HARMONY-6590.diff
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> Today I read through the OutputStreamWrtier.close() code below:
>     public void close() throws IOException {
>         synchronized (lock) {
>             if (encoder != null) {
>                 encoder.flush(bytes);
>                 flush();
>                 out.flush();
>                 out.close();
>                 encoder = null;
>                 bytes = null;
>             }
>         }
>     } 
> I remember the java spec says for the CharsetEncoder.flush(): IllegalStateException -
If the previous step of the current encoding operation was an invocation neither of the reset
method nor of the three-argument encode method with a value of true for the endOfInput parameter.
> Obviously OutputStreamWrtier.close() does not check this prerequisite before invoking
the encoder.flush(bytes). So I write a test case[1] to check this issue but it passed, I think
it is because our CharsetEncoder.flush() does not follow the spec.
> Though I think our OutputStreamWrtier.close() should modify to follow the spec. I have
put the patch[1] on this jira.
> And I will also look into the CharsetEncoder.flush() to investigate this problem.
> [1] see the attached patch

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message