本文整理汇总了C++中IODevice::receive方法的典型用法代码示例。如果您正苦于以下问题:C++ IODevice::receive方法的具体用法?C++ IODevice::receive怎么用?C++ IODevice::receive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IODevice
的用法示例。
在下文中一共展示了IODevice::receive方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buffer
XMLTokenizer::XMLTokenizer(IODevice &input) : impl(new XMLTokenizer_Impl)
{
impl->input = input;
impl->size = input.get_size();
impl->pos = 0;
DataBuffer buffer(impl->size);
input.receive(buffer.get_data(), buffer.get_size(), true);
StringHelp::BOMType bom_type = StringHelp::detect_bom(buffer.get_data(), buffer.get_size());
switch (bom_type)
{
default:
case StringHelp::bom_none:
impl->data = StringHelp::utf8_to_text(std::string(buffer.get_data(), buffer.get_size()));
break;
case StringHelp::bom_utf32_be:
case StringHelp::bom_utf32_le:
throw Exception("UTF-16 XML files not supported yet");
break;
case StringHelp::bom_utf16_be:
case StringHelp::bom_utf16_le:
throw Exception("UTF-32 XML files not supported yet");
break;
case StringHelp::bom_utf8:
impl->data = StringHelp::utf8_to_text(std::string(buffer.get_data()+3, buffer.get_size()-3));
break;
}
}
示例2: deflate_read
int64_t ZipReader_Impl::deflate_read(void *data, int64_t size, bool read_all)
{
zs.next_out = (unsigned char *)data;
zs.avail_out = size;
// Continue feeding zlib data until we get our data:
while (zs.avail_out > 0)
{
// zlib needs more data:
if (zs.avail_in == 0 && compressed_pos < local_header.compressed_size)
{
// Read some compressed data:
int received_input = 0;
while (received_input < 16 * 1024)
{
received_input += input.receive(zbuffer, int(min((int64_t)16 * 1024, local_header.compressed_size - compressed_pos)), true);
if (compressed_pos + received_input == local_header.compressed_size) break;
}
compressed_pos += received_input;
zs.next_in = (unsigned char *)zbuffer;
zs.avail_in = received_input;
}
// Decompress data:
int result = mz_inflate(&zs, (compressed_pos == local_header.compressed_size) ? MZ_FINISH : MZ_NO_FLUSH);
if (result == MZ_STREAM_END) break;
if (result == MZ_NEED_DICT) throw Exception("Zlib inflate wants a dictionary!");
if (result == MZ_DATA_ERROR) throw Exception("Zip data stream is corrupted");
if (result == MZ_STREAM_ERROR) throw Exception("Zip stream structure was inconsistent!");
if (result == MZ_MEM_ERROR) throw Exception("Zlib did not have enough memory to decompress file!");
if (result == MZ_BUF_ERROR) throw Exception("Not enough data in buffer when Z_FINISH was used");
if (result != MZ_OK) throw Exception("Zlib inflate failed while decompressing zip file!");
}
return size - zs.avail_out;
}
示例3: cwd
void TestApp::test_virtual_directory_part2(void)
{
Console::write_line(" (Using FileSystem)");
std::string str;
std::string cwd(working_dir);
FileSystem vfs("../../Core/");
//*** testing get_directory_listing()
Console::write_line(" Function: DirectoryListing get_directory_listing()");
DirectoryListing listing = vfs.get_directory_listing("");
do
{
if (!listing.next()) fail();
str = listing.get_filename();
}while(str != "IOData");
//*** testing open_file()
Console::write_line(" Function: IODevice Directory::open_file()");
if(true)
{
IODevice device = vfs.open_file("IOData/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
char test_data[4];
if (device.receive(test_data, 4, true) != 4) fail();
if ( (test_data[0] != '/') || (test_data[1] != '*') ) fail();
}
//*** testing mount(const std::string &mount_point, const std::string &path)
Console::write_line(" Function: mount(const std::string &mount_point, const std::string &path)");
if(true)
{
FileSystem vfs("somewhere");
vfs.mount("ABC", "../../Core/IOData", false);
IODevice device = vfs.open_file("ABC/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
}
//*** testing mount(const std::string &mount_point, FileSystem &fs)
Console::write_line(" Function: mount(const std::string &mount_point, FileSystem &fs)");
if(true)
{
FileSystem new_vfs(new MyFileSource("Hello/"));
IODevice device = new_vfs.open_file("ABC/World", File::open_existing, File::access_read, File::share_all, 0);
if (MyFileSource::fullname != "Hello/ABC/World") fail();
}
//*** testing unmount(const std::string &mount_point)
Console::write_line(" Function: unmount(const std::string &mount_point)");
if(true)
{
FileSystem vfs("./");
vfs.mount("ABC", "../../Core/IOData", false);
vfs.mount("DEF", "../../Core/IOData", false);
vfs.mount("GHI", "../../Core/IOData", false);
vfs.open_file("ABC/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
vfs.open_file("DEF/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
vfs.open_file("GHI/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
vfs.unmount("DEF");
vfs.unmount("WWW");
vfs.open_file("ABC/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
vfs.open_file("GHI/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
try
{
vfs.open_file("DEF/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
fail(); // Exception should have been called
}
catch (Exception errror)
{
}
vfs.unmount("ABC");
vfs.unmount("GHI");
try
{
vfs.open_file("ABC/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
vfs.open_file("GHI/test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
fail(); // Exception should have been called
}
catch (Exception errror)
{
}
vfs.open_file("test_virtual_directory.cpp", File::open_existing, File::access_read, File::share_all, 0);
}
}