Combining IOs and Strings?

D

Derek Lewis

I've been experimenting with some modifications to WEBrick, and came
across an interesting little problem I'm not sure how to solve.

I've got a method with a signature something like this:

def appendTo( someData, moreData)
end

If both someData and moreData are Strings, then the method is really easy:
return someData + moreData

The problem is when either (or both) someData and moreData are IOs. I don't
want to read all the lines from the IOs, into a string, and append to
that. It's concievable that the data from the IO may be larger than
memory. What I'd like to do is return an IO from the method, that, when
read from, will return the data from someData, and then the data from
moreData.

Basically what I want to do is create a subclass of IO, maybe called
ArrayIO, that maintains an array of Strings and IO objects, and
progresses through them as it is read from.

Is there a particular subset of the methods in IO that I can override in
an IO subclass, and be confident that my subclass will work?

--
Derek Lewis

===================================================================
Java Web-Application Developer

Email : (e-mail address removed)
Cellular : 778.898.5825
Website : http://www.lewisd.com

"If you've got a 5000-line JSP page that has "all in one" support
for three input forms and four follow-up screens, all controlled
by "if" statements in scriptlets, well ... please don't show it
to me :). Its almost dinner time, and I don't want to lose my
appetite :)."
- Craig R. McClanahan
 
E

Eric Hodel

--Apple-Mail-17--770249786
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

Is there a particular subset of the methods in IO that I can override
in
an IO subclass, and be confident that my subclass will work?

Take a look at StringIO. Generally, just #read, but maybe also #eof?
and a few others.
[strip 15 lines of sig]

Please make your signature fit in about four lines (not including '--
').

--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-17--770249786
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCEuDMMypVHHlsnwQRAjypAKDEMVlqkUrJ9cF55qK7kFsdVtwYqQCdHPFo
sEF+jKrb8z55oEZ3Sg1NdPc=
=IFVm
-----END PGP SIGNATURE-----

--Apple-Mail-17--770249786--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top