aspose file tools*
The moose likes Java in General and the fly likes Buffered reader readline not throws malformed input exception  in jre1.6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Buffered reader readline not throws malformed input exception  in jre1.6" Watch "Buffered reader readline not throws malformed input exception  in jre1.6" New topic
Author

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

Vinu jos
Greenhorn

Joined: May 21, 2012
Posts: 2
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: May 21, 2012
Posts: 2
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

Joined: Oct 13, 2005
Posts: 40064
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Buffered reader readline not throws malformed input exception in jre1.6