| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_IO_STRINGSTREAM_H |
| 18 |
#define AAPT_IO_STRINGSTREAM_H |
| 19 |
|
| 20 |
#include "io/Io.h" |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
|
| 24 |
#include "android-base/macros.h" |
| 25 |
#include "androidfw/StringPiece.h" |
| 26 |
|
| 27 |
namespace aapt { |
| 28 |
namespace io { |
| 29 |
|
| 30 |
class StringInputStream : public KnownSizeInputStream { |
| 31 |
public: |
| 32 |
explicit StringInputStream(const android::StringPiece& str); |
| 33 |
|
| 34 |
bool Next(const void** data, size_t* size) override; |
| 35 |
|
| 36 |
void BackUp(size_t count) override; |
| 37 |
|
| 38 |
size_t ByteCount() const override; |
| 39 |
|
| 40 |
inline bool HadError() const override { |
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
inline std::string GetError() const override { |
| 45 |
return {}; |
| 46 |
} |
| 47 |
|
| 48 |
size_t TotalSize() const override; |
| 49 |
|
| 50 |
private: |
| 51 |
DISALLOW_COPY_AND_ASSIGN(StringInputStream); |
| 52 |
|
| 53 |
android::StringPiece str_; |
| 54 |
size_t offset_; |
| 55 |
}; |
| 56 |
|
| 57 |
class StringOutputStream : public OutputStream { |
| 58 |
public: |
| 59 |
explicit StringOutputStream(std::string* str, size_t buffer_capacity = 4096u); |
| 60 |
|
| 61 |
~StringOutputStream(); |
| 62 |
|
| 63 |
bool Next(void** data, size_t* size) override; |
| 64 |
|
| 65 |
void BackUp(size_t count) override; |
| 66 |
|
| 67 |
void Flush(); |
| 68 |
|
| 69 |
size_t ByteCount() const override; |
| 70 |
|
| 71 |
inline bool HadError() const override { |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
inline std::string GetError() const override { |
| 76 |
return {}; |
| 77 |
} |
| 78 |
|
| 79 |
private: |
| 80 |
DISALLOW_COPY_AND_ASSIGN(StringOutputStream); |
| 81 |
|
| 82 |
void FlushImpl(); |
| 83 |
|
| 84 |
std::string* str_; |
| 85 |
size_t buffer_capacity_; |
| 86 |
size_t buffer_offset_; |
| 87 |
std::unique_ptr<char[]> buffer_; |
| 88 |
}; |
| 89 |
|
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
#endif |