wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes MalformedInputException in BufferedReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "MalformedInputException in BufferedReader " Watch "MalformedInputException in BufferedReader " New topic
Author

MalformedInputException in BufferedReader

Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Hi,

Have a problem when reading a file that was transferred from AS400 through FTP via the following command
------------------
bin
quote type C 943
get source destfile
------------------
This creates a xxx.txt file in the Application Server in Linux.

When the Servlet uses the BufferedReader to read the file it returns the below exception when it tries to read the file..



This works fine when the file is read from windows OS. Understand that there's some problem understanding the Japanese character while the read. Request your valuable inputs on this .. since we are hang up here.

Thanks in advance for the inputs and time.
[ September 10, 2008: Message edited by: roshini sridhar ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7


This sure sounds like you are trying to read a value that can't be converted into the UTF-8 codepage.
How about setting the BufferedReader to use the same codepage that the file uses, or use a Stream, as they do not do character conversion.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Thanks a lot for the reply.

Can you please tell how to set the codepage for the Reader, also is there any default codepage format for AS/400 files based on the ftp command we used to download to [quote type C 943 ]

Also would like to know how the file same is read when created in the Windows machine.
[ September 10, 2008: Message edited by: roshini sridhar ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

Originally posted by roshini sridhar:
Thanks a lot for the reply.

Can you please tell how to set the codepage for the Reader,

I apologize. I swear that there was some way to change Reader to use something other than the default encoding, but there doesn't seem to be.

Originally posted by roshini sridhar:

Also would like to know how the file same is read when created in the Windows machine.

The only thing I can think of is that Windows is not using UTF-8 as the default encoding.
My advice is use a stream if you are not doing any text processing. It will be faster and you won't run into encoding issues.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Joe:
I swear that there was some way to change Reader to use something other than the default encoding, but there doesn't seem to be.


Actually, it is not directly specified in the BufferedReader but in the reader that it is wrapping.
So, if one is using an InputStreamReader(As looks the case in the stacktrace) then the character encoding specified in this reader will be used by the buffered reader. After all, buffered reader just wraps over a reader and does not do the byte to char conversion on its own.
P.S.


apigee, a better way to API!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

Originally posted by Nitesh Kant:
InputStreamReader


Thanks. I must have looked at every other Reader in the API and was questioning my sanity!
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Joe:
I must have looked at every other Reader in the API and was questioning my sanity!


No problems. It happens!
anadi kumar
Greenhorn

Joined: Mar 19, 2010
Posts: 7
give second parameter, "UTF-16" or "UTF-8" as encoding type, to the InputStream / OutputStream.


InputStreamReader ir = new InputStreamReader(fileinputstream, "UTF-16");





Regards,
Anadi KUMAR
Architecture and R2ds, Channels and Framework, Software Engineer | HSBC Technology and Services - Global Technology
HSBC Software Development (India)Limited
GLT 4.0 - Panchshil Tech. Park, Block D, S.No. 19, Hissa 2A/11/2, Yerawada, Pune, 411006.
India.

Mobile. +91 99822622054
Email. anadikumar@hsbc.co.in
Email. anadikumar@gmail.com
Gladwin Burboz
Greenhorn

Joined: Feb 26, 2008
Posts: 25

I know this thread is very old but didn't find any satisfying answer and hence adding few comments.


http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html
In Extended Encoding Set look for "Cp943" - "IBM OS/2 Japanese, superset of Cp932 and Shift-JIS"

Make sure your JVM has required charset in "jre\lib\charsets.jar"
Use IBM JRE which will mostly have this extended charset for Cp943


Thanks,

Gladwin
[http://www.linkedin.com/in/gladwinb/]

<a href="http://www.sealordresortarnala.com" target="_blank" rel="nofollow">http://www.sealordresortarnala.com</a>
anadi kumar
Greenhorn

Joined: Mar 19, 2010
Posts: 7
anadi kumar wrote:give second parameter, "UTF-16" or "UTF-8" as encoding type, to the InputStream / OutputStream.


InputStreamReader ir = new InputStreamReader(fileinputstream, "UTF-16");





Regards,
Anadi KUMAR
Architecture and R2ds, Channels and Framework, Software Engineer | HSBC Technology and Services - Global Technology
HSBC Software Development (India)Limited
GLT 4.0 - Panchshil Tech. Park, Block D, S.No. 19, Hissa 2A/11/2, Yerawada, Pune, 411006.
India.

Mobile. +91 9822622054
Email. anadikumar@hsbc.co.in
Email. anadikumar@gmail.com
 
wood burning stoves
 
subject: MalformedInputException in BufferedReader
 
Similar Threads
unable see the server logs in console of websphere 6.0
Error : WSVR0068E: Attempt to start EnterpriseBean
ResultSet is closed exception
urgent help needed - Struts-Faces integration problem
getting the Duplicate home name Exception while installing application