[android] Switched from FileReader to MmapReader

This commit is contained in:
Alex Zolotarev 2012-01-04 14:12:44 +03:00 committed by Alex Zolotarev
parent f8be0cd10f
commit 0e6cfcbd35
5 changed files with 21 additions and 10 deletions

View file

@ -34,7 +34,7 @@ UNIT_TEST(ZipReaderSmoke)
r.ReadAsString(s);
TEST_EQUAL(s, "Test\n", ("Invalid zip file contents"));
}
catch (FileReader::Exception const & e)
catch (std::exception const & e)
{
noException = false;
LOG(LERROR, (e.what()));
@ -47,7 +47,7 @@ UNIT_TEST(ZipReaderSmoke)
{
ZipFileReader r("some_nonexisting_filename", "test.txt");
}
catch (FileReader::Exception const &)
catch (std::exception const &)
{
noException = false;
}
@ -59,7 +59,7 @@ UNIT_TEST(ZipReaderSmoke)
{
ZipFileReader r(ZIPFILE, "test");
}
catch (FileReader::Exception const &)
catch (std::exception const &)
{
noException = false;
}
@ -110,7 +110,7 @@ UNIT_TEST(ZipFilesList)
TEST_EQUAL(files[1], "2.txt", ());
TEST_EQUAL(files[2], "3.ttt", ());
}
catch (FileReader::OpenException const & e)
catch (std::exception const & e)
{
TEST(false, ("Can't get list of files inside zip", e.what()));
}
@ -120,7 +120,7 @@ UNIT_TEST(ZipFilesList)
vector<string> files = ZipFileReader::FilesList(ZIPFILE_INVALID);
TEST(false, ("This test shouldn't be reached - exception should be thrown"));
}
catch (FileReader::OpenException const &)
catch (std::exception const &)
{
}

View file

@ -89,3 +89,10 @@ uint8_t * MmapReader::Data() const
{
return m_data->m_memory;
}
void MmapReader::SetOffsetAndSize(uint64_t offset, uint64_t size)
{
ASSERT_LESS_OR_EQUAL(offset + size, Size(), (offset, size));
m_offset = offset;
m_size = size;
}

View file

@ -25,4 +25,8 @@ public:
/// Direct file/memory access
uint8_t * Data() const;
protected:
// Used in special derived readers.
void SetOffsetAndSize(uint64_t offset, uint64_t size);
};

View file

@ -1,12 +1,12 @@
#pragma once
#include "file_reader.hpp"
#include "mmap_reader.hpp"
#include "../base/exception.hpp"
class ZipFileReader : public FileReader
class ZipFileReader : public MmapReader
{
typedef FileReader base_type;
typedef MmapReader base_type;
public:
DECLARE_EXCEPTION(OpenZipException, OpenException);

View file

@ -1,6 +1,6 @@
#include "platform.hpp"
#include "../coding/file_reader.hpp"
#include "../coding/mmap_reader.hpp"
#include "../coding/zip_reader.hpp"
#include <dirent.h>
@ -23,7 +23,7 @@ bool Platform::IsFileExistsByFullPath(string const & filePath)
ModelReader * Platform::GetReader(string const & file) const
{
if (IsFileExistsByFullPath(m_writableDir + file))
return new FileReader(ReadPathForFile(file), 10, 12);
return new MmapReader(ReadPathForFile(file));
else
{
ASSERT_EQUAL(file.find("assets/"), string::npos, ("Do not use assets/, only file name"));