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).
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?
Joined: Feb 10, 2011
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.
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.
Joined: Feb 10, 2011
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
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.
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.