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?
poweranger77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

radarshCommented:
You are wrapping on the same instance of byte[] b1. That's why. If you really want isolated copies,
you either have to clone b1 and use it in the constructor or create copies of b1 and use.

byte[] b1 = xml_data.getBytes(1, (int) xml_data.length());
byte[] b2 = new byte [b1.length];
byte[] b3 = new byte [b1.length];

System.arraycopy(b1, 0, b2, 0, b1.length);
System.arraycopy(b1, 0, b3, 0, b1.length);

ByteArrayInputStream xml_in_byte1 = new java.io.ByteArrayInputStream(b1);
ByteArrayInputStream xml_in_byte2 = new java.io.ByteArrayInputStream(b2);
ByteArrayInputStream xml_in_byte3 = new java.io.ByteArrayInputStream(b3);

________
radarsh
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
avinthmCommented:
why are u declaring 3 ByteArrayInputStream objects ???
and wht is the error u r getting?
0
CEHJCommented:
All you need is

Document doc = builder.build(new StringReader(xml_data));
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Leo EikelmanDirector, IT and Business DevelopmentCommented:
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

0
Mayank SAssociate Director - Product EngineeringCommented:
>> SAXBuilder builder = new SAXBuilder();

You're also declaring that three times. You can remove the other two.
0
CEHJCommented:
You'd be better using Reader/Writer with text-based input
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.