mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
throws CachedCharStorageException from native code
This commit is contained in:
parent
30f0a850e2
commit
5de272c9d4
5 changed files with 19 additions and 5 deletions
|
@ -250,7 +250,10 @@ JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPl
|
|||
if (!plugin->readModel(*model)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
model->flush();
|
||||
if (!model->flush()) {
|
||||
AndroidUtil::throwCachedCharStorageException("Cannot write file from native code");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if (!initInternalHyperlinks(env, javaModel, *model) || !initTOC(env, javaModel, *model)) {
|
||||
return JNI_FALSE;
|
||||
|
|
|
@ -76,12 +76,19 @@ const shared_ptr<Book> BookModel::book() const {
|
|||
return myBook;
|
||||
}
|
||||
|
||||
void BookModel::flush() {
|
||||
bool BookModel::flush() {
|
||||
myBookTextModel->flush();
|
||||
if (myBookTextModel->allocator().failed()) {
|
||||
return false;
|
||||
}
|
||||
myContentsModel->flush();
|
||||
|
||||
std::map<std::string,shared_ptr<ZLTextModel> >::const_iterator it = myFootnotes.begin();
|
||||
for (; it != myFootnotes.end(); ++it) {
|
||||
it->second->flush();
|
||||
if (it->second->allocator().failed()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
|
||||
const shared_ptr<Book> book() const;
|
||||
|
||||
void flush();
|
||||
bool flush();
|
||||
|
||||
private:
|
||||
const shared_ptr<Book> myBook;
|
||||
|
|
|
@ -36,6 +36,7 @@ ZLCachedMemoryAllocator::ZLCachedMemoryAllocator(const size_t rowSize,
|
|||
myCurrentRowSize(0),
|
||||
myOffset(0),
|
||||
myHasChanges(false),
|
||||
myFailed(false),
|
||||
myDirectoryName(directoryName),
|
||||
myFileExtension(fileExtension) {
|
||||
ZLFile(directoryName).directory(true);
|
||||
|
@ -67,7 +68,7 @@ std::string ZLCachedMemoryAllocator::makeFileName(size_t index) {
|
|||
}
|
||||
|
||||
void ZLCachedMemoryAllocator::writeCache(size_t blockLength) {
|
||||
if (myPool.size() == 0) {
|
||||
if (myFailed || myPool.size() == 0) {
|
||||
return;
|
||||
}
|
||||
const size_t index = myPool.size() - 1;
|
||||
|
@ -75,7 +76,7 @@ void ZLCachedMemoryAllocator::writeCache(size_t blockLength) {
|
|||
ZLFile file(fileName);
|
||||
shared_ptr<ZLOutputStream> stream = file.outputStream();
|
||||
if (stream.isNull() || !stream->open()) {
|
||||
//AndroidUtil::throwCachedCharStorageException("Cannot create file " + fileName);
|
||||
myFailed = true;
|
||||
return;
|
||||
}
|
||||
stream->write(myPool[index], blockLength);
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
const std::string &fileExtension() const;
|
||||
size_t blocksNumber() const;
|
||||
size_t currentBytesOffset() const;
|
||||
bool failed() const;
|
||||
|
||||
private:
|
||||
std::string makeFileName(size_t index);
|
||||
|
@ -58,6 +59,7 @@ private:
|
|||
size_t myOffset;
|
||||
|
||||
bool myHasChanges;
|
||||
bool myFailed;
|
||||
|
||||
const std::string myDirectoryName;
|
||||
const std::string myFileExtension;
|
||||
|
@ -71,6 +73,7 @@ inline const std::string &ZLCachedMemoryAllocator::directoryName() const { retur
|
|||
inline const std::string &ZLCachedMemoryAllocator::fileExtension() const { return myFileExtension; }
|
||||
inline size_t ZLCachedMemoryAllocator::blocksNumber() const { return myPool.size(); }
|
||||
inline size_t ZLCachedMemoryAllocator::currentBytesOffset() const { return myOffset; }
|
||||
inline bool ZLCachedMemoryAllocator::failed() const { return myFailed; }
|
||||
|
||||
inline char *ZLCachedMemoryAllocator::writeUInt16(char *ptr, uint16_t value) {
|
||||
*ptr++ = value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue