本文整理汇总了C++中String8::lockBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ String8::lockBuffer方法的具体用法?C++ String8::lockBuffer怎么用?C++ String8::lockBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String8
的用法示例。
在下文中一共展示了String8::lockBuffer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sanitizeString
static void sanitizeString(String8& utf8Chars) {
size_t size = utf8Chars.size();
char* str = utf8Chars.lockBuffer(size);
for (size_t i = 0; i < size; i++) {
char c = str[i];
if (c == '\0' || c == '\n' || c == '|') {
str[i] = ' ';
}
}
utf8Chars.unlockBuffer();
}
示例2: getDumpFileName
void BufferQueueDump::getDumpFileName(String8& fileName, const String8& name) {
fileName = name;
// check file name, filter out invalid chars
const char invalidChar[] = {'\\', '/', ':', '*', '?', '"', '<', '>', '|'};
size_t size = fileName.size();
char *buf = fileName.lockBuffer(size);
for (unsigned int i = 0; i < ARRAY_SIZE(invalidChar); i++) {
for (size_t c = 0; c < size; c++) {
if (buf[c] == invalidChar[i]) {
// find invalid char, replace it with '_'
buf[c] = '_';
}
}
}
fileName.unlockBuffer(size);
}
示例3: sprintf
String8
Time::toString() const
{
String8 str;
char* s = str.lockBuffer(150);
#ifdef HAVE_TM_GMTOFF
long tm_gmtoff = t.tm_gmtoff;
#else
long tm_gmtoff = 0;
#endif
sprintf(s, "%04d%02d%02dT%02d%02d%02d%s(%d,%d,%ld,%d,%d)",
t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min,
t.tm_sec, timezone, t.tm_wday, t.tm_yday, tm_gmtoff, t.tm_isdst,
(int)(((Time*)this)->toMillis(false /* use isDst */)/1000));
str.unlockBuffer();
return str;
}
示例4: jniGetFDFromFileDescriptor
static int
readHeader_native(JNIEnv* env, jobject clazz, jobject headerObj, jobject fdObj)
{
chunk_header_v1 flattenedHeader;
ssize_t amt;
String8 keyPrefix;
char* buf;
int fd = jniGetFDFromFileDescriptor(env, fdObj);
amt = read(fd, &flattenedHeader.headerSize, sizeof(flattenedHeader.headerSize));
if (amt != sizeof(flattenedHeader.headerSize)) {
return -1;
}
int remainingHeader = flattenedHeader.headerSize - sizeof(flattenedHeader.headerSize);
if (flattenedHeader.headerSize < (int)sizeof(chunk_header_v1)) {
ALOGW("Skipping unknown header: %d bytes", flattenedHeader.headerSize);
if (remainingHeader > 0) {
lseek(fd, remainingHeader, SEEK_CUR);
// >0 means skip this chunk
return 1;
}
}
amt = read(fd, &flattenedHeader.version,
sizeof(chunk_header_v1)-sizeof(flattenedHeader.headerSize));
if (amt <= 0) {
ALOGW("Failed reading chunk header");
return -1;
}
remainingHeader -= sizeof(chunk_header_v1)-sizeof(flattenedHeader.headerSize);
if (flattenedHeader.version != VERSION_1_HEADER) {
ALOGW("Skipping unknown header version: 0x%08x, %d bytes", flattenedHeader.version,
flattenedHeader.headerSize);
if (remainingHeader > 0) {
lseek(fd, remainingHeader, SEEK_CUR);
// >0 means skip this chunk
return 1;
}
}
#if 0
ALOGD("chunk header:");
ALOGD(" headerSize=%d", flattenedHeader.headerSize);
ALOGD(" version=0x%08x", flattenedHeader.version);
ALOGD(" dataSize=%d", flattenedHeader.dataSize);
ALOGD(" nameLength=%d", flattenedHeader.nameLength);
#endif
if (flattenedHeader.dataSize < 0 || flattenedHeader.nameLength < 0 ||
remainingHeader < flattenedHeader.nameLength) {
ALOGW("Malformed V1 header remainingHeader=%d dataSize=%d nameLength=%d", remainingHeader,
flattenedHeader.dataSize, flattenedHeader.nameLength);
return -1;
}
buf = keyPrefix.lockBuffer(flattenedHeader.nameLength);
if (buf == NULL) {
ALOGW("unable to allocate %d bytes", flattenedHeader.nameLength);
return -1;
}
amt = read(fd, buf, flattenedHeader.nameLength);
buf[flattenedHeader.nameLength] = 0;
keyPrefix.unlockBuffer(flattenedHeader.nameLength);
remainingHeader -= flattenedHeader.nameLength;
if (remainingHeader > 0) {
lseek(fd, remainingHeader, SEEK_CUR);
}
env->SetIntField(headerObj, s_chunkSizeField, flattenedHeader.dataSize);
env->SetObjectField(headerObj, s_keyPrefixField, env->NewStringUTF(keyPrefix.string()));
return 0;
}