3 #include "nsIInputStream.h"
4 #include "nsIStringStream.h"
6 #include "StartupCacheUtils.h"
7 #include "mozilla/scache/StartupCache.h"
13 NS_NewObjectInputStreamFromBuffer(char* buffer
, PRUint32 len
,
14 nsIObjectInputStream
** stream
)
16 nsCOMPtr
<nsIStringInputStream
> stringStream
17 = do_CreateInstance("@mozilla.org/io/string-input-stream;1");
18 nsCOMPtr
<nsIObjectInputStream
> objectInput
19 = do_CreateInstance("@mozilla.org/binaryinputstream;1");
21 stringStream
->AdoptData(buffer
, len
);
22 objectInput
->SetInputStream(stringStream
);
24 objectInput
.forget(stream
);
29 NS_NewObjectOutputWrappedStorageStream(nsIObjectOutputStream
**wrapperStream
,
30 nsIStorageStream
** stream
)
33 nsCOMPtr
<nsIStorageStream
> storageStream
34 = do_CreateInstance("@mozilla.org/storagestream;1");
36 rv
= storageStream
->Init(256, PR_UINT32_MAX
, nsnull
);
37 NS_ENSURE_SUCCESS(rv
, rv
);
39 nsCOMPtr
<nsIObjectOutputStream
> objectOutput
40 = do_CreateInstance("@mozilla.org/binaryoutputstream;1");
41 nsCOMPtr
<nsIOutputStream
> outputStream
42 = do_QueryInterface(storageStream
);
44 objectOutput
->SetOutputStream(outputStream
);
47 // Wrap in debug stream to detect unsupported writes of
48 // multiply-referenced non-singleton objects
49 StartupCache
* sc
= StartupCache::GetSingleton();
50 NS_ENSURE_TRUE(sc
, NS_ERROR_UNEXPECTED
);
51 nsCOMPtr
<nsIObjectOutputStream
> debugStream
;
52 sc
->GetDebugObjectOutputStream(objectOutput
, getter_AddRefs(debugStream
));
53 debugStream
.forget(wrapperStream
);
55 objectOutput
.forget(wrapperStream
);
58 storageStream
.forget(stream
);
63 NS_NewBufferFromStorageStream(nsIStorageStream
*storageStream
,
64 char** buffer
, PRUint32
* len
)
67 nsCOMPtr
<nsIInputStream
> inputStream
;
68 rv
= storageStream
->NewInputStream(0, getter_AddRefs(inputStream
));
69 NS_ENSURE_SUCCESS(rv
, rv
);
72 rv
= inputStream
->Available(&avail
);
73 NS_ENSURE_SUCCESS(rv
, rv
);
75 nsAutoArrayPtr
<char> temp (new char[avail
]);
76 rv
= inputStream
->Read(temp
, avail
, &read
);
77 if (NS_SUCCEEDED(rv
) && avail
!= read
)
78 rv
= NS_ERROR_UNEXPECTED
;
85 *buffer
= temp
.forget();