• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Buffered reader readline not throws malformed input exception in jre1.6

 
Vinu jos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IN Jre 1.4.2 ascented characters are encoded to utf8 when it was read by readline method malformed input exception is thrown

BufferedReader out1 = new BufferedReader (new InputStreamReader(in,"utf-8"));
while((inputLine=out1.readLine())!=null){} - this line throws exception

input - éó

when this code is executed in jre1.4.2 it gives

sun.io.MalformedInputException
at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java:270)
at sun.nio.cs.StreamDecoder$ConverterSD.convertInto(StreamDecoder.java:2
87)
at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:337)

at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:223)
at java.io.InputStreamReader.read(InputStreamReader.java:208)
at java.io.BufferedReader.fill(BufferedReader.java:153)
at java.io.BufferedReader.readLine(BufferedReader.java:316)
at java.io.BufferedReader.readLine(BufferedReader.java:379)
at Testutf.main(Testutf.java:46)
sun.io.MalformedInputException

Where as the same code compiled and run in JRE1.6 is not throwing the malinformed exception and the ascented characters are shown as boxes ,

why malformed input exception is not thrown in jre 1.6 ? we need the mal informed input exception for some cases
 
Tim Moores
Bartender
Posts: 2752
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, not that the encoding is called "UTF-8", not "utf-8", so that's what you should use. It's also specified that way in the javadocs.

I guess the salient question is: *Is* that character a valid UTF-8 encoded character? If so, then Java 6 is right not to throw an exception. What are the decimal values that character is represented by in the (supposedly) UTF-8-encoded representation?
 
Vinu jos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changed utf-8 to UTF-8 .

the UTF8-encoded bytes as decimal numbers

195.136 -é
195.155 - ó

but still jre1.6 is accetping the character .

where as jre1.4.2 malinformedinput exception is thrown why jre 6 is not throwing it ?

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be that the Unicode representation has changed. Please review the documentation for the Character class and that Exception for Java1.4.2 and Java6. Please work out the representation of those two byte pairs into Unicode; it is not that difficult from the UTF-8 numbers, and compare their values in a 10‑year‑old version of Unicode and the more recent versions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic