• 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

Character Encoding

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I had problem in converting blob object (which was stored as zip) to string. since i used different encoding format while reading from the database vs encoding used by database to convert the data to blob object.

below code creates problem if i use different encoding



i fix the issue by replacing the above code with the below one



so please advice me whether it is correct approach to fix the problem in case of reading the file in different encoding . i feel there is no much difference between code, but second code fix my problem (educate me how does the second code fix the issue).


i appreciate you reply on this
Thanks
Dhoni
 
Sheriff
Posts: 28322
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dhoni Gibson wrote:I had problem in converting blob object (which was stored as zip) to string.



If the BLOB data was originally a ZIP archive, then it doesn't make sense to convert it to a string. It isn't text data so it shouldn't be treated as a string.

However it's impossible to answer your question specifically about character encoding in your code, because the fragments you posted don't show any evidence of character encodings being used. Could you perhaps show us where you think you are using a character encoding?
 
dhoni Gibson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi paul

appreciate your apply on this.

1) i want to convert the zip data (byte) into the character later i will form the string object.

2) i was passing the encoding as jvm argument as below.

-Dfile.encoding=UTF8

hope i answered your question


Thanks
Dhoni
 
Paul Clapham
Sheriff
Posts: 28322
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you didn't answer my question.

Character encodings are only used when bytes are converted to chars, or vice versa. Your code doesn't have any such examples. And BLOBs are binary objects, so producing a BLOB from bytes doesn't involve any character encoding.
 
dhoni Gibson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i got it. i am pasting the code with the byte to char conversion code here.


Old code here




New code with byte to char conversion



once i got all the bytes.. i will convert the bytes into the text data in the new code

 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if this affecting you, but Java had a problem with foreign characters in ZipEntry. Apparently, that's fixed in Java 7, but if you're using an earlier JDK, that could be causing you problems. http://bugs.sun.com/view_bug.do?bug_id=4244499
 
dhoni Gibson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Greg

Thanks for your post. i read through the link and learned issue was between two different platforms while encoding characaters.my issue is bit different, I am running my application in unix environment where i had issue while reading through zip file. i happen where my zip data is persisited in db and while reading through the java code i couldnt recreate the data inside the data.

i have fixed the issue which i have mentioned in the previous post.

i want to know whether i need to use same encoding format which my database is using.

i am using oracle database which uses US7ASCII as encoding . where as my jvm uses US-ASCII.
 
Greg Charles
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't think it matters. Blobs are binary data and therefore not encoded. You might have to match encodings between whatever produced the zip file entry names and whatever is consuming them, but I can't see how Oracle's preferred encoding would make any difference.
 
My honeysuckle is blooming this year! Now to fertilize this 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