1 /* 2 * Copyright 2011 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _BUFFERED_DATA_IO_H 6 #define _BUFFERED_DATA_IO_H 7 8 9 #include <DataIO.h> 10 11 12 class BBufferedDataIO : public BDataIO { 13 public: 14 BBufferedDataIO(BDataIO& stream, 15 size_t bufferSize = 65536L, 16 bool ownsStream = true, 17 bool partialReads = false); 18 virtual ~BBufferedDataIO(); 19 20 status_t InitCheck() const; 21 22 BDataIO* Stream() const; 23 size_t BufferSize() const; 24 bool OwnsStream() const; 25 void SetOwnsStream(bool ownsStream); 26 status_t Flush(); 27 28 // BDataIO interface 29 virtual ssize_t Read(void* buffer, size_t size); 30 virtual ssize_t Write(const void* buffer, size_t size); 31 32 private: 33 BBufferedDataIO(const BBufferedDataIO& other); 34 // not implemented 35 36 virtual status_t _Reserved0(void*); 37 virtual status_t _Reserved1(void*); 38 virtual status_t _Reserved2(void*); 39 virtual status_t _Reserved3(void*); 40 virtual status_t _Reserved4(void*); 41 42 private: 43 BDataIO& fStream; 44 uint8* fBuffer; 45 size_t fBufferSize; 46 size_t fPosition; 47 size_t fSize; 48 49 uint32 _reserved_ints[4]; 50 51 bool fDirty; 52 bool fOwnsStream; 53 bool fPartialReads; 54 55 bool _reserved_bools[5]; 56 }; 57 58 59 #endif // _BUFFERED_DATA_IO_H 60