harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Li Jing Qin (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-4196) [classlib][luni] InputStreamReader can't handle UnicodeBig encoding
Date Thu, 05 Mar 2009 06:41:59 GMT

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

Li Jing Qin commented on HARMONY-4196:
--------------------------------------

Hey guys, I am doing EUT test for 3.5. This also block the testcase. So I decide to fix it.
I am agree with Paulex to map the UnicodeBig and UnicodeLittle to the UTF-16. Here is the
similiar tests:
public final static byte[] BOM_UTF_16BE = {(byte) 0xFE, (byte) 0xFF};
	
	public static void printByteArray(byte[] array) {
		System.out.println("LEN: " + array.length);
		for (byte b : array) {
			System.out.print(Character.forDigit(((b & 0xF0) >> 4), 16));
			System.out.print(Character.forDigit((b & 0x0F), 16));
			System.out.print(" ");
		}
		System.out.println();
	}
	
	public static InputStream getInputStream(byte[][] contents) {
		int size = 0;
		// computes final array size 
		for (int i = 0; i < contents.length; i++)
			size += contents[i].length;
		byte[] full = new byte[size];
		int fullIndex = 0;
		// concatenates all byte arrays
		for (int i = 0; i < contents.length; i++)
			for (int j = 0; j < contents[i].length; j++)
				full[fullIndex++] = contents[i][j];
		return new ByteArrayInputStream(full);
	}
	
	public static void main(String[] args) throws Exception {
		String XML_ROOT_ELEMENT_NO_DECL = "<org.eclipse.core.runtime.tests.root-element/>";
		try {
			byte[] bArray = XML_ROOT_ELEMENT_NO_DECL.getBytes("UTF-16BE");
			printByteArray(bArray);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		InputStreamReader reader = new InputStreamReader(getInputStream(new byte[][] {BOM_UTF_16BE,
XML_ROOT_ELEMENT_NO_DECL.getBytes("UTF-16BE")}), "UnicodeBig");
		StringBuilder sb = new StringBuilder();
		int c = -1;
		while ((c = reader.read()) != -1) {
			sb.append((char)c);
		}
		System.out.println("GET:" + sb);
	}

if we change the "UnicodeBig" to the "UTF-16", our harmony could correctly parse the stream.

There are two ways to fix this:
1. Add the mapping in the InputStreamReader and OutputStreamReader
2. Add the mapping in the Charset.forName(), which will let the Charset support UnicodeBig
and UnicodeLittle.

I would like to choose fix 2. Any consideration is appreciate.
Patch will be attached later.


> [classlib][luni] InputStreamReader can't handle UnicodeBig encoding
> -------------------------------------------------------------------
>
>                 Key: HARMONY-4196
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4196
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>            Assignee: Alexei Zakharov
>            Priority: Minor
>         Attachments: Harmony-4196-InputStreamReader_diagnostics.patch
>
>
> Consider the following simple test:
> import java.io.*;
> public class Test {
>     public static void main(String[] args) {
>         try {
>             new InputStreamReader(new ByteArrayInputStream(new byte[] {(byte) 0xFE, (byte)
0xFF}), "UnicodeBig");
>             System.out.println("SUCCESS");
>         } catch (Throwable e) {
>             System.out.println("FAIL:");
>             e.printStackTrace(System.out);
>         }
>     }
> }
> Output on RI:
> SUCCESS
> Output on Harmony (both DRL VM and IBM VM):
> FAIL:
> java.io.UnsupportedEncodingException
>         at java.io.InputStreamReader.<init>(InputStreamReader.java:104)
>         at Test.main(Test.java:6)
> Additional investigation shows that the cause for this exception is:
> java.nio.charset.UnsupportedCharsetException: The unsupported charset name is "UnicodeBig".
>         at java.nio.charset.Charset.forName(Charset.java:564)
>         at java.io.InputStreamReader.<init>(InputStreamReader.java:99)
>         at Test.main(Test.java:5)
> Interesting point is, the direct call to Charset.forName("UnicodeBig") causes the same
exception on RI also.
> So it seems the problem is not in Charset but in InputStreamReader itself.

-- 
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