@mozilla.org/io/string-input-stream;1

This component implements the following interfaces:

Constants

PRInt32 nsISeekableStream.NS_SEEK_SET = 0
PRInt32 nsISeekableStream.NS_SEEK_CUR = 1
PRInt32 nsISeekableStream.NS_SEEK_END = 2

Methods

InterfaceMethod
nsIStringInputStream [noscript] void adoptData ( charPtr* data , PRInt32 datlen )
nsIInputStream PRUint32 available ( )
nsIInputStream void close ( )
nsIInputStream PRBool isNonBlocking ( )
nsIInputStream [noscript] PRUint32 read ( charPtr* buf , PRUint32 count )
nsIInputStream [noscript] PRUint32 readSegments ( nsWriteSegmentFun writer , voidPtr* closure , PRUint32 count )
nsISeekableStream void seek ( PRInt32 whence , PRInt64 offset )
nsIStringInputStream void setData ( char* data , PRInt32 datlen )
nsISeekableStream void setEOF ( )
nsIStringInputStream [noscript] void shareData ( char* data , PRInt32 datlen )
nsISeekableStream PRInt64 tell ( )

Reference documentation is generated from Mozilla's source.

Add a note User Contributed Notes
June 27, 2004, 4:23 am basic at mozdev dot org
nsIOutputStream interface is not actually available via this class. So these methods:

close()
flush()
isNonBlocking()
write ( buf, count)
writeFrom ( fromStream , count)
writeSegments ( reader , closure , count)
are not available. Here's a quick hack for a nsIOutputStream interface:

function StringOutputStream () {this.buf = '';}
StringOutputStream.prototype = {
QueryInterface: function(iid) {
if (!iid.equals(Components.interfaces.nsISupports) &&
!iid.equals(Components.interfaces.nsIOutputStream))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
close : function () {},
flush : function () {},
isNonBlocking : function () { return false; },
write : function (buf, count) {
if (count < 0 || count > buf.length) {
this.buf += buf;
return buf.length;
}
this.buf += buf.substr(0,count);
return count;
},
writeFrom : function (fromStream, count) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
writeSegments : function (reader, closure , count) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
};
to dump the data from this output stream to the string input stream, just do:

string_input_stream_object.setData(hack_output_stream_object.buf,-1);

Copyright © 1999 - 2005 XULPlanet.com