As a new comer I don't know I am fortunate enough or not...I picked
the test_io.rb as my starting point to do some work for xruby. And I
found a bunch of issues, so I post here looking for advice/help.
First of all, current IO module highly depends on RandomAccessFile,
aka real file. it's true under unix/linux 'cause everyting is file.
But in JVM I think they have seperate it mainly into two parts, the
File and the Streams. We have InputStream/InputReader/Channel...to
have different ways doing IO. Current RubyIO implementation can not
meet the requirement.
OK, let's see the IO.pipe. As we know in Java before jdk1.4, we do
pipe like this:
pr = new PipeReader();
pw = new PipeWriter(pr);
printWriter = new PrintWriter(pw);
printWriter.write("xxxx");
while (pr.read() !=-1) { ... }
Or, from JDK1.4 NIO:
pipe = Pipe.open();
pipe.sink().write...
pipe.source().read...
They have no direct relationship with File.
and more, the ruby's $stdin, $stdout and $stderr are directly binding
to system input/output/error, I don't know how to create a file for
them.
So what I am thinking about is, refactory the RubyIO to an abstract
class, have the basic operations(read, write, gets, puts...) only, and
have FileRubyIO(aka RubyFile, yes), StreamRubyIO(or ReaderRubyIO),
PipedRubyIO inherited. the class hierarchy is like below:
RubyIO
- FileRubyIO(RubyFile)
- StreamRubyIO
- PipedRubyIO
We can also map the global variables $stdin, $stdout, $stderr to
StreamRubyIO, constructed with System.in, System,out and System.err.
I have just went thru the code for about one day. If I have something
wrong please let me know, thanks.
--
Michael Chen
--------------------------------
Blog: http://michael.nona.name
MSN: jzch...@hotmail.com
_________________________________________________________________
PC Magazine’s 2007 editors’ choice for best Web mail—award-winning Windows
Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507
I have done some work and make the test_io.rb passed. I will refactory
the code and make a patch late today or tommorow. As I think rewrite
the whole RubyIO is a huge work for me(not only the work effort, but
also there are may be many thin unknown to me), I would prefer make
the IO#pipe work and then move further. I am quite sure that you or
other developers have your own concern/design thoughts on that. May be
we could have a discussion.
You can either submit the patch or check in the code directly. Please
login http://code.google.com/p/xruby/source to find your SVN password. For
timezone difference (I live in Maryland), feel free to contact other team
members if you need help while I am offline.
IO is one of the most important parts of library and our current
implementation is weak. I will think more about the problem and be very
happy to hear insights from you.
(btw, I am on the road this weekend, will back to the project work soon.)
>From: "Michael Chen" <mech...@gmail.com>
>Reply-To: xruby...@googlegroups.com
>To: xruby...@googlegroups.com
>Subject: [xruby-devel] Re: IO.pipe issues -- related to RubyIO
>Date: Sun, 20 May 2007 15:01:32 +0800
>
>
>Hi Yongzhi,
>
>I have done some work and make the test_io.rb passed. I will refactory
>the code and make a patch late today or tommorow. As I think rewrite
>the whole RubyIO is a huge work for me(not only the work effort, but
>also there are may be many thin unknown to me), I would prefer make
>the IO#pipe work and then move further. I am quite sure that you or
>other developers have your own concern/design thoughts on that. May be
>we could have a discussion.
>
_________________________________________________________________