本文整理汇总了C++中NPT_InputStreamReference::Tell方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_InputStreamReference::Tell方法的具体用法?C++ NPT_InputStreamReference::Tell怎么用?C++ NPT_InputStreamReference::Tell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_InputStreamReference
的用法示例。
在下文中一共展示了NPT_InputStreamReference::Tell方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*----------------------------------------------------------------------
| PLT_HttpHelper::IsBodyStreamSeekable
+---------------------------------------------------------------------*/
bool
PLT_HttpHelper::IsBodyStreamSeekable(NPT_HttpMessage* message)
{
NPT_HttpEntity* entity = message->GetEntity();
NPT_InputStreamReference stream;
if (!entity || NPT_FAILED(entity->GetInputStream(stream))) return true;
// try to get current position and seek there
NPT_Position position;
if (NPT_FAILED(stream->Tell(position)) ||
NPT_FAILED(stream->Seek(position))) {
return false;
}
return true;
}
示例2: file
//.........这里部分代码省略.........
result = NPT_File::ListDirectory("foobar.dir", entries);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(entries.GetItemCount() == 3);
result = NPT_File::DeleteFile("foobar.dir");
NPT_ASSERT(NPT_FAILED(result));
result = NPT_File::DeleteDirectory("foobar.dir");
NPT_ASSERT(result == NPT_ERROR_DIRECTORY_NOT_EMPTY);
result = NPT_File::Rename("foobar.dir", "foobar.dir-r");
NPT_ASSERT(NPT_SUCCEEDED(result));
dirname = "foobar.dir-r";
fname = dirname;
fname += NPT_FilePath::Separator;
fname += "file1";
result = NPT_File::DeleteFile(fname);
NPT_ASSERT(NPT_SUCCEEDED(result));
fname = dirname;
fname += NPT_FilePath::Separator;
fname += "file2";
result = NPT_File::DeleteFile(fname);
NPT_ASSERT(NPT_SUCCEEDED(result));
fname = dirname;
fname += NPT_FilePath::Separator;
fname += "file3";
result = NPT_File::DeleteFile(fname);
NPT_ASSERT(NPT_SUCCEEDED(result));
result = NPT_File::DeleteDirectory("foobar.dir-r");
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(!NPT_File::Exists("foobar.dir-r"));
// paths
NPT_String test;
test = NPT_FilePath::BaseName("");
NPT_ASSERT(test == "");
test = NPT_FilePath::BaseName("a");
NPT_ASSERT(test == "a");
test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b");
NPT_ASSERT(test == "b");
test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
NPT_ASSERT(test == "");
test = NPT_FilePath::BaseName(NPT_FilePath::Separator+"a");
NPT_ASSERT(test == "a");
test = NPT_FilePath::BaseName(NPT_FilePath::Separator);
NPT_ASSERT(test == "");
test = NPT_FilePath::DirectoryName("");
NPT_ASSERT(test == "");
test = NPT_FilePath::DirectoryName("a");
NPT_ASSERT(test == "");
test = NPT_FilePath::DirectoryName("a"+NPT_FilePath::Separator+"b");
NPT_ASSERT(test == "a");
test = NPT_FilePath::DirectoryName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
NPT_ASSERT(test == "a"+NPT_FilePath::Separator+"b");
test = NPT_FilePath::DirectoryName(NPT_FilePath::Separator+"a");
NPT_ASSERT(test == NPT_FilePath::Separator);
test = NPT_FilePath::DirectoryName(NPT_FilePath::Separator);
NPT_ASSERT(test == NPT_FilePath::Separator);
// large files
if (argc == 2) {
result = CreateNewFile(argv[1], 0x10000, 0x10007);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_String new_name = argv[1];
new_name += ".renamed";
result = NPT_File::Rename(argv[1], new_name);
NPT_ASSERT(NPT_SUCCEEDED(result));
file = NPT_File(new_name);
result = file.Open(NPT_FILE_OPEN_MODE_READ);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_InputStreamReference input;
file.GetInputStream(input);
NPT_Position position;
result = input->Tell(position);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(position == 0);
NPT_LargeSize large_size = (NPT_LargeSize)0x10007 * (NPT_LargeSize)0x10000;
result = input->Seek(large_size-0x10007);
NPT_ASSERT(NPT_SUCCEEDED(result));
result = input->Tell(position);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(position == large_size-0x10007);
unsigned char* buffer = new unsigned char[0x10007];
result = input->ReadFully(buffer, 0x10007);
NPT_ASSERT(NPT_SUCCEEDED(result));
result = input->Tell(position);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(position == large_size);
for (unsigned int i=0; i<0x10007; i++) {
NPT_ASSERT(buffer[i] == (unsigned char)i);
}
file.Close();
NPT_File::DeleteFile(new_name);
}
return 0;
}
示例3: tmp_context
/*----------------------------------------------------------------------
| PLT_HttpServer::ServeStream
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpServer::ServeStream(const NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response,
NPT_InputStreamReference& body,
const char* content_type)
{
if (body.IsNull()) return NPT_FAILURE;
// set date
NPT_TimeStamp now;
NPT_System::GetCurrentTimeStamp(now);
response.GetHeaders().SetHeader("Date", NPT_DateTime(now).ToString(NPT_DateTime::FORMAT_RFC_1123), true);
// get entity
NPT_HttpEntity* entity = response.GetEntity();
NPT_CHECK_POINTER_FATAL(entity);
// set the content type
entity->SetContentType(content_type);
// check for range requests
const NPT_String* range_spec = request.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_RANGE);
// setup entity body
NPT_CHECK(NPT_HttpFileRequestHandler::SetupResponseBody(response, body, range_spec));
// set some default headers
if (response.GetEntity()->GetTransferEncoding() != NPT_HTTP_TRANSFER_ENCODING_CHUNKED) {
// set but don't replace Accept-Range header only if body is seekable
NPT_Position offset;
if (NPT_SUCCEEDED(body->Tell(offset)) && NPT_SUCCEEDED(body->Seek(offset))) {
response.GetHeaders().SetHeader(NPT_HTTP_HEADER_ACCEPT_RANGES, "bytes", false);
}
}
// set getcontentFeatures.dlna.org
const NPT_String* value = request.GetHeaders().GetHeaderValue("getcontentFeatures.dlna.org");
if (value) {
PLT_HttpRequestContext tmp_context(request, context);
const char* dlna = PLT_ProtocolInfo::GetDlnaExtension(entity->GetContentType(),
&tmp_context);
if (dlna) response.GetHeaders().SetHeader("ContentFeatures.DLNA.ORG", dlna, false);
}
// transferMode.dlna.org
value = request.GetHeaders().GetHeaderValue("transferMode.dlna.org");
if (value) {
// Interactive mode not supported?
/*if (value->Compare("Interactive", true) == 0) {
response.SetStatus(406, "Not Acceptable");
return NPT_SUCCESS;
}*/
response.GetHeaders().SetHeader("TransferMode.DLNA.ORG", value->GetChars(), false);
} else {
response.GetHeaders().SetHeader("TransferMode.DLNA.ORG", "Streaming", false);
}
if (request.GetHeaders().GetHeaderValue("TimeSeekRange.dlna.org")) {
response.SetStatus(406, "Not Acceptable");
return NPT_SUCCESS;
}
return NPT_SUCCESS;
}
示例4: file
//.........这里部分代码省略.........
NPT_ASSERT(test == "a");
test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b");
NPT_ASSERT(test == "b");
test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
NPT_ASSERT(test == "");
test = NPT_FilePath::BaseName(NPT_FilePath::Separator+"a");
NPT_ASSERT(test == "a");
test = NPT_FilePath::BaseName(NPT_FilePath::Separator);
NPT_ASSERT(test == "");
test = NPT_FilePath::DirName("");
NPT_ASSERT(test == "");
test = NPT_FilePath::DirName("a");
NPT_ASSERT(test == "");
test = NPT_FilePath::DirName("a"+NPT_FilePath::Separator+"b");
NPT_ASSERT(test == "a");
test = NPT_FilePath::DirName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
NPT_ASSERT(test == "a"+NPT_FilePath::Separator+"b");
test = NPT_FilePath::DirName(NPT_FilePath::Separator+"a");
NPT_ASSERT(test == NPT_FilePath::Separator);
test = NPT_FilePath::DirName(NPT_FilePath::Separator);
NPT_ASSERT(test == NPT_FilePath::Separator);
// small files
result = CreateNewFile("small.bin", 0x100, 0x107);
NPT_ASSERT(NPT_SUCCEEDED(result));
file = NPT_File("small.bin");
result = file.Open(NPT_FILE_OPEN_MODE_READ);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_InputStreamReference input;
file.GetInputStream(input);
NPT_Position position;
result = input->Tell(position);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(position == 0);
NPT_LargeSize large_size = (NPT_LargeSize)0x107 * (NPT_LargeSize)0x100;
result = input->Seek(large_size-0x107);
NPT_ASSERT(NPT_SUCCEEDED(result));
result = input->Tell(position);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(position == large_size-0x107);
unsigned char* buffer = new unsigned char[0x107];
result = input->ReadFully(buffer, 0x107);
NPT_ASSERT(NPT_SUCCEEDED(result));
result = input->Tell(position);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(position == large_size);
for (unsigned int i=0; i<0x107; i++) {
NPT_ASSERT(buffer[i] == (unsigned char)i);
}
file.Close();
NPT_File::RemoveFile(file.GetPath());
// large files
if (argc == 2) {
result = CreateNewFile(argv[1], 0x10000, 0x10007);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_String new_name = argv[1];
new_name += ".renamed";
result = NPT_File::Rename(argv[1], new_name);
NPT_ASSERT(NPT_SUCCEEDED(result));
file = NPT_File(new_name);
result = file.Open(NPT_FILE_OPEN_MODE_READ);
NPT_ASSERT(NPT_SUCCEEDED(result));