blob: 36cc19c26fd681dfa3d6fb28f2374afab445c556 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "Swiften/Base/ByteArray.h"
#include <fstream>
std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s) {
std::ios::fmtflags oldFlags = os.flags();
os << std::hex;
for (Swift::ByteArray::const_iterator i = s.begin(); i != s.end(); ++i) {
os << "0x" << static_cast<unsigned int>(static_cast<unsigned char>(*i));
if (i + 1 < s.end()) {
os << " ";
}
}
os << std::endl;
os.flags(oldFlags);
return os;
}
namespace Swift {
static const int BUFFER_SIZE = 4096;
void ByteArray::readFromFile(const String& file) {
std::ifstream input(file.getUTF8Data(), std::ios_base::in|std::ios_base::binary);
while (input.good()) {
size_t oldSize = data_.size();
data_.resize(oldSize + BUFFER_SIZE);
input.read(&data_[oldSize], BUFFER_SIZE);
data_.resize(oldSize + input.gcount());
}
input.close();
}
}
|