00001 /* Copyright (c) 2006, Gennady Bystritsky <bystr@mac.com> 00002 * 00003 * Distributed under the MIT Licence. 00004 * This is free software. See 'LICENSE' for details. 00005 * You must read and accept the license prior to use. 00006 */ 00007 00008 #ifndef _SK_IO_BYTEARRAYINPUTSTREAM_ 00009 #define _SK_IO_BYTEARRAYINPUTSTREAM_ 00010 00011 #include <sk/io/AbstractInputStream.h> 00012 #include <sk/util/Holder.hxx> 00013 #include <vector> 00014 00015 namespace sk { 00016 namespace io { 00017 class ByteArrayInputStream 00018 : public sk::io::AbstractInputStream 00019 { 00020 public: 00021 ByteArrayInputStream(const char* buffer, int size); 00022 ByteArrayInputStream(const std::vector<char>& buffer); 00023 virtual ~ByteArrayInputStream(); 00024 00025 // sk::util::Object re-implementation. 00026 const sk::util::Class getClass() const; 00027 00028 // sk::io::InputStream implementation. 00029 int read(char* buffer, int offset, int length); 00030 using AbstractInputStream::read; 00031 void close(); 00032 long long available() const; 00033 bool markSupported() const; 00034 int skip(int number); 00035 void mark(int readlimit); 00036 void reset(); 00037 00038 private: 00039 ByteArrayInputStream(const ByteArrayInputStream& other); 00040 ByteArrayInputStream& operator = (const ByteArrayInputStream& other); 00041 00042 void init(); 00043 void initMark(); 00044 00045 sk::util::Holder<const std::vector<char> > _bufferHolder; 00046 bool _closed; 00047 int _cursor; 00048 int _mark; 00049 int _markDistance; 00050 }; 00051 } 00052 } 00053 00054 #endif /* _SK_IO_BYTEARRAYINPUTSTREAM_ */