471,873 Members | 992 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

Problems with encoding/decoding locales

Hi there,
I'm using a python script in conjunction with a JPype, to run java classes.
So, here's the code:

from jpype import *
import os
import random
import math
import sys

input = open('foo.img','rb').read().decode('ISO-8859-1')

square = java.encoding(input)

output = java.decoding()

fd = open('foo_decode.img','wb')
fd.write(output.encode('ISO-8859-1'))
fd.close()
sys.exit(0)

First of all, java.encoding and java.decoding are two methods that
respectively take a java string as an argument and return a java String.
JPype is the bridge between Java and Python, and converts automatically
a str or unicode pythonstring into a Java String.
So, input and output are two unicode strings. I were forced to use
decode() and encode() methods by python, otherwise it refuses to read
foo.img file.
Here's the strange behaviour: when I write the output in the
'foo_decode.img', I don't reassemble the original file; I already tested
the java encoding/decoding libraries with the same input file, and what
the decoding process returns is the original file.
I suspect that the discrepancy is due to encoding/decoding of
ISO-8859-1: is that required?
What do you think about?

Thank you

Sep 30 '08 #1
0 1688

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Stingray | last post: by
1 post views Thread by Slade | last post: by
9 posts views Thread by Mark | last post: by
3 posts views Thread by Joshua Stewart | last post: by
37 posts views Thread by Zhiv Kurilka | last post: by
6 posts views Thread by Franz Steinhaeusler | last post: by
9 posts views Thread by KWSW | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.