Re: String parameter in nsIOutputStream.write(...)

gigamorph <[email protected]> Wed, 18 Feb 2009 07:49:53 -0800 (PST)
Newsgroups gmane.comp.mozilla.devel.java
Organization http://groups.google.com
Message-ID <16e49b8e-dcf1-4e3a-94a2-b95f285ee936__40397.9590315886$1234972317$gmane$org@m22g2000vbp.googlegroups.com>
On Feb 12, 1:39 pm, seong <[email protected]> wrote:
> Hello,
>
> I have a few interrelated questions about the write() method of the
> interface org.mozilla.interfaces.nsIOutputStream that takes two
> arguments; aBuf of type String and aCount of type long.
>
> 1) The C++ counterpart of the method takes a char array. Exactly what
> is being done to convert
>     a Java String to a C++ char*?
> 2) What should the value of aCount be? Should it be aBuf.length() or
> aBuf.getBytes().length or some other value?
> 3) What if I want to write binary data? Is this interface suitable for
> that task at all?
>
> Thank you.
>
> -Seong

I think I found an answer to my last question. It seems
nsIBinaryOutputStream can be an adapter for nsIOutputStream:

nsIBinaryOutputStream bout = XPCOMUtils.create("@mozilla.org/
binaryoutputstream;1",
                nsIBinaryOutputStream.class); //using an XPCOMUtil
method in MozSwing to create the instance
bout.setOutputStream(aNsIOutputStream);
bout.writeByteArray(aBiteArray, numBytes);

It seems to work for me, but could someone confirm whether this is the
right approach?
And question #1 and #2 remains. Thanks!

-Seong