1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 #if !defined(XALANFILEOUTPUTSTREAM_HEADER_GUARD_1357924680) 19 #define XALANFILEOUTPUTSTREAM_HEADER_GUARD_1357924680 20 21 22 23 // Base include file. Must be first. 24 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 25 26 27 28 #if defined(XALAN_WINDOWS) 29 #include <windows.h> 30 #else 31 #include <cstdio> 32 #endif 33 34 35 36 // Base class header file. 37 #include <xalanc/PlatformSupport/XalanOutputStream.hpp> 38 39 40 41 namespace XALAN_CPP_NAMESPACE { 42 43 44 using std::FILE; 45 46 class XALAN_PLATFORMSUPPORT_EXPORT XalanFileOutputStream : public XalanOutputStream 47 { 48 public : 49 50 enum { eDefaultBufferSize = 8192u }; 51 52 #if defined(XALAN_WINDOWS) 53 typedef HANDLE HandleType; 54 #else 55 typedef FILE* HandleType; 56 #endif 57 58 /** 59 * Construct an XalanFileOutputStream object. 60 * 61 * @param theFileName name of file 62 * @param theBufferSize The size of the transcoding buffer 63 */ 64 XalanFileOutputStream( 65 const XalanDOMString& theFileName, 66 MemoryManager& theManager, 67 size_type theBufferSize = eDefaultBufferSize); 68 69 static XalanFileOutputStream* 70 create( 71 const XalanDOMString& theFileName, 72 MemoryManager& theManager, 73 size_type theBufferSize = eDefaultBufferSize); 74 virtual 75 ~XalanFileOutputStream(); 76 77 78 class XALAN_PLATFORMSUPPORT_EXPORT XalanFileOutputStreamOpenException : public XalanOutputStream::XalanOutputStreamException 79 { 80 public: 81 82 /** 83 * Construct an XalanFileOutputStreamOpen exception object for an exception 84 * that occurred on opening a text file stream. 85 * 86 * @param theFileName name of file causing the exception 87 * @param theErrorCode number of error encountered 88 */ 89 XalanFileOutputStreamOpenException( 90 const XalanDOMString& theFileName, 91 int theErrorCode, 92 XalanDOMString& theBuffer, 93 const Locator* theLocator = 0); 94 95 virtual 96 ~XalanFileOutputStreamOpenException(); 97 98 virtual const XalanDOMChar* getType() const99 getType() const 100 { 101 return m_type; 102 } 103 104 private: 105 106 static const XalanDOMChar m_type[]; 107 108 }; 109 110 class XALAN_PLATFORMSUPPORT_EXPORT XalanFileOutputStreamWriteException : public XalanOutputStream::XalanOutputStreamException 111 { 112 public: 113 114 /** 115 * Construct an XalanFileOutputStreamOpen exception object for an exception 116 * that occurred while writing to a text file stream. 117 * 118 * @param theFileName name of file causing the exception 119 * @param theErrorCode number of error encountered 120 */ 121 XalanFileOutputStreamWriteException( 122 const XalanDOMString& theFileName, 123 int theErrorCode, 124 XalanDOMString& theBuffer, 125 const Locator* theLocator = 0); 126 127 virtual 128 ~XalanFileOutputStreamWriteException(); 129 130 virtual const XalanDOMChar* getType() const131 getType() const 132 { 133 return m_type; 134 } 135 136 private: 137 static const XalanDOMChar m_type[]; 138 139 }; 140 141 protected: 142 143 virtual void 144 writeData( 145 const char* theBuffer, 146 size_type theBufferLength); 147 148 virtual void 149 doFlush(); 150 151 private: 152 153 // These are not implemented... 154 XalanFileOutputStream(const XalanFileOutputStream&); 155 156 XalanFileOutputStream& 157 operator=(const XalanFileOutputStream&); 158 159 bool 160 operator==(const XalanFileOutputStream&) const; 161 162 163 // Data members... 164 const XalanDOMString m_fileName; 165 166 const HandleType m_handle; 167 }; 168 169 170 171 } 172 173 174 175 #endif // XALANFILEOUTPUTSTREAM_HEADER_GUARD_1357924680 176