mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
synchronization with native branch
This commit is contained in:
parent
8c15981687
commit
1d4a4082d8
9 changed files with 408 additions and 5 deletions
|
@ -39,11 +39,20 @@ LOCAL_SRC_FILES := \
|
||||||
NativeFormats/JavaPluginCollection.cpp \
|
NativeFormats/JavaPluginCollection.cpp \
|
||||||
NativeFormats/util/AndroidUtil.cpp \
|
NativeFormats/util/AndroidUtil.cpp \
|
||||||
NativeFormats/zlibrary/core/src/encoding/DummyEncodingConverter.cpp \
|
NativeFormats/zlibrary/core/src/encoding/DummyEncodingConverter.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/encoding/EncodingCollectionReader.cpp \
|
||||||
NativeFormats/zlibrary/core/src/encoding/ZLEncodingCollection.cpp \
|
NativeFormats/zlibrary/core/src/encoding/ZLEncodingCollection.cpp \
|
||||||
NativeFormats/zlibrary/core/src/encoding/ZLEncodingConverter.cpp \
|
NativeFormats/zlibrary/core/src/encoding/ZLEncodingConverter.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/encoding/ZLEncodingSet.cpp \
|
||||||
NativeFormats/zlibrary/core/src/filesystem/ZLDir.cpp \
|
NativeFormats/zlibrary/core/src/filesystem/ZLDir.cpp \
|
||||||
NativeFormats/zlibrary/core/src/filesystem/ZLFSManager.cpp \
|
NativeFormats/zlibrary/core/src/filesystem/ZLFSManager.cpp \
|
||||||
NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp \
|
NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/filesystem/ZLInputStreamDecorator.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/filesystem/zip/ZLGzipInputStream.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipDir.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipEntryCache.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipHeader.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipInputStream.cpp \
|
||||||
NativeFormats/zlibrary/core/src/language/ZLCharSequence.cpp \
|
NativeFormats/zlibrary/core/src/language/ZLCharSequence.cpp \
|
||||||
NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.cpp \
|
NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.cpp \
|
||||||
NativeFormats/zlibrary/core/src/language/ZLLanguageList.cpp \
|
NativeFormats/zlibrary/core/src/language/ZLLanguageList.cpp \
|
||||||
|
@ -54,13 +63,17 @@ LOCAL_SRC_FILES := \
|
||||||
NativeFormats/zlibrary/core/src/language/ZLStatisticsXMLReader.cpp \
|
NativeFormats/zlibrary/core/src/language/ZLStatisticsXMLReader.cpp \
|
||||||
NativeFormats/zlibrary/core/src/library/ZLibrary.cpp \
|
NativeFormats/zlibrary/core/src/library/ZLibrary.cpp \
|
||||||
NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp \
|
NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/util/ZLFileUtil.cpp \
|
||||||
NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp \
|
NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp \
|
||||||
NativeFormats/zlibrary/core/src/util/ZLUnicodeUtil.cpp \
|
NativeFormats/zlibrary/core/src/util/ZLUnicodeUtil.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/util/ZLUserData.cpp \
|
||||||
NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.cpp \
|
NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.cpp \
|
||||||
NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp \
|
NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp \
|
||||||
NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp \
|
NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp \
|
||||||
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFSDir.cpp \
|
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFSDir.cpp \
|
||||||
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFSManager.cpp \
|
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFSManager.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.cpp \
|
||||||
NativeFormats/zlibrary/core/src/unix/library/ZLUnixLibrary.cpp \
|
NativeFormats/zlibrary/core/src/unix/library/ZLUnixLibrary.cpp \
|
||||||
NativeFormats/zlibrary/ui/src/android/filesystem/JavaFSDir.cpp \
|
NativeFormats/zlibrary/ui/src/android/filesystem/JavaFSDir.cpp \
|
||||||
NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.cpp \
|
NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.cpp \
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
APP_ABI := armeabi
|
||||||
#APP_ABI := armeabi armeabi-v7a x86 mips mips-r2 mips-r2-sf
|
#APP_ABI := armeabi armeabi-v7a x86 mips mips-r2 mips-r2-sf
|
||||||
APP_ABI := all
|
#APP_ABI := all
|
||||||
APP_STL := stlport_static
|
APP_STL := stlport_static
|
||||||
|
|
|
@ -21,7 +21,9 @@
|
||||||
|
|
||||||
JavaVM *AndroidUtil::ourJavaVM = 0;
|
JavaVM *AndroidUtil::ourJavaVM = 0;
|
||||||
|
|
||||||
|
const char * const AndroidUtil::Class_java_util_Collection = "java/util/Collection";
|
||||||
const char * const AndroidUtil::Class_java_util_Locale = "java/util/Locale";
|
const char * const AndroidUtil::Class_java_util_Locale = "java/util/Locale";
|
||||||
|
const char * const AndroidUtil::Class_java_io_InputStream = "java/io/InputStream";
|
||||||
const char * const AndroidUtil::Class_ZLibrary = "org/geometerplus/zlibrary/core/library/ZLibrary";
|
const char * const AndroidUtil::Class_ZLibrary = "org/geometerplus/zlibrary/core/library/ZLibrary";
|
||||||
const char * const AndroidUtil::Class_NativeFormatPlugin = "org/geometerplus/fbreader/formats/NativeFormatPlugin";
|
const char * const AndroidUtil::Class_NativeFormatPlugin = "org/geometerplus/fbreader/formats/NativeFormatPlugin";
|
||||||
const char * const AndroidUtil::Class_PluginCollection = "org/geometerplus/fbreader/formats/PluginCollection";
|
const char * const AndroidUtil::Class_PluginCollection = "org/geometerplus/fbreader/formats/PluginCollection";
|
||||||
|
@ -29,18 +31,27 @@ const char * const AndroidUtil::Class_ZLFile = "org/geometerplus/zlibrary/core/f
|
||||||
const char * const AndroidUtil::Class_Book = "org/geometerplus/fbreader/library/Book";
|
const char * const AndroidUtil::Class_Book = "org/geometerplus/fbreader/library/Book";
|
||||||
const char * const AndroidUtil::Class_Tag = "org/geometerplus/fbreader/library/Tag";
|
const char * const AndroidUtil::Class_Tag = "org/geometerplus/fbreader/library/Tag";
|
||||||
|
|
||||||
|
jmethodID AndroidUtil::MID_java_util_Collection_toArray;
|
||||||
|
|
||||||
jmethodID AndroidUtil::SMID_java_util_Locale_getDefault;
|
jmethodID AndroidUtil::SMID_java_util_Locale_getDefault;
|
||||||
jmethodID AndroidUtil::MID_java_util_Locale_getLanguage;
|
jmethodID AndroidUtil::MID_java_util_Locale_getLanguage;
|
||||||
|
|
||||||
|
jmethodID AndroidUtil::MID_java_io_InputStream_close;
|
||||||
|
jmethodID AndroidUtil::MID_java_io_InputStream_read;
|
||||||
|
jmethodID AndroidUtil::MID_java_io_InputStream_skip;
|
||||||
|
|
||||||
jmethodID AndroidUtil::SMID_ZLibrary_Instance;
|
jmethodID AndroidUtil::SMID_ZLibrary_Instance;
|
||||||
jmethodID AndroidUtil::MID_ZLibrary_getVersionName;
|
jmethodID AndroidUtil::MID_ZLibrary_getVersionName;
|
||||||
|
|
||||||
jmethodID AndroidUtil::SMID_PluginCollection_Instance;
|
jmethodID AndroidUtil::SMID_PluginCollection_Instance;
|
||||||
|
|
||||||
jmethodID AndroidUtil::MID_ZLFile_size;
|
jmethodID AndroidUtil::SMID_ZLFile_createFileByPath;
|
||||||
|
jmethodID AndroidUtil::MID_ZLFile_children;
|
||||||
jmethodID AndroidUtil::MID_ZLFile_exists;
|
jmethodID AndroidUtil::MID_ZLFile_exists;
|
||||||
jmethodID AndroidUtil::MID_ZLFile_isDirectory;
|
jmethodID AndroidUtil::MID_ZLFile_getInputStream;
|
||||||
jmethodID AndroidUtil::MID_ZLFile_getPath;
|
jmethodID AndroidUtil::MID_ZLFile_getPath;
|
||||||
|
jmethodID AndroidUtil::MID_ZLFile_isDirectory;
|
||||||
|
jmethodID AndroidUtil::MID_ZLFile_size;
|
||||||
|
|
||||||
jfieldID AndroidUtil::FID_Book_File;
|
jfieldID AndroidUtil::FID_Book_File;
|
||||||
jfieldID AndroidUtil::FID_Book_Title;
|
jfieldID AndroidUtil::FID_Book_Title;
|
||||||
|
@ -63,11 +74,22 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
JNIEnv *env = getEnv();
|
JNIEnv *env = getEnv();
|
||||||
jclass cls;
|
jclass cls;
|
||||||
|
|
||||||
|
CHECK_NULL( cls = env->FindClass(Class_java_util_Collection) );
|
||||||
|
CHECK_NULL( MID_java_util_Collection_toArray = env->GetMethodID(cls, "toArray", "()[Ljava/lang/Object;") );
|
||||||
|
//CHECK_NULL( MID_java_util_Collection_add = env->GetMethodID(cls, "add", "(Ljava/lang/Object;)Z") );
|
||||||
|
env->DeleteLocalRef(cls);
|
||||||
|
|
||||||
CHECK_NULL( cls = env->FindClass(Class_java_util_Locale) );
|
CHECK_NULL( cls = env->FindClass(Class_java_util_Locale) );
|
||||||
CHECK_NULL( SMID_java_util_Locale_getDefault = env->GetStaticMethodID(cls, "getDefault", "()Ljava/util/Locale;") );
|
CHECK_NULL( SMID_java_util_Locale_getDefault = env->GetStaticMethodID(cls, "getDefault", "()Ljava/util/Locale;") );
|
||||||
CHECK_NULL( MID_java_util_Locale_getLanguage = env->GetMethodID(cls, "getLanguage", "()Ljava/lang/String;") );
|
CHECK_NULL( MID_java_util_Locale_getLanguage = env->GetMethodID(cls, "getLanguage", "()Ljava/lang/String;") );
|
||||||
env->DeleteLocalRef(cls);
|
env->DeleteLocalRef(cls);
|
||||||
|
|
||||||
|
CHECK_NULL( cls = env->FindClass(Class_java_io_InputStream) );
|
||||||
|
CHECK_NULL( MID_java_io_InputStream_close = env->GetMethodID(cls, "close", "()V") );
|
||||||
|
CHECK_NULL( MID_java_io_InputStream_read = env->GetMethodID(cls, "read", "([BII)I") );
|
||||||
|
CHECK_NULL( MID_java_io_InputStream_skip = env->GetMethodID(cls, "skip", "(J)J") );
|
||||||
|
env->DeleteLocalRef(cls);
|
||||||
|
|
||||||
CHECK_NULL( cls = env->FindClass(Class_ZLibrary) );
|
CHECK_NULL( cls = env->FindClass(Class_ZLibrary) );
|
||||||
CHECK_NULL( SMID_ZLibrary_Instance = env->GetStaticMethodID(cls, "Instance", "()Lorg/geometerplus/zlibrary/core/library/ZLibrary;") );
|
CHECK_NULL( SMID_ZLibrary_Instance = env->GetStaticMethodID(cls, "Instance", "()Lorg/geometerplus/zlibrary/core/library/ZLibrary;") );
|
||||||
CHECK_NULL( MID_ZLibrary_getVersionName = env->GetMethodID(cls, "getVersionName", "()Ljava/lang/String;") );
|
CHECK_NULL( MID_ZLibrary_getVersionName = env->GetMethodID(cls, "getVersionName", "()Ljava/lang/String;") );
|
||||||
|
@ -117,3 +139,24 @@ jstring AndroidUtil::createJavaString(JNIEnv* env, const std::string &str) {
|
||||||
}
|
}
|
||||||
return env->NewStringUTF(str.c_str());
|
return env->NewStringUTF(str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string AndroidUtil::convertNonUtfString(const std::string &str) {
|
||||||
|
const int len = str.length();
|
||||||
|
if (len == 0) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEnv *env = getEnv();
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
jchar *chars = new jchar[len];
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
chars[i] = str[i];
|
||||||
|
}
|
||||||
|
jstring javaString = env->NewString(chars, len);
|
||||||
|
extractJavaString(env, javaString, result);
|
||||||
|
env->DeleteLocalRef(javaString);
|
||||||
|
delete[] chars;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ private:
|
||||||
public:
|
public:
|
||||||
static const char * const Class_java_util_Collection;
|
static const char * const Class_java_util_Collection;
|
||||||
static const char * const Class_java_util_Locale;
|
static const char * const Class_java_util_Locale;
|
||||||
|
static const char * const Class_java_io_InputStream;
|
||||||
static const char * const Class_ZLibrary;
|
static const char * const Class_ZLibrary;
|
||||||
static const char * const Class_ZLFile;
|
static const char * const Class_ZLFile;
|
||||||
static const char * const Class_NativeFormatPlugin;
|
static const char * const Class_NativeFormatPlugin;
|
||||||
|
@ -44,15 +45,20 @@ public:
|
||||||
static jmethodID SMID_java_util_Locale_getDefault;
|
static jmethodID SMID_java_util_Locale_getDefault;
|
||||||
static jmethodID MID_java_util_Locale_getLanguage;
|
static jmethodID MID_java_util_Locale_getLanguage;
|
||||||
|
|
||||||
|
static jmethodID MID_java_io_InputStream_close;
|
||||||
|
static jmethodID MID_java_io_InputStream_read;
|
||||||
|
static jmethodID MID_java_io_InputStream_skip;
|
||||||
|
|
||||||
static jmethodID SMID_ZLibrary_Instance;
|
static jmethodID SMID_ZLibrary_Instance;
|
||||||
static jmethodID MID_ZLibrary_getVersionName;
|
static jmethodID MID_ZLibrary_getVersionName;
|
||||||
|
|
||||||
static jmethodID SMID_ZLFile_createFileByPath;
|
static jmethodID SMID_ZLFile_createFileByPath;
|
||||||
static jmethodID MID_ZLFile_children;
|
static jmethodID MID_ZLFile_children;
|
||||||
static jmethodID MID_ZLFile_size;
|
|
||||||
static jmethodID MID_ZLFile_exists;
|
static jmethodID MID_ZLFile_exists;
|
||||||
static jmethodID MID_ZLFile_isDirectory;
|
static jmethodID MID_ZLFile_getInputStream;
|
||||||
static jmethodID MID_ZLFile_getPath;
|
static jmethodID MID_ZLFile_getPath;
|
||||||
|
static jmethodID MID_ZLFile_isDirectory;
|
||||||
|
static jmethodID MID_ZLFile_size;
|
||||||
|
|
||||||
static jmethodID SMID_PluginCollection_Instance;
|
static jmethodID SMID_PluginCollection_Instance;
|
||||||
|
|
||||||
|
@ -70,6 +76,7 @@ public:
|
||||||
static jobject createZLFile(JNIEnv *env, const std::string &path);
|
static jobject createZLFile(JNIEnv *env, const std::string &path);
|
||||||
static bool extractJavaString(JNIEnv *env, jstring from, std::string &to);
|
static bool extractJavaString(JNIEnv *env, jstring from, std::string &to);
|
||||||
static jstring createJavaString(JNIEnv* env, const std::string &str);
|
static jstring createJavaString(JNIEnv* env, const std::string &str);
|
||||||
|
static std::string convertNonUtfString(const std::string &str);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __ANDROIDUTIL_H__ */
|
#endif /* __ANDROIDUTIL_H__ */
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ZLUnicodeUtil.h>
|
||||||
|
|
||||||
|
#include "EncodingCollectionReader.h"
|
||||||
|
|
||||||
|
static const std::string GROUP = "group";
|
||||||
|
static const std::string ENCODING = "encoding";
|
||||||
|
static const std::string NAME = "name";
|
||||||
|
static const std::string REGION = "region";
|
||||||
|
static const std::string ALIAS = "alias";
|
||||||
|
static const std::string CODE = "code";
|
||||||
|
static const std::string NUMBER = "number";
|
||||||
|
|
||||||
|
ZLEncodingCollectionReader::ZLEncodingCollectionReader(ZLEncodingCollection &collection) : myCollection(collection) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLEncodingCollectionReader::startElementHandler(const char *tag, const char **attributes) {
|
||||||
|
if (GROUP == tag) {
|
||||||
|
const char *name = attributeValue(attributes, NAME.c_str());
|
||||||
|
if (name != 0) {
|
||||||
|
myCurrentSet = new ZLEncodingSet(name);
|
||||||
|
}
|
||||||
|
} else if (!myCurrentSet.isNull()) {
|
||||||
|
if (ENCODING == tag) {
|
||||||
|
const char *name = attributeValue(attributes, NAME.c_str());
|
||||||
|
const char *region = attributeValue(attributes, REGION.c_str());
|
||||||
|
if ((name != 0) && (region != 0)) {
|
||||||
|
const std::string sName = name;
|
||||||
|
myCurrentInfo = new ZLEncodingConverterInfo(sName, region);
|
||||||
|
myNames.push_back(sName);
|
||||||
|
}
|
||||||
|
} else if (!myCurrentInfo.isNull()) {
|
||||||
|
const char *name = 0;
|
||||||
|
if (CODE == tag) {
|
||||||
|
name = attributeValue(attributes, NUMBER.c_str());
|
||||||
|
} else if (ALIAS == tag) {
|
||||||
|
name = attributeValue(attributes, NAME.c_str());
|
||||||
|
}
|
||||||
|
if (name != 0) {
|
||||||
|
const std::string sName = name;
|
||||||
|
myCurrentInfo->addAlias(sName);
|
||||||
|
myNames.push_back(sName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLEncodingCollectionReader::endElementHandler(const char *tag) {
|
||||||
|
if (!myCurrentInfo.isNull() && (ENCODING == tag)) {
|
||||||
|
if (myCurrentInfo->canCreateConverter()) {
|
||||||
|
myCurrentSet->addInfo(myCurrentInfo);
|
||||||
|
for (std::vector<std::string>::const_iterator it = myNames.begin(); it != myNames.end(); ++it) {
|
||||||
|
myCollection.myInfosByName[ZLUnicodeUtil::toLower(*it)] = myCurrentInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myCurrentInfo = 0;
|
||||||
|
myNames.clear();
|
||||||
|
} else if (!myCurrentSet.isNull() && (GROUP == tag)) {
|
||||||
|
if (!myCurrentSet->infos().empty()) {
|
||||||
|
myCollection.mySets.push_back(myCurrentSet);
|
||||||
|
}
|
||||||
|
myCurrentSet = 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ZLInputStream.h"
|
||||||
|
|
||||||
|
ZLInputStreamDecorator::ZLInputStreamDecorator(shared_ptr<ZLInputStream> decoratee) : myBaseStream(decoratee), myBaseOffset(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZLInputStreamDecorator::open() {
|
||||||
|
bool result = myBaseStream->open();
|
||||||
|
myBaseOffset = myBaseStream->offset();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZLInputStreamDecorator::read(char *buffer, size_t maxSize) {
|
||||||
|
myBaseStream->seek(myBaseOffset, true);
|
||||||
|
size_t result = myBaseStream->read(buffer, maxSize);
|
||||||
|
myBaseOffset = myBaseStream->offset();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLInputStreamDecorator::close() {
|
||||||
|
myBaseStream->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLInputStreamDecorator::seek(int offset, bool absoluteOffset) {
|
||||||
|
if (absoluteOffset) {
|
||||||
|
myBaseStream->seek(offset, true);
|
||||||
|
} else {
|
||||||
|
myBaseStream->seek(myBaseOffset + offset, true);
|
||||||
|
}
|
||||||
|
myBaseOffset = myBaseStream->offset();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZLInputStreamDecorator::offset() const {
|
||||||
|
return myBaseOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZLInputStreamDecorator::sizeOfOpened() {
|
||||||
|
return myBaseStream->sizeOfOpened();
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ZLUnixFileInputStream.h"
|
||||||
|
|
||||||
|
ZLUnixFileInputStream::ZLUnixFileInputStream(const std::string &name) : myName(name), myNeedRepositionToStart(false) {
|
||||||
|
myFile = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLUnixFileInputStream::~ZLUnixFileInputStream() {
|
||||||
|
//close();
|
||||||
|
if (myFile != 0) {
|
||||||
|
fclose(myFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZLUnixFileInputStream::open() {
|
||||||
|
//close();
|
||||||
|
if (myFile == 0) {
|
||||||
|
myFile = fopen(myName.c_str(), "rb");
|
||||||
|
} else {
|
||||||
|
//fseek(myFile, 0, SEEK_SET);
|
||||||
|
myNeedRepositionToStart = true;
|
||||||
|
}
|
||||||
|
return myFile != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZLUnixFileInputStream::read(char *buffer, size_t maxSize) {
|
||||||
|
if (buffer != 0) {
|
||||||
|
if (myNeedRepositionToStart) {
|
||||||
|
fseek(myFile, 0, SEEK_SET);
|
||||||
|
myNeedRepositionToStart = false;
|
||||||
|
}
|
||||||
|
return fread(buffer, 1, maxSize, myFile);
|
||||||
|
} else {
|
||||||
|
if (myNeedRepositionToStart) {
|
||||||
|
fseek(myFile, maxSize, SEEK_SET);
|
||||||
|
myNeedRepositionToStart = false;
|
||||||
|
return ftell(myFile);
|
||||||
|
} else {
|
||||||
|
int pos = ftell(myFile);
|
||||||
|
fseek(myFile, maxSize, SEEK_CUR);
|
||||||
|
return ftell(myFile) - pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLUnixFileInputStream::close() {
|
||||||
|
//if (myFile != 0) {
|
||||||
|
// fclose(myFile);
|
||||||
|
// myFile = 0;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZLUnixFileInputStream::sizeOfOpened() {
|
||||||
|
if (myFile == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
long pos = ftell(myFile);
|
||||||
|
fseek(myFile, 0, SEEK_END);
|
||||||
|
long size = ftell(myFile);
|
||||||
|
fseek(myFile, pos, SEEK_SET);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLUnixFileInputStream::seek(int offset, bool absoluteOffset) {
|
||||||
|
if (myNeedRepositionToStart) {
|
||||||
|
absoluteOffset = true;
|
||||||
|
myNeedRepositionToStart = false;
|
||||||
|
}
|
||||||
|
fseek(myFile, offset, absoluteOffset ? SEEK_SET : SEEK_CUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZLUnixFileInputStream::offset() const {
|
||||||
|
return myNeedRepositionToStart ? 0 : ftell(myFile);
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "ZLUnixFileOutputStream.h"
|
||||||
|
|
||||||
|
ZLUnixFileOutputStream::ZLUnixFileOutputStream(const std::string &name) : myName(name), myHasErrors(false), myFile(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLUnixFileOutputStream::~ZLUnixFileOutputStream() {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZLUnixFileOutputStream::open() {
|
||||||
|
close();
|
||||||
|
|
||||||
|
myTemporaryName = myName + ".XXXXXX" + '\0';
|
||||||
|
mode_t currentMask = umask(S_IRWXO | S_IRWXG);
|
||||||
|
int temporaryFileDescriptor = ::mkstemp(const_cast<char*>(myTemporaryName.data()));
|
||||||
|
umask(currentMask);
|
||||||
|
if (temporaryFileDescriptor == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
myFile = fdopen(temporaryFileDescriptor, "w+");
|
||||||
|
return myFile != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLUnixFileOutputStream::write(const char *data, size_t len) {
|
||||||
|
if (::fwrite(data, 1, len, myFile) != len) {
|
||||||
|
myHasErrors = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLUnixFileOutputStream::write(const std::string &str) {
|
||||||
|
if (::fwrite(str.data(), 1, str.length(), myFile) != (size_t)str.length()) {
|
||||||
|
myHasErrors = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLUnixFileOutputStream::close() {
|
||||||
|
if (myFile != 0) {
|
||||||
|
::fclose(myFile);
|
||||||
|
myFile = 0;
|
||||||
|
if (!myHasErrors) {
|
||||||
|
rename(myTemporaryName.c_str(), myName.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
jni/NativeFormats/zlibrary/core/src/util/ZLUserData.cpp
Normal file
39
jni/NativeFormats/zlibrary/core/src/util/ZLUserData.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2008-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ZLUserData.h"
|
||||||
|
|
||||||
|
ZLUserData::~ZLUserData() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLUserDataHolder::~ZLUserDataHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLUserDataHolder::addUserData(const std::string &key, shared_ptr<ZLUserData> data) {
|
||||||
|
myDataMap[key] = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLUserDataHolder::removeUserData(const std::string &key) {
|
||||||
|
myDataMap.erase(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<ZLUserData> ZLUserDataHolder::getUserData(const std::string &key) const {
|
||||||
|
std::map<std::string,shared_ptr<ZLUserData> >::const_iterator it = myDataMap.find(key);
|
||||||
|
return (it != myDataMap.end()) ? it->second : 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue