aspose file tools*
The moose likes Java in General and the fly likes Parsing BLOB datatype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing BLOB datatype" Watch "Parsing BLOB datatype" New topic
Author

Parsing BLOB datatype

Reddy Anoop
Greenhorn

Joined: Aug 22, 2007
Posts: 8
Hello,

I need help/suggestion on how to resolve the following issue.
I need to read an xml file stored in as BLOB in an oracle table. I am able to read the file. I am stuck after this because, I am calling another java program to parse by passing in an XML file. Since I am not sure how to convert the BLOB to an xml file, I am getting no where. Any suggestions/help is greatly appreciated.
Here is what I need to do.
1. Read BLOB data type from xml
2. Convert the BLOB into an xml file and call the parser program with this
xml file as the parameter.

Regards
Anoop
Joseph Kampf
Greenhorn

Joined: Mar 04, 2004
Posts: 26
Well first thing you need to do is convert the Binary Data into a String. Do you have the code that put the XML into the BLOB? Is it on the same platform?

When you call the getBytes() method of a string, you use the default character encoding for the platform the JVM is running on. You do have the option of passing a Character encoding to the getByte() method to specify how the String is converted into Bytes. Check out the JavaDoc for getBytes() method on java.lang.String for how to do this.

Once you figure out what encoding, you then need to gather your bytes and create a String. You can do this in a loop that reads the ByteInputStream into an array. Then you can construct a string that contains your XML with the String(byte[] bytes, String charsetName) constructor.

After you have your XML in a string it is easy to open a FileWriter and write the String to the Writer.


Originally posted by Reddy Anoop:
Hello,

I need help/suggestion on how to resolve the following issue.
I need to read an xml file stored in as BLOB in an oracle table. I am able to read the file. I am stuck after this because, I am calling another java program to parse by passing in an XML file. Since I am not sure how to convert the BLOB to an xml file, I am getting no where. Any suggestions/help is greatly appreciated.
Here is what I need to do.
1. Read BLOB data type from xml
2. Convert the BLOB into an xml file and call the parser program with this
xml file as the parameter.

Regards
Anoop
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
In fact you don't need to create a String at all. Just write the binary stream that you can get from Blob object to a FileOutputStream. That will preserve the encoding of the XML data (assuming that it was correctly written to the database in the first place).


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Don't get me started about those stupid light bulbs.
 
subject: Parsing BLOB datatype