24 #include <nsComponentManagerUtils.h>
25 #include <nsServiceManagerUtils.h>
26 #include <nsStringAPI.h>
30 : mFileStreamIsActive(PR_FALSE)
31 , mObjectStreamIsActive(PR_FALSE)
44 mFileStreamIsActive = PR_FALSE;
45 mObjectStreamIsActive = PR_FALSE;
51 if (NS_FAILED(
Close())) {
52 NS_WARNING(
"Error cold not close the output streams!");
60 NS_ENSURE_ARG_POINTER(aStreamedFile);
64 do_CreateInstance(
"@mozilla.org/network/file-output-stream;1", &rv);
65 NS_ENSURE_SUCCESS(rv, rv);
68 rv = mFileOutputStream->Init(aStreamedFile, -1, -1, 0);
69 NS_ENSURE_SUCCESS(rv, rv);
74 do_CreateInstance(
"@mozilla.org/binaryoutputstream;1", &rv);
75 NS_ENSURE_SUCCESS(rv, rv);
77 rv = mObjectOutputStream->SetOutputStream(mFileOutputStream);
78 NS_ENSURE_SUCCESS(rv, rv);
89 NS_ENSURE_ARG_POINTER(aSupports);
92 return NS_ERROR_NOT_AVAILABLE;
95 return mObjectOutputStream->WriteObject(aSupports, aIsStrongRef);
102 return NS_ERROR_NOT_AVAILABLE;
105 nsCString
str(aString);
106 return mObjectOutputStream->WriteStringZ(str.get());
113 return NS_ERROR_NOT_AVAILABLE;
116 nsString
str(aString);
117 return mObjectOutputStream->WriteWStringZ(str.get());
124 return NS_ERROR_NOT_AVAILABLE;
127 return mObjectOutputStream->Write32(aOutInt);
134 return NS_ERROR_NOT_IMPLEMENTED;
137 return mObjectOutputStream->WriteBoolean(aBoolean);
143 NS_ENSURE_ARG_POINTER(aData);
146 return NS_ERROR_NOT_AVAILABLE;
149 return mObjectOutputStream->WriteBytes(aData, aLength);
157 rv = mFileOutputStream->Close();
158 NS_ENSURE_SUCCESS(rv, rv);
163 rv = mObjectOutputStream->Close();
164 NS_ENSURE_SUCCESS(rv, rv);
178 mFileStreamIsActive = PR_FALSE;
179 mBufferedStreamIsActive = PR_FALSE;
180 mObjectStreamIsActive = PR_FALSE;
186 mBufferedStreamIsActive ||
189 if (NS_FAILED(
Close())) {
190 NS_WARNING(
"Error cold not close the output streams!");
198 NS_ENSURE_ARG_POINTER(aStreamedFile);
202 do_CreateInstance(
"@mozilla.org/network/file-input-stream;1", &rv);
203 NS_ENSURE_SUCCESS(rv, rv);
206 rv = mFileInputStream->Init(aStreamedFile, -1, -1, 0);
207 NS_ENSURE_SUCCESS(rv, rv);
211 mBufferedInputStream =
212 do_GetService(
"@mozilla.org/network/buffered-input-stream;1", &rv);
213 NS_ENSURE_SUCCESS(rv, rv);
215 rv = mBufferedInputStream->Init(mFileInputStream, 4096);
216 NS_ENSURE_SUCCESS(rv, rv);
218 mBufferedStreamIsActive = PR_TRUE;
221 do_CreateInstance(
"@mozilla.org/binaryinputstream;1", &rv);
222 NS_ENSURE_SUCCESS(rv, rv);
224 rv = mObjectInputStream->SetInputStream(mBufferedInputStream);
225 NS_ENSURE_SUCCESS(rv, rv);
236 NS_ENSURE_ARG_POINTER(aOutObject);
239 !mBufferedStreamIsActive ||
242 return NS_ERROR_NOT_AVAILABLE;
245 return mObjectInputStream->ReadObject(aIsStrongRef, aOutObject);
252 !mBufferedStreamIsActive ||
255 return NS_ERROR_NOT_AVAILABLE;
258 return mObjectInputStream->ReadCString(aReadString);
265 !mBufferedStreamIsActive ||
268 return NS_ERROR_NOT_AVAILABLE;
271 return mObjectInputStream->ReadString(aReadString);
277 NS_ENSURE_ARG_POINTER(aReadInt);
280 !mBufferedStreamIsActive ||
283 return NS_ERROR_FAILURE;
286 return mObjectInputStream->Read32(aReadInt);
292 NS_ENSURE_ARG_POINTER(aReadBoolean);
295 !mBufferedStreamIsActive ||
298 return NS_ERROR_FAILURE;
301 return mObjectInputStream->ReadBoolean(aReadBoolean);
307 NS_ENSURE_ARG_POINTER(aString);
310 !mBufferedStreamIsActive ||
313 return NS_ERROR_FAILURE;
316 return mObjectInputStream->ReadBytes(aLength, aString);
324 rv = mFileInputStream->Close();
325 NS_ENSURE_SUCCESS(rv, rv);
329 if (mBufferedStreamIsActive) {
330 rv = mBufferedInputStream->Close();
331 NS_ENSURE_SUCCESS(rv, rv);
333 mBufferedStreamIsActive = PR_FALSE;
336 rv = mObjectInputStream->Close();
337 NS_ENSURE_SUCCESS(rv, rv);
NS_DECL_ISUPPORTS NS_IMETHOD InitWithFile(nsIFile *aStreamedFile)
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
nsresult WriteObject(nsISupports *aSupports, PRBool aIsStrongRef)
nsresult WriteString(const nsAString &aString)
virtual ~sbFileObjectStream()
nsresult WriteUint32(PRUint32 aOutInt)
nsresult WriteCString(const nsACString &aString)
virtual ~sbFileObjectOutputStream()
PRBool mFileStreamIsActive
nsresult WriteBytes(const char *aData, PRUint32 aLength)
PRBool mObjectStreamIsActive
_updateTextAndScrollDataForFrame aData
nsresult WritePRBool(PRBool aBoolean)