Link to home
Start Free TrialLog in
Avatar of poweranger77
poweranger77

asked on

ByteArrayInputStream problems.

I have some problems.. and i have tested it's really because of that. I just dont understand why. Anyone can help to tell me why.

i have this:
..
..
String xml_data = rs.getBlob("XML_PARSED_DATA");
byte[] b1 = xml_data.getBytes(1, (int) xml_data.length());
ByteArrayInputStream xml_in_byte1 = new java.io.ByteArrayInputStream(b1);
ByteArrayInputStream xml_in_byte2 = new java.io.ByteArrayInputStream(b1);
ByteArrayInputStream xml_in_byte3 = new java.io.ByteArrayInputStream(b1);

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xml_in_byte1);
Element root = doc.getRootElement();

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xml_in_byte2);
Element root = doc.getRootElement();

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xml_in_byte3);
Element root = doc.getRootElement();
..
..
this variable, if i keep on reusing it, it'll have error with me. And if i didnt repeat to declare multiple time, i will safe. I am wondering any limitation with this [ByteArrayInputStream ] datatype?
ASKER CERTIFIED SOLUTION
Avatar of radarsh
radarsh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of avinthm
avinthm

why are u declaring 3 ByteArrayInputStream objects ???
and wht is the error u r getting?
Avatar of CEHJ
All you need is

Document doc = builder.build(new StringReader(xml_data));
Yeah....

I don't understand why you are creating three instances of ByteArrayInputStream and only one of the byte[] array.

If you want to do it that way u need to create three instanes of the byte[] array.

Cheers,

Leo

>> SAXBuilder builder = new SAXBuilder();

You're also declaring that three times. You can remove the other two.
You'd be better using Reader/Writer with text-based input