activemq-cpp-3.3.0

src/main/decaf/io/InputStream.h

Go to the documentation of this file.
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_INPUTSTREAM_H_
00019 #define _DECAF_IO_INPUTSTREAM_H_
00020 
00021 #include <decaf/io/IOException.h>
00022 #include <decaf/io/Closeable.h>
00023 #include <decaf/util/concurrent/Synchronizable.h>
00024 #include <decaf/util/concurrent/Mutex.h>
00025 #include <decaf/lang/exceptions/UnsupportedOperationException.h>
00026 #include <decaf/lang/exceptions/NullPointerException.h>
00027 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
00028 #include <decaf/util/Config.h>
00029 
00030 namespace decaf{
00031 namespace io{
00032 
00039     class DECAF_API InputStream : public Closeable,
00040                                   virtual public util::concurrent::Synchronizable {
00041     private:
00042 
00043         // Synchronization object.
00044         util::concurrent::Mutex mutex;
00045 
00046     private:
00047 
00048         InputStream( const InputStream& );
00049         InputStream& operator= ( const InputStream& );
00050 
00051     public:
00052 
00053         InputStream();
00054 
00055         virtual ~InputStream();
00056 
00065         virtual void close();
00066 
00083         virtual void mark( int readLimit );
00084 
00112         virtual void reset();
00113 
00123         virtual bool markSupported() const {
00124             return false;
00125         }
00126 
00140         virtual int available() const {
00141             return 0;
00142         }
00143 
00157         virtual int read();
00158 
00187         virtual int read( unsigned char* buffer, int size );
00188 
00234         virtual int read( unsigned char* buffer, int size, int offset, int length );
00235 
00257         virtual long long skip( long long num );
00258 
00266         virtual std::string toString() const;
00267 
00268     protected:  // Virtual doRead methods that can be overridden to customize subclasses.
00269 
00270         virtual int doReadByte() = 0;
00271 
00272         virtual int doReadArray( unsigned char* buffer, int size );
00273 
00274         virtual int doReadArrayBounded( unsigned char* buffer, int size, int offset, int length );
00275 
00276     public:  // Synchronizable
00277 
00278         virtual void lock() {
00279             mutex.lock();
00280         }
00281 
00282         virtual bool tryLock() {
00283             return mutex.tryLock();
00284         }
00285 
00286         virtual void unlock() {
00287             mutex.unlock();
00288         }
00289 
00290         virtual void wait() {
00291             mutex.wait();
00292         }
00293 
00294         virtual void wait( long long millisecs ) {
00295             mutex.wait( millisecs );
00296         }
00297 
00298         virtual void wait( long long millisecs, int nanos ) {
00299             mutex.wait( millisecs, nanos );
00300         }
00301 
00302         virtual void notify() {
00303             mutex.notify();
00304         }
00305 
00306         virtual void notifyAll() {
00307             mutex.notifyAll();
00308         }
00309 
00310     };
00311 
00312 }}
00313 
00314 #endif /*_DECAF_IO_INPUTSTREAM_H_*/