Back to index

lightning-sunbird  0.9+nobinonly
nsIFileStream.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsIFileStream_h___
00038 #define nsIFileStream_h___
00039 
00040 #include "xpcomobsolete.h"
00041 #include "nsIInputStream.h"
00042 #include "nsIOutputStream.h"
00043 #include "nsISeekableStream.h"
00044 #include "prio.h"
00045 
00046 class nsFileSpec;
00047 
00048 /* a6cf90e8-15b3-11d2-932e-00805f8add32 */
00049 #define NS_IOPENFILE_IID \
00050 { 0xa6cf90e8, 0x15b3, 0x11d2, \
00051     {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
00052 
00053 //========================================================================================
00054 class nsIOpenFile
00055 // Represents a file, and supports Open.
00056 //========================================================================================
00057 : public nsISupports
00058 {
00059 public:
00060     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IOPENFILE_IID)
00061 
00062        NS_IMETHOD                         Open(
00063                                            const nsFileSpec& inFile,
00064                                            int nsprMode,
00065                                            PRIntn accessMode) = 0;
00066                                            // Note: Open() is only needed after
00067                                            // an explicit Close().  All file streams
00068                                            // are automatically opened on construction.
00069     NS_IMETHOD                         GetIsOpen(PRBool* outOpen) = 0;
00070 
00071 }; // class nsIOpenFile
00072 
00073 /* a6cf90e8-15b3-11d2-932e-00805f8add32 */
00074 #define NS_IRANDOMACCESS_IID \
00075 {  0xa6cf90eb, 0x15b3, 0x11d2, \
00076     {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
00077 
00078 //========================================================================================
00079 class nsIRandomAccessStore
00080 // Supports Seek, Tell etc.
00081 //========================================================================================
00082 : public nsISeekableStream
00083 {
00084 public:
00085     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRANDOMACCESS_IID)
00086 
00087 /* "PROTECTED" */
00088     NS_IMETHOD                         GetAtEOF(PRBool* outAtEOF) = 0;
00089     NS_IMETHOD                         SetAtEOF(PRBool inAtEOF) = 0;
00090 }; // class nsIRandomAccessStore
00091 
00092 
00093 #ifndef NO_XPCOM_FILE_STREAMS   // hack to work around duplicate class definitions in here
00094                                 // and mozilla/netwerks/base/nsIFileStreams.idl
00095 
00096 /* a6cf90e6-15b3-11d2-932e-00805f8add32 */
00097 #define NS_IFILESPECINPUTSTREAM_IID \
00098 { 0xa6cf90e6, 0x15b3, 0x11d2, \
00099     {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
00100     
00101 //========================================================================================
00102 class nsIFileSpecInputStream
00103 // These are additional file-specific methods that files have, above what
00104 // nsIInputStream supports.  The current implementation supports both
00105 // interfaces.
00106 //========================================================================================
00107 : public nsIInputStream
00108 {
00109 public:
00110     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFILESPECINPUTSTREAM_IID)
00111 }; // class nsIFileSpecInputStream
00112 
00113 /* a6cf90e7-15b3-11d2-932e-00805f8add32 */
00114 #define NS_IFILESPECOUTPUTSTREAM_IID \
00115 { 0xa6cf90e7, 0x15b3, 0x11d2, \
00116     {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
00117 
00118 //========================================================================================
00119 class nsIFileSpecOutputStream
00120 // These are additional file-specific methods that files have, above what
00121 // nsIOutputStream supports.  The current implementation supports both
00122 // interfaces.
00123 //========================================================================================
00124 : public nsIOutputStream
00125 {
00126 public:
00127     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFILESPECOUTPUTSTREAM_IID)
00128 }; // class nsIFileSpecOutputStream
00129 
00130 #endif // NO_XPCOM_FILE_STREAMS
00131 
00132 //----------------------------------------------------------------------------------------
00133 nsresult NS_NewTypicalInputFileStream(
00134     nsISupports** aStreamResult,
00135     const nsFileSpec& inFile
00136     /*Default nsprMode == PR_RDONLY*/
00137     /*Default accessmode = 0700 (octal)*/);
00138 // Factory method to get an nsInputStream from a file, using most common options
00139 
00140 //----------------------------------------------------------------------------------------
00141 nsresult NS_NewTypicalOutputFileStream(
00142     nsISupports** aStreamResult, // will implement all the above interfaces
00143     const nsFileSpec& inFile
00144     /*default nsprMode= (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE)*/
00145     /*Default accessMode= 0700 (octal)*/);
00146     // Factory method to get an nsOutputStream to a file - most common case.
00147 
00148 //----------------------------------------------------------------------------------------
00149 extern "C" NS_COM_OBSOLETE nsresult NS_NewIOFileStream(
00150     nsISupports** aStreamResult, // will implement all the above interfaces
00151     const nsFileSpec& inFile,
00152     PRInt32 nsprMode,
00153     PRInt32 accessMode);
00154     // Factory method to get an object that implements both nsIInputStream
00155     // and nsIOutputStream, associated with a single file.
00156 
00157 #endif /* nsIFileSpecStream_h___ */