summaryrefslogtreecommitdiffstats
blob: b3a5d8d9e36abe17f284893b30eac4df4658022b (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
#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();
}

}