473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with copying objects please

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
2 2306
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: onTilt | last post by:
Hi, I have few questions and doubts,so please help: Is it true that Runtime class holds runtime information on all objects? Is it true that a subclass has more, or equal amount of...
9
by: Enc5 | last post by:
data structures teacher gave me like 50 questions, I have a few I'm not sure about. My last c++ class was like 8 months ago and I can't remember a lot of things. If anyone could help me on any of...
6
by: ziwu | last post by:
std::copy() is a function from C++ library. Is memcpy() a function from C library, or is it re-implemented in C++ library? Why people say "In C++, don't use memcpy for non-POD types? What is...
5
by: Shane | last post by:
Thanks in advance for the help. I'm new to the STL and havig a bit of trouble figuring out the whole iterator thing. I am using the <list> template and I can insert elements into the list just...
5
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
2
by: Carl Howarth | last post by:
Sorry to repost, but I am fairly desparate to get this issue resolved! Please see below, when it hangs if I leave it long enough I get a 'General Network Error', or something similar. Could this...
1
by: Esteban Felipe | last post by:
Hi, thanks for reading. I hope to find some help here before I commit suicide because this is driving me crazy. Please excuse me if this looks like a long post, but I hope that a complete...
9
by: Julian | last post by:
Hi, I have a vector defined like this: std::vector<Load*LoadList; which is populated with different objects of classes that are derived from 'Load'. I need to make a copy of this list during...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.