By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,782 Members | 1,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,782 IT Pros & Developers. It's quick & easy.

Help with copying objects please

P: n/a
D
Hi,
I have some old code that uses the deprecated copy command as :

ByteArrayOutputStream bout = new ByteArrayOutputStream();
StringReader sr = new StringReader(strString);
copy(sr,bout);

how could I achieve the same result without the now redundant copy command?

Thanks

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SPG
Try:

ByteArrayOutputStream bout = new ByteArrayOutputStream();
StringReader sr = new StringReader(strString);

int val=0;
byte[] bytes = new byte[32*1024] //32K byte array
while ((val=sr.read(bytes))!= -1) {
bout.write(bytes,0,val);
}

But, I would be weary of mixing readers with outputstreams. I would make
sure you use a Reader with a Writer or and InputStream with an OutputStream.
Mainly due to conversion protocols but can cause some probs...

HTH

Steve

"D" <no***@nowhere.COM> wrote in message
news:3f**********************@news.dial.pipex.com. ..
Hi,
I have some old code that uses the deprecated copy command as :

ByteArrayOutputStream bout = new ByteArrayOutputStream();
StringReader sr = new StringReader(strString);
copy(sr,bout);

how could I achieve the same result without the now redundant copy command?
Thanks

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003

Jul 17 '05 #2

P: n/a
D

"SPG" <st************@nopoo.blueyonder.co.uk> wrote in message
news:PY*********************@news-text.cableinet.net...
Try:

ByteArrayOutputStream bout = new ByteArrayOutputStream();
StringReader sr = new StringReader(strString);

int val=0;
byte[] bytes = new byte[32*1024] //32K byte array
while ((val=sr.read(bytes))!= -1) {
bout.write(bytes,0,val);
}

But, I would be weary of mixing readers with outputstreams. I would make
sure you use a Reader with a Writer or and InputStream with an OutputStream. Mainly due to conversion protocols but can cause some probs...

HTH

Steve


Hi Steve. Many thanks for that help. I'm just getting up to speed with
Java, hopefully I'll be able to rewrite it once I get the time and a bit
more familiar with it.

Cheers

Dave
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.