1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef nsFileStreams_h__
|
---|
39 | #define nsFileStreams_h__
|
---|
40 |
|
---|
41 | #include "nsIFileStreams.h"
|
---|
42 | #include "nsIFile.h"
|
---|
43 | #include "nsIInputStream.h"
|
---|
44 | #include "nsIOutputStream.h"
|
---|
45 | #include "nsISeekableStream.h"
|
---|
46 | #include "nsILineInputStream.h"
|
---|
47 | #include "nsCOMPtr.h"
|
---|
48 | #include "prlog.h"
|
---|
49 | #include "prio.h"
|
---|
50 |
|
---|
51 | template<class CharType> class nsLineBuffer;
|
---|
52 |
|
---|
53 | ////////////////////////////////////////////////////////////////////////////////
|
---|
54 |
|
---|
55 | class nsFileStream : public nsISeekableStream
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | NS_DECL_ISUPPORTS
|
---|
59 | NS_DECL_NSISEEKABLESTREAM
|
---|
60 |
|
---|
61 | nsFileStream();
|
---|
62 | virtual ~nsFileStream();
|
---|
63 |
|
---|
64 | nsresult Close();
|
---|
65 | nsresult InitWithFileDescriptor(PRFileDesc* fd, nsISupports* parent);
|
---|
66 |
|
---|
67 | protected:
|
---|
68 | PRFileDesc* mFD;
|
---|
69 | nsCOMPtr<nsISupports> mParent; // strong reference to parent nsFileIO,
|
---|
70 | // which ensures mFD remains valid.
|
---|
71 | PRBool mCloseFD;
|
---|
72 | };
|
---|
73 |
|
---|
74 | ////////////////////////////////////////////////////////////////////////////////
|
---|
75 |
|
---|
76 | class nsFileInputStream : public nsFileStream,
|
---|
77 | public nsIFileInputStream,
|
---|
78 | public nsILineInputStream
|
---|
79 | {
|
---|
80 | public:
|
---|
81 | NS_DECL_ISUPPORTS_INHERITED
|
---|
82 | NS_DECL_NSIINPUTSTREAM
|
---|
83 | NS_DECL_NSIFILEINPUTSTREAM
|
---|
84 | NS_DECL_NSILINEINPUTSTREAM
|
---|
85 |
|
---|
86 | // Overrided from nsFileStream
|
---|
87 | NS_IMETHOD Seek(PRInt32 aWhence, PRInt64 aOffset);
|
---|
88 |
|
---|
89 | nsFileInputStream() : nsFileStream()
|
---|
90 | {
|
---|
91 | mBehaviorFlags = 0;
|
---|
92 | }
|
---|
93 | virtual ~nsFileInputStream()
|
---|
94 | {
|
---|
95 | Close();
|
---|
96 | }
|
---|
97 |
|
---|
98 | static NS_METHOD
|
---|
99 | Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
---|
100 |
|
---|
101 | protected:
|
---|
102 | /**
|
---|
103 | * The file being opened. Only stored when DELETE_ON_CLOSE or
|
---|
104 | * REOPEN_ON_REWIND are true.
|
---|
105 | */
|
---|
106 | nsCOMPtr<nsIFile> mFile;
|
---|
107 | /**
|
---|
108 | * The IO flags passed to Init() for the file open.
|
---|
109 | * Only set for REOPEN_ON_REWIND.
|
---|
110 | */
|
---|
111 | PRInt32 mIOFlags;
|
---|
112 | /**
|
---|
113 | * The permissions passed to Init() for the file open.
|
---|
114 | * Only set for REOPEN_ON_REWIND.
|
---|
115 | */
|
---|
116 | PRInt32 mPerm;
|
---|
117 | /**
|
---|
118 | * Flags describing our behavior. See the IDL file for possible values.
|
---|
119 | */
|
---|
120 | PRInt32 mBehaviorFlags;
|
---|
121 |
|
---|
122 | protected:
|
---|
123 | /**
|
---|
124 | * Internal, called to open a file. Parameters are the same as their
|
---|
125 | * Init() analogues.
|
---|
126 | */
|
---|
127 | nsresult Open(nsIFile* file, PRInt32 ioFlags, PRInt32 perm);
|
---|
128 | /**
|
---|
129 | * Reopen the file (for OPEN_ON_READ only!)
|
---|
130 | */
|
---|
131 | nsresult Reopen() { return Open(mFile, mIOFlags, mPerm); }
|
---|
132 | };
|
---|
133 |
|
---|
134 | ////////////////////////////////////////////////////////////////////////////////
|
---|
135 |
|
---|
136 | class nsFileOutputStream : public nsFileStream,
|
---|
137 | public nsIFileOutputStream
|
---|
138 | {
|
---|
139 | public:
|
---|
140 | NS_DECL_ISUPPORTS_INHERITED
|
---|
141 | NS_DECL_NSIOUTPUTSTREAM
|
---|
142 | NS_DECL_NSIFILEOUTPUTSTREAM
|
---|
143 |
|
---|
144 | nsFileOutputStream() : nsFileStream() {}
|
---|
145 | virtual ~nsFileOutputStream() { nsFileOutputStream::Close(); }
|
---|
146 |
|
---|
147 | static NS_METHOD
|
---|
148 | Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
---|
149 | };
|
---|
150 |
|
---|
151 | ////////////////////////////////////////////////////////////////////////////////
|
---|
152 |
|
---|
153 | #endif // nsFileStreams_h__
|
---|