|
activemq-cpp-3.3.0
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (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 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef _DECAF_IO_OUTPUTSTREAM_H 00019 #define _DECAF_IO_OUTPUTSTREAM_H 00020 00021 #include <decaf/io/Closeable.h> 00022 #include <decaf/io/Flushable.h> 00023 #include <decaf/io/IOException.h> 00024 #include <decaf/util/concurrent/Synchronizable.h> 00025 #include <decaf/util/concurrent/Mutex.h> 00026 #include <decaf/util/Config.h> 00027 00028 #include <decaf/lang/exceptions/NullPointerException.h> 00029 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h> 00030 00031 namespace decaf{ 00032 namespace io{ 00033 00039 class DECAF_API OutputStream : public Closeable, 00040 public Flushable, 00041 public util::concurrent::Synchronizable 00042 { 00043 private: 00044 00045 // Synchronization object. 00046 util::concurrent::Mutex mutex; 00047 00048 private: 00049 00050 OutputStream( const OutputStream& ); 00051 OutputStream& operator= ( const OutputStream& ); 00052 00053 public: 00054 00055 OutputStream(); 00056 00057 virtual ~OutputStream(); 00058 00064 virtual void close(); 00065 00071 virtual void flush(); 00072 00084 virtual void write( unsigned char c ); 00085 00104 virtual void write( const unsigned char* buffer, int size ); 00105 00130 virtual void write( const unsigned char* buffer, int size, int offset, int length ); 00131 00139 virtual std::string toString() const; 00140 00141 protected: 00142 00143 virtual void doWriteByte( unsigned char value ) = 0; 00144 00145 virtual void doWriteArray( const unsigned char* buffer, int size ); 00146 00147 virtual void doWriteArrayBounded( const unsigned char* buffer, int size, int offset, int length ); 00148 00149 public: // Synchronizable 00150 00151 virtual void lock() { 00152 mutex.lock(); 00153 } 00154 00155 virtual bool tryLock() { 00156 return mutex.tryLock(); 00157 } 00158 00159 virtual void unlock() { 00160 mutex.unlock(); 00161 } 00162 00163 virtual void wait() { 00164 mutex.wait(); 00165 } 00166 00167 virtual void wait( long long millisecs ) { 00168 mutex.wait( millisecs ); 00169 } 00170 00171 virtual void wait( long long millisecs, int nanos ) { 00172 mutex.wait( millisecs, nanos ); 00173 } 00174 00175 virtual void notify() { 00176 mutex.notify(); 00177 } 00178 00179 virtual void notifyAll() { 00180 mutex.notifyAll(); 00181 } 00182 00183 }; 00184 00185 }} 00186 00187 #endif /*_DECAF_IO_OUTPUTSTREAM_H*/