本文整理汇总了C++中ZLInputStream::read方法的典型用法代码示例。如果您正苦于以下问题:C++ ZLInputStream::read方法的具体用法?C++ ZLInputStream::read怎么用?C++ ZLInputStream::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZLInputStream
的用法示例。
在下文中一共展示了ZLInputStream::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: detectLanguage
void FormatPlugin::detectLanguage(Book &book, ZLInputStream &stream) {
std::string language = book.language();
if (!language.empty()) {
return;
}
PluginCollection &collection = PluginCollection::Instance();
if (language.empty()) {
language = collection.DefaultLanguageOption.value();
}
if (collection.LanguageAutoDetectOption.value() && stream.open()) {
static const int BUFSIZE = 65536;
char *buffer = new char[BUFSIZE];
const size_t size = stream.read(buffer, BUFSIZE);
stream.close();
shared_ptr<ZLLanguageDetector::LanguageInfo> info =
ZLLanguageDetector().findInfo(buffer, size);
delete[] buffer;
if (!info.isNull()) {
if (!info->Language.empty()) {
language = info->Language;
}
}
}
book.setLanguage(language);
}
示例2: entryName
ZLZipEntryCache::ZLZipEntryCache(const std::string &containerName, ZLInputStream &containerStream) : myContainerName(containerName) {
//ZLLogger::Instance().println("ZipEntryCache", "creating cache for " + containerName);
myLastModifiedTime = ZLFile(containerName).lastModified();
if (!containerStream.open()) {
return;
}
ZLZipHeader header;
while (header.readFrom(containerStream)) {
Info *infoPtr = 0;
if (header.Signature == (unsigned long)ZLZipHeader::SignatureLocalFile) {
std::string entryName(header.NameLength, '\0');
if ((unsigned int)containerStream.read((char*)entryName.data(), header.NameLength) == header.NameLength) {
entryName = AndroidUtil::convertNonUtfString(entryName);
Info &info = myInfoMap[entryName];
info.Offset = containerStream.offset() + header.ExtraLength;
info.CompressionMethod = header.CompressionMethod;
info.CompressedSize = header.CompressedSize;
info.UncompressedSize = header.UncompressedSize;
infoPtr = &info;
}
}
ZLZipHeader::skipEntry(containerStream, header);
if (infoPtr != 0) {
infoPtr->UncompressedSize = header.UncompressedSize;
}
}
containerStream.close();
}
示例3: entryName
ZLZipEntryCache::ZLZipEntryCache(ZLInputStream &baseStream) {
if (!baseStream.open()) {
return;
}
ZLZipHeader header;
while (header.readFrom(baseStream)) {
Info *infoPtr = 0;
if (header.Signature == ZLZipHeader::SignatureLocalFile) {
std::string entryName(header.NameLength, '\0');
if ((unsigned int)baseStream.read((char*)entryName.data(), header.NameLength) == header.NameLength) {
Info &info = myInfoMap[entryName];
info.Offset = baseStream.offset() + header.ExtraLength;
info.CompressionMethod = header.CompressionMethod;
info.CompressedSize = header.CompressedSize;
info.UncompressedSize = header.UncompressedSize;
infoPtr = &info;
}
}
ZLZipHeader::skipEntry(baseStream, header);
if (infoPtr != 0) {
infoPtr->UncompressedSize = header.UncompressedSize;
}
}
baseStream.close();
}
示例4: detectLanguage
bool FormatPlugin::detectLanguage(Book &book, ZLInputStream &stream, const std::string &encoding, bool force) {
std::string language = book.language();
if (!force && !language.empty()) {
return true;
}
bool detected = false;
PluginCollection &collection = PluginCollection::Instance();
if (collection.isLanguageAutoDetectEnabled() && stream.open()) {
static const int BUFSIZE = 65536;
char *buffer = new char[BUFSIZE];
const std::size_t size = stream.read(buffer, BUFSIZE);
stream.close();
shared_ptr<ZLLanguageDetector::LanguageInfo> info =
ZLLanguageDetector().findInfoForEncoding(encoding, buffer, size, -20000);
delete[] buffer;
if (!info.isNull()) {
detected = true;
if (!info->Language.empty()) {
language = info->Language;
}
}
}
book.setLanguage(language);
return detected;
}
示例5: decompress
size_t HuffDecompressor::decompress(ZLInputStream &stream, char *targetBuffer, size_t compressedSize, size_t maxUncompressedSize) {
if (compressedSize == 0 || myErrorCode == ERROR_CORRUPTED_FILE) {
return 0;
}
if (targetBuffer != 0) {
unsigned char *sourceBuffer = new unsigned char[compressedSize];
myTargetBuffer = targetBuffer;
myTargetBufferEnd = targetBuffer + maxUncompressedSize;
myTargetBufferPtr = targetBuffer;
if (stream.read((char*)sourceBuffer, compressedSize) == compressedSize) {
const size_t trailSize = sizeOfTrailingEntries(sourceBuffer, compressedSize);
if (trailSize < compressedSize) {
bitsDecompress(BitReader(sourceBuffer, compressedSize - trailSize));
} else {
myErrorCode = ERROR_CORRUPTED_FILE;
}
}
delete[] sourceBuffer;
} else {
myTargetBuffer = 0;
myTargetBufferEnd = 0;
myTargetBufferPtr = 0;
}
return myTargetBufferPtr - myTargetBuffer;
}
示例6: detectEncodingAndLanguage
void FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream) {
std::string language = book.language();
std::string encoding = book.encoding();
if (!encoding.empty() && !language.empty()) {
return;
}
PluginCollection &collection = PluginCollection::Instance();
if (language.empty()) {
language = collection.DefaultLanguageOption.value();
}
if (encoding.empty()) {
encoding = collection.DefaultEncodingOption.value();
}
if (collection.LanguageAutoDetectOption.value() && stream.open()) {
static const int BUFSIZE = 65536;
char *buffer = new char[BUFSIZE];
const size_t size = stream.read(buffer, BUFSIZE);
stream.close();
shared_ptr<ZLLanguageDetector::LanguageInfo> info =
ZLLanguageDetector().findInfo(buffer, size);
delete[] buffer;
if (!info.isNull()) {
if (!info->Language.empty()) {
language = info->Language;
}
encoding = info->Encoding;
if ((encoding == "US-ASCII") || (encoding == "ISO-8859-1")) {
encoding = "windows-1252";
}
}
}
book.setEncoding(encoding);
book.setLanguage(language);
}
示例7: decompress
size_t DocDecompressor::decompress(ZLInputStream &stream, char *targetBuffer, size_t compressedSize, size_t maxUncompressedSize) {
const unsigned char *sourceBuffer = new unsigned char[compressedSize];
const unsigned char *sourceBufferEnd = sourceBuffer + compressedSize;
const unsigned char *sourcePtr = sourceBuffer;
unsigned char *targetBufferEnd = (unsigned char*)targetBuffer + maxUncompressedSize;
unsigned char *targetPtr = (unsigned char*)targetBuffer;
if (stream.read((char*)sourceBuffer, compressedSize) == compressedSize) {
unsigned char token;
unsigned short copyLength, N, shift;
unsigned char *shifted;
while ((sourcePtr < sourceBufferEnd) && (targetPtr < targetBufferEnd)) {
token = *(sourcePtr++);
switch (TOKEN_CODE[token]) {
case 0:
*(targetPtr++) = token;
break;
case 1:
if ((sourcePtr + token > sourceBufferEnd) || (targetPtr + token > targetBufferEnd)) {
goto endOfLoop;
}
memcpy(targetPtr, sourcePtr, token);
sourcePtr += token;
targetPtr += token;
break;
case 2:
if (targetPtr + 2 > targetBufferEnd) {
goto endOfLoop;
}
*(targetPtr++) = ' ';
*(targetPtr++) = token ^ 0x80;
break;
case 3:
if (sourcePtr + 1 > sourceBufferEnd) {
goto endOfLoop;
}
N = 256 * token + *(sourcePtr++);
copyLength = (N & 7) + 3;
if (targetPtr + copyLength > targetBufferEnd) {
goto endOfLoop;
}
shift = (N & 0x3fff) / 8;
shifted = targetPtr - shift;
if ((char*)shifted >= targetBuffer) {
for (short i = 0; i < copyLength; i++) {
*(targetPtr++) = *(shifted++);
}
}
break;
}
}
}
endOfLoop:
delete[] sourceBuffer;
return targetPtr - (unsigned char*)targetBuffer;
}
示例8: read
bool ZLTarHeader::read(ZLInputStream &stream) {
size_t startOffset = stream.offset();
char fileName[101];
stream.read(fileName, 100);
if (fileName[0] == '\0') {
return false;
}
fileName[100] = '\0';
if (Name.empty()) {
Name = fileName;
}
stream.seek(24, false);
char fileSizeString[12];
stream.read(fileSizeString, 12);
Size = 0;
for (int i = 0; i < 12; ++i) {
if (!isdigit(fileSizeString[i])) {
break;
}
Size *= 8;
Size += fileSizeString[i] - '0';
}
stream.seek(20, false);
char linkFlag;
stream.read(&linkFlag, 1);
IsRegularFile = (linkFlag == '\0') || (linkFlag == '0');
stream.seek(355, false);
if (((linkFlag == 'L') || (linkFlag == 'K')) && (Name == "././@LongLink") && (Size < 10240)) {
Name.erase();
Name.append(Size - 1, '\0');
stream.read(const_cast<char*>(Name.data()), Size - 1);
const int skip = 512 - (Size & 0x1ff);
stream.seek(skip + 1, false);
return (stream.offset() == startOffset + Size + skip + 512) && read(stream);
} else {
DataOffset = stream.offset();
return DataOffset == startOffset + 512;
}
}
示例9: readUnsignedLongLE
void PdbUtil::readUnsignedLongLE(ZLInputStream &stream, unsigned long &N) {
unsigned char data[4];
stream.read((char*)data, 4);
N = (((unsigned long)data[3]) << 24) +
(((unsigned long)data[2]) << 16) +
(((unsigned long)data[1]) << 8) +
(unsigned long)data[0];
}
示例10: readUnsignedWord
static unsigned short readUnsignedWord(ZLInputStream &stream) {
unsigned char buffer[2];
stream.read((char*)buffer, 2);
unsigned short result = buffer[1];
result = result << 8;
result += buffer[0];
return result;
}
示例11: readUnsignedShort
void PdbUtil::readUnsignedShort(ZLInputStream &stream, unsigned short &N) {
unsigned char data[2];
stream.read((char*)data, 2);
N = (((unsigned short)data[0]) << 8) + data[1];
/*
stream.read((char*)&N + 1, 1);
stream.read((char*)&N, 1);
*/
}
示例12: readEncodedInteger
static unsigned long long readEncodedInteger(ZLInputStream &stream) {
unsigned long long result = 0;
char part;
do {
result = result << 7;
stream.read(&part, 1);
result += part & 0x7F;
} while (part & -0x80);
return result;
}
示例13: readLong
unsigned long ZLZipHeader::readLong(ZLInputStream &stream) {
char buffer[4];
stream.read(buffer, 4);
return
((((unsigned long)buffer[3]) & 0xFF) << 24) +
((((unsigned long)buffer[2]) & 0xFF) << 16) +
((((unsigned long)buffer[1]) & 0xFF) << 8) +
((unsigned long)buffer[0] & 0xFF);
}
示例14: fullReference
static std::string readNTString(ZLInputStream &stream) {
std::string s;
char c;
while (stream.read(&c, 1) == 1) {
if (c == '\0') {
break;
} else {
s += c;
}
}
return CHMReferenceCollection::fullReference("/", s);
}
示例15: readDocument
void TxtReader::readDocument(ZLInputStream &stream) {
if (!stream.open()) {
return;
}
startDocumentHandler();
const size_t BUFSIZE = 2048;
char *buffer = new char[BUFSIZE];
std::string str;
size_t length;
do {
length = stream.read(buffer, BUFSIZE);
char *start = buffer;
const char *end = buffer + length;
for (char *ptr = start; ptr != end; ++ptr) {
if (*ptr == '\n' || *ptr == '\r') {
bool skipNewLine = false;
if (*ptr == '\r' && (ptr + 1) != end && *(ptr + 1) == '\n') {
skipNewLine = true;
*ptr = '\n';
}
if (start != ptr) {
str.erase();
myConverter->convert(str, start, ptr + 1);
characterDataHandler(str);
}
if (skipNewLine) {
++ptr;
}
start = ptr + 1;
newLineHandler();
} else if (isspace((unsigned char)*ptr)) {
if (*ptr != '\t') {
*ptr = ' ';
}
} else {
}
}
if (start != end) {
str.erase();
myConverter->convert(str, start, end);
characterDataHandler(str);
}
} while (length == BUFSIZE);
delete[] buffer;
endDocumentHandler();
stream.close();
}