• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

MalformedInputException in BufferedReader

 
Ranch Hand
Posts: 143
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



No problems. It happens!
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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/]
 
anadi kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
That is a really big piece of pie for such a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic