Java input/output streams from Ruby string's backing byte array
---------------------------------------------------------------
Key: JRUBY-929
URL: http://jira.codehaus.org/browse/JRUBY-929
Project: JRuby
Issue Type: New Feature
Components: Java Integration
Affects Versions: JRuby 1.x
Reporter: Bill Dortch
It would be useful to be able to read/write Java input/output streams directly
from the backing byte array of Ruby strings. This would avoid unnecessary
array allocation/copying (one user reports transmitting byte arrays of several
hundred K derived from Ruby strings).
This functionality could be implemented as methods on String, or in some kind
of helper class. Here's what the direct approach might look like:
{code}
ostream = (some kind of java.io.OutputStream)
a_string.to_java_output_stream(ostream) #=> writes the backing bytes to ostream
istream = a_string.to_java_input_stream #=> (some kind of java.io.InputStream)
aJavaApp.readSomeBytes(istream) #=> app reads stream from backing bytes
{code}
This would be easy enough to implement, but some care would need to be taken to
ensure the integrity of the data. In the second case, for example, the _very_
easy solution would seem to be to wrap the bytes (from the string's ByteList)
in a ByteArrayInputStream. But B-A-I-S exposes the underlying array as a
protected field; if/when we decide how to enable protected field/method access,
Ruby's lax enforcement of protected/private visibility could lead to problems.
(But that's a topic for a different issue - see JRUBY-194.)
A related feature that might be useful is the ability to read in a Ruby string
from a Java input stream:
{code}
istream = (some kind of java.io.InputStream)
a_string = String.from_java_input_stream(istream)
{code}
As I said, there are other ways this functionality could be exposed. But there
does seem to be a need/desire for this, especially since we really can't
directly expose the backing bytes of RubyString/ByteList.
I imagine this would probably all be post-1.0 functionality.
Thoughts?
-Bill
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email