本文整理汇总了C++中CharBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ CharBuffer类的具体用法?C++ CharBuffer怎么用?C++ CharBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CharBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CPPUNIT_ASSERT
void CharArrayBufferTest::testCompareTo() {
// compare to self
CPPUNIT_ASSERT( 0 == testBuffer1->compareTo( *testBuffer1 ) );
CPPUNIT_ASSERT( testBuffer1->capacity() > SMALL_TEST_LENGTH );
testBuffer1->clear();
CharBuffer* other = CharBuffer::allocate( testBuffer1->capacity() );
for( int ix = 0; ix < testData1Size; ++ix ){
testBuffer1->put( ix, testData1[ix] );
}
for( int ix = 0; ix < testData1Size; ++ix ){
other->put( ix, testData1[ix] );
}
CPPUNIT_ASSERT( 0 == testBuffer1->compareTo( *other ) );
CPPUNIT_ASSERT( 0 == other->compareTo( *testBuffer1 ) );
testBuffer1->position(1);
CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) > 0 );
CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) < 0 );
other->position( 2 );
CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) < 0 );
CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) > 0 );
testBuffer1->position( 2 );
other->limit(SMALL_TEST_LENGTH);
CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) > 0 );
CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) < 0 );
char* data = new char[21];
memset( data, 0, 21 );
CharBuffer* empty = CharBuffer::allocate(21);
CharBuffer* wrapped = CharBuffer::wrap( data, 21, 0, 21 );
CPPUNIT_ASSERT( wrapped->compareTo( *empty ) == 0 );
delete empty;
delete wrapped;
delete other;
delete [] data;
}
示例2: SHGetFolderPath
void WinConsole::SetupConfigFile()
{
// create new config-file from config template
char commonAppDataPath[MAX_PATH];
SHGetFolderPath(nullptr, CSIDL_COMMON_APPDATA, nullptr, 0, commonAppDataPath);
BString<1024> filename("%s\\NZBGet\\nzbget.conf", commonAppDataPath);
BString<1024> appDataPath("%s\\NZBGet", commonAppDataPath);
FileSystem::CreateDirectory(appDataPath);
BString<1024> confTemplateFilename("%s\\nzbget.conf.template", g_Options->GetAppDir());
CopyFile(confTemplateFilename, filename, FALSE);
// set MainDir in the config-file
int size = 0;
CharBuffer config;
if (FileSystem::LoadFileIntoBuffer(filename, config, true))
{
const char* SIGNATURE = "MainDir=${AppDir}\\downloads";
char* p = strstr(config, SIGNATURE);
if (p)
{
DiskFile outfile;
if (outfile.Open(filename, DiskFile::omWrite))
{
outfile.Write(config, p - config);
outfile.Write("MainDir=", 8);
outfile.Write(appDataPath, strlen(appDataPath));
outfile.Write(p + strlen(SIGNATURE), config.Size() - 1 - (p + strlen(SIGNATURE) - config) - 1);
outfile.Close();
}
}
}
// create default destination directory (which is not created on start automatically)
BString<1024> completeDir("%s\\NZBGet\\complete", commonAppDataPath);
FileSystem::CreateDirectory(completeDir);
}
示例3: testReadOnlyMap
void CharArrayBufferTest::testReadOnlyMap() {
CharBuffer* cb = testBuffer1->asReadOnlyBuffer();
MyCharSequence cs( "String" );
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw a ReadOnlyBufferException",
cb->append( 'A' ),
ReadOnlyBufferException );
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw a ReadOnlyBufferException",
cb->append( &cs ),
ReadOnlyBufferException );
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw a ReadOnlyBufferException",
cb->append( &cs, 1, 2 ),
ReadOnlyBufferException );
delete cb;
}
示例4: testAppendCharSequenceNormal
void CharArrayBufferTest::testAppendCharSequenceNormal() {
CharBuffer* cb = CharBuffer::allocate(10);
cb->put('A');
MyCharSequence cs( "String" );
CPPUNIT_ASSERT( cb == &( cb->append( &cs ) ) );
cb->flip();
CPPUNIT_ASSERT( MyCharSequence("AString").toString() == cb->toString() );
cb->append( (const lang::CharSequence*)NULL );
cb->flip();
CPPUNIT_ASSERT( cb->toString() == "null" );
delete cb;
}
示例5: testAppendCharSequenceIINormal
void CharArrayBufferTest::testAppendCharSequenceIINormal() {
CharBuffer* cb = CharBuffer::allocate( 10 );
cb->put( 'A' );
MyCharSequence cs( "String" );
CPPUNIT_ASSERT( cb == &( cb->append( &cs, 1, 3 ) ) );
cb->flip();
CPPUNIT_ASSERT( "Atr" == cb->toString() );
cb->append( (const lang::CharSequence*)NULL, 0, 1 );
cb->flip();
CPPUNIT_ASSERT( "n" == cb->toString() );
delete cb;
}
示例6:
bool RarVolume::ReadRar3File(DiskFile& file, RarBlock& block, RarFile& innerFile)
{
innerFile.m_splitBefore = block.flags & RAR3_FILE_SPLITBEFORE;
innerFile.m_splitAfter = block.flags & RAR3_FILE_SPLITAFTER;
uint16 namelen;
uint32 size;
if (!Read32(file, &block, &size)) return false;
innerFile.m_size = size;
if (!Skip(file, &block, 1)) return false;
if (!Skip(file, &block, 4)) return false;
if (!Read32(file, &block, &innerFile.m_time)) return false;
if (!Skip(file, &block, 2)) return false;
if (!Read16(file, &block, &namelen)) return false;
if (!Read32(file, &block, &innerFile.m_attr)) return false;
if (block.flags & RAR3_FILE_ADDSIZE)
{
uint32 highsize;
if (!Read32(file, &block, &highsize)) return false;
block.trailsize += (uint64)highsize << 32;
if (!Read32(file, &block, &highsize)) return false;
innerFile.m_size += (uint64)highsize << 32;
}
if (namelen > 8192) return false; // an error
CharBuffer name;
name.Reserve(namelen + 1);
if (!Read(file, &block, (char*)name, namelen)) return false;
name[namelen] = '\0';
innerFile.m_filename = name;
debug("%i, %i, %s", (int)block.trailsize, (int)namelen, (const char*)name);
return true;
}
示例7: testReadOverflow
void CharArrayBufferTest::testReadOverflow() {
std::vector<char> buffer;
buffer.push_back('S');
CharBuffer* source = CharBuffer::wrap( buffer );
CharBuffer* target = CharBuffer::allocate( 1 );
CPPUNIT_ASSERT( 1 == source->read(target) );
target->flip();
CPPUNIT_ASSERT( "S" == target->toString() );
CPPUNIT_ASSERT( 1 == source->position() );
delete source;
delete target;
}
示例8: defined
PathName SessionImpl::GetMyProgramFile(bool canonicalized)
{
// we do this once
if (myProgramFile.Empty())
{
#if defined(__APPLE__)
CharBuffer<char> buf;
uint32_t bufsize = buf.GetCapacity();
if (_NSGetExecutablePath(buf.GetData(), &bufsize) < 0)
{
buf.Reserve(bufsize);
if (_NSGetExecutablePath(buf.GetData(), &bufsize) != 0)
{
MIKTEX_UNEXPECTED();
}
}
myProgramFile = buf.GetData();
#else
string invocationName = initInfo.GetProgramInvocationName();
if (invocationName.empty())
{
MIKTEX_FATAL_ERROR(T_("No invocation name has been set."));
}
if (Utils::IsAbsolutePath(invocationName.c_str()))
{
myProgramFile = invocationName;
}
else if (invocationName.length() > 3 && (invocationName.substr(0, 2) == "./" || invocationName.substr(0, 3) == "../"))
{
myProgramFile = GetFullPath(invocationName.c_str());
}
else if (!Utils::FindProgram(invocationName, myProgramFile))
{
MIKTEX_FATAL_ERROR_2(T_("The invoked program could not be found in the PATH."), "invocationName", invocationName);
}
#endif
myProgramFileCanon = myProgramFile;
myProgramFileCanon.Canonicalize();
}
if (canonicalized)
{
return myProgramFileCanon;
}
else
{
return myProgramFile;
}
}
示例9: get_line
String FileAccess::get_line() const {
CharBuffer line;
CharType c = get_8();
while (!eof_reached()) {
if (c == '\n' || c == '\0') {
line.push_back(0);
return String::utf8(line.get_data());
} else if (c != '\r')
line.push_back(c);
c = get_8();
}
line.push_back(0);
return String::utf8(line.get_data());
}
示例10: createHTTPRequest
void BinHTTPInputStreamCommon::createHTTPRequest(const XMLURL &urlSource, const XMLNetHTTPInfo *httpInfo, CharBuffer &buffer)
{
static const char *GET = "GET ";
static const char *PUT = "PUT ";
static const char *POST = "POST ";
static const char *HTTP10 = " HTTP/1.0\r\n";
static const char *HOST = "Host: ";
static const char *AUTHORIZATION = "Authorization: Basic ";
static const char *COLON = ":";
XMLTransService::Codes failReason;
const XMLSize_t blockSize = 2048;
XMLTranscoder* trans = XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO8859-1", failReason, blockSize, fMemoryManager);
Janitor<XMLTranscoder> janTrans(trans);
TranscodeToStr hostName(urlSource.getHost(), trans, fMemoryManager);
TranscodeToStr path(urlSource.getPath(), trans, fMemoryManager);
TranscodeToStr fragment(urlSource.getFragment(), trans, fMemoryManager);
TranscodeToStr query(urlSource.getQuery(), trans, fMemoryManager);
// Build up the http GET command to send to the server.
// To do: We should really support http 1.1. This implementation
// is weak.
if(httpInfo) {
switch(httpInfo->fHTTPMethod) {
case XMLNetHTTPInfo::GET: buffer.append(GET); break;
case XMLNetHTTPInfo::PUT: buffer.append(PUT); break;
case XMLNetHTTPInfo::POST: buffer.append(POST); break;
}
}
else {
buffer.append(GET);
}
if(path.str() != 0) {
buffer.append((char*)path.str());
}
else {
buffer.append("/");
}
if(query.str() != 0) {
buffer.append("?");
buffer.append((char*)query.str());
}
if(fragment.str() != 0) {
buffer.append((char*)fragment.str());
}
buffer.append(HTTP10);
buffer.append(HOST);
buffer.append((char*)hostName.str());
if(urlSource.getPortNum() != 80)
{
buffer.append(COLON);
buffer.appendDecimalNumber(urlSource.getPortNum());
}
buffer.append(CRLF);
const XMLCh *username = urlSource.getUser();
const XMLCh *password = urlSource.getPassword();
if(username && password) {
XMLBuffer userPassBuf(256, fMemoryManager);
userPassBuf.append(username);
userPassBuf.append(chColon);
userPassBuf.append(password);
TranscodeToStr userPass(userPassBuf.getRawBuffer(), trans, fMemoryManager);
XMLSize_t len;
XMLByte* encodedData = Base64::encode(userPass.str(), userPass.length(), &len, fMemoryManager);
ArrayJanitor<XMLByte> janBuf2(encodedData, fMemoryManager);
if(encodedData) {
// HTTP doesn't want the 0x0A separating the data in chunks of 76 chars per line
XMLByte* authData = (XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte));
ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager);
XMLByte *cursor = authData;
for(XMLSize_t i = 0; i < len; ++i)
if(encodedData[i] != chLF)
*cursor++ = encodedData[i];
*cursor++ = 0;
buffer.append(AUTHORIZATION);
buffer.append((char*)authData);
buffer.append(CRLF);
}
}
if(httpInfo && httpInfo->fHeaders)
buffer.append(httpInfo->fHeaders, httpInfo->fHeadersLen);
buffer.append(CRLF);
}
示例11: run
void run() {
// start server thread
_myAcceptor = AcceptorPtr(new ConduitAcceptor<POLICY>(_myLocalEndpoint,
myLowercaseServer<POLICY>::create));
ENSURE(_myAcceptor->start());
// XXX uncomment this to play with telnet
//while (true);
// start client
{
CharBuffer myInputBuffer;
typename Conduit<POLICY>::Ptr myClient(new Conduit<POLICY>(_myLocalEndpoint));
ENSURE(myClient);
setSilentSuccess(true);
for (int i = 0; i < 20; ++i) {
myClient->sendData("HELLO",5);
while (!myClient->receiveData(myInputBuffer)) {
myClient->handleIO(10);
}
ENSURE(myInputBuffer.size()==5);
ENSURE(strncmp(&myInputBuffer[0],"hello",5)==0);
}
setSilentSuccess(false);
// now send something, but don't pick up the reply
myClient->sendData("GOOD BYE!",5);
}
msleep(100);
// Stress Test
setSilentSuccess(true);
for (int i=0; i < 20; ++i) {
CharBuffer myInputBuffer(5,0);
typename Conduit<POLICY>::Ptr myClient(new Conduit<POLICY>(_myLocalEndpoint));
ENSURE(myClient);
//msleep(100);
string myOutput("Q");
myOutput += as_string(i);
ENSURE(myClient->sendData(myOutput.c_str(), myOutput.length()));
while (!myClient->receiveData(myInputBuffer)) {
myClient->handleIO(10);
}
//cerr << "sent '" << myOutput << "', recv '" << &(myInputBuffer[0]) << "'" << endl;
ENSURE(myInputBuffer.size()==myOutput.length());
string myExpectedReply("q");
myExpectedReply += as_string(i);
ENSURE_MSG(strncmp(&myInputBuffer[0],myExpectedReply.c_str(),myInputBuffer.size())==0, " iterations.");
}
setSilentSuccess(false);
// now start two clients simultaneously
{
CharBuffer myInputBuffer1;
typename Conduit<POLICY>::Ptr myClient1(new Conduit<POLICY>(_myLocalEndpoint));
ENSURE(myClient1);
CharBuffer myInputBuffer2;
typename Conduit<POLICY>::Ptr myClient2(new Conduit<POLICY>(_myLocalEndpoint));
ENSURE(myClient2);
myClient2->sendData("WORLD",5);
myClient1->sendData("HELLO",5);
bool myWaiting1 = true;
bool myWaiting2 = true;
while (myWaiting1 || myWaiting2) {
if (myWaiting1 && myClient1->receiveData(myInputBuffer1)) {
myWaiting1 = false;
};
if (myWaiting2 && myClient2->receiveData(myInputBuffer2)) {
myWaiting2 = false;
};
}
ENSURE(strncmp(&myInputBuffer1[0],"hello",5)==0);
ENSURE(strncmp(&myInputBuffer2[0],"world",5)==0);
}
// how about a really big string
{
std::string myBigString;
for (int i = 0; i<10000; ++i) {
myBigString += as_string(i);
}
CharBuffer myInputBuffer;
typename Conduit<POLICY>::Ptr myClient(new Conduit<POLICY>(_myLocalEndpoint));
ENSURE(myClient);
ENSURE(myClient->sendData(myBigString.c_str(), myBigString.length()));
string myReceiveString;
while (myReceiveString.length() < myBigString.length() && myClient->isValid()) {
if (myClient->receiveData(myInputBuffer)) {
myReceiveString += string(&myInputBuffer[0], myInputBuffer.size());
}
}
ENSURE(myReceiveString == myBigString);
}
// check already-is-use behaviour
{
AcceptorPtr myAcceptor;
ENSURE_EXCEPTION(myAcceptor = AcceptorPtr(new ConduitAcceptor<POLICY>(_myLocalEndpoint,
myLowercaseServer<POLICY>::create)), ConduitInUseException);
}
// close the server (also test if the server is cancelable)
msleep(100);
//.........这里部分代码省略.........
示例12: T_
void
TarExtractor::Extract (/*[in]*/ Stream * pStreamIn_,
/*[in]*/ const PathName & destDir,
/*[in]*/ bool makeDirectories,
/*[in]*/ IExtractCallback * pCallback,
/*[in]*/ const char * lpszPrefix)
{
try
{
pStreamIn = pStreamIn_;
totalBytesRead = 0;
traceStream->WriteFormattedLine ("libextractor",
T_("extracting to %s (%s)"),
Q_(destDir),
(makeDirectories
? T_("make directories")
: T_("don't make directories")));
size_t len;
Header header;
size_t prefixLen = (lpszPrefix == 0 ? 0 : StrLen(lpszPrefix));
unsigned fileCount = 0;
bool checkHeader = true;
CharBuffer<char> buffer;
buffer.Reserve (1024 * 1024);
while ((len = Read(&header, sizeof(header))) > 0)
{
// read next header
if (len != sizeof(header))
{
FATAL_EXTRACTOR_ERROR
("TarExtractor::Extract",
T_("Invalid package archive file."),
0);
}
if (header.IsEndOfArchive())
{
break;
}
if (checkHeader)
{
if (! header.Check())
{
FATAL_EXTRACTOR_ERROR
("TarExtractor::Extract",
T_("Invalid package archive file."),
0);
}
#if ! defined(MIKTEX_DEBUG)
checkHeader = false;
#endif
}
PathName dest = header.GetFileName();
size_t size = header.GetFileSize();
if (! header.IsNormalFile())
{
if (header.GetType() == Header::LongName)
{
if (size >= BLOCKSIZE)
{
UNEXPECTED_CONDITION ("TarExtractor::Extract");
}
char longNameData[BLOCKSIZE];
ReadBlock (longNameData);
longNameData[size] = 0;
longName = longNameData;
haveLongName = true;
}
else
{
Skip (((size + sizeof(Header) - 1) / sizeof(Header))
* sizeof(Header));
}
continue;
}
if (haveLongName)
{
dest = longName;
haveLongName = false;
}
// skip directory prefix
if (lpszPrefix != 0
&& PathName::Compare(lpszPrefix, dest, prefixLen) == 0)
{
PathName tmp (dest);
dest = tmp.Get() + prefixLen;
}
// make the destination path name
PathName path (destDir);
//.........这里部分代码省略.........
示例13: testAppendSelf
void CharArrayBufferTest::testAppendSelf() {
CharBuffer* cb = CharBuffer::allocate(10);
CharBuffer* cb2 = cb->duplicate();
cb->append( cb );
CPPUNIT_ASSERT( 10 == cb->position() );
cb->clear();
CPPUNIT_ASSERT( cb2->equals( *cb ) );
delete cb2;
cb->put( "abc" );
cb2 = cb->duplicate();
cb->append( cb );
CPPUNIT_ASSERT( 10 == cb->position() );
cb->clear();
cb2->clear();
CPPUNIT_ASSERT( cb2->equals( *cb ) );
delete cb2;
cb->put( "edfg" );
cb->clear();
cb2 = cb->duplicate();
cb->append( cb );
CPPUNIT_ASSERT( 10 == cb->position() );
cb->clear();
cb2->clear();
CPPUNIT_ASSERT( cb->equals( *cb2 ) );
delete cb;
delete cb2;
}
示例14: CPPUNIT_ASSERT_THROW_MESSAGE
void CharArrayBufferTest::testPutCharBuffer() {
CharBuffer* other = CharBuffer::allocate( testBuffer1->capacity() );
CharBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
readOnly->clear();
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw a ReadOnlyBufferException",
readOnly->put( *other ),
ReadOnlyBufferException );
delete readOnly;
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw a IllegalArgumentException",
testBuffer1->put( *testBuffer1 ),
IllegalArgumentException );
CharBuffer* toBig = testBuffer1->allocate( testBuffer1->capacity() + 1 );
toBig->clear();
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw a BufferOverflowException",
testBuffer1->put( *toBig ),
BufferOverflowException );
delete toBig;
for( int ix = 0; ix < testData1Size; ++ix ){
other->put( ix, testData1[ix] );
}
other->clear();
testBuffer1->clear();
CharBuffer& ret = testBuffer1->put( *other );
CPPUNIT_ASSERT( other->position() == other->capacity() );
CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
for( int ix = 0; ix < testBuffer1->capacity() - 1; ix++ ) {
CPPUNIT_ASSERT( testBuffer1->get( ix ) == other->get( ix ) );
}
CPPUNIT_ASSERT( &ret == testBuffer1 );
delete other;
}
示例15: connection
bool Frontend::RequestFileList()
{
const char* controlIp = !strcmp(g_Options->GetControlIp(), "0.0.0.0") ? "127.0.0.1" : g_Options->GetControlIp();
Connection connection(controlIp, g_Options->GetControlPort(), false);
bool OK = connection.Connect();
if (!OK)
{
return false;
}
SNzbListRequest ListRequest;
InitMessageBase(&ListRequest.m_messageBase, rrList, sizeof(ListRequest));
ListRequest.m_fileList = htonl(m_fileList);
ListRequest.m_serverState = htonl(m_summary);
if (!connection.Send((char*)(&ListRequest), sizeof(ListRequest)))
{
return false;
}
// Now listen for the returned list
SNzbListResponse ListResponse;
bool read = connection.Recv((char*) &ListResponse, sizeof(ListResponse));
if (!read ||
(int)ntohl(ListResponse.m_messageBase.m_signature) != (int)NZBMESSAGE_SIGNATURE ||
ntohl(ListResponse.m_messageBase.m_structSize) != sizeof(ListResponse))
{
return false;
}
CharBuffer buf;
if (ntohl(ListResponse.m_trailingDataLength) > 0)
{
buf.Reserve(ntohl(ListResponse.m_trailingDataLength));
if (!connection.Recv(buf, buf.Size()))
{
return false;
}
}
connection.Disconnect();
if (m_summary)
{
m_pauseDownload = ntohl(ListResponse.m_downloadPaused);
m_remainingSize = Util::JoinInt64(ntohl(ListResponse.m_remainingSizeHi), ntohl(ListResponse.m_remainingSizeLo));
m_currentDownloadSpeed = ntohl(ListResponse.m_downloadRate);
m_downloadLimit = ntohl(ListResponse.m_downloadLimit);
m_threadCount = ntohl(ListResponse.m_threadCount);
m_postJobCount = ntohl(ListResponse.m_postJobCount);
m_upTimeSec = ntohl(ListResponse.m_upTimeSec);
m_dnTimeSec = ntohl(ListResponse.m_downloadTimeSec);
m_standBy = ntohl(ListResponse.m_downloadStandBy);
m_allBytes = Util::JoinInt64(ntohl(ListResponse.m_downloadedBytesHi), ntohl(ListResponse.m_downloadedBytesLo));
}
if (m_fileList && ntohl(ListResponse.m_trailingDataLength) > 0)
{
RemoteClient client;
client.SetVerbose(false);
client.BuildFileList(&ListResponse, buf, DownloadQueue::Guard());
}
return true;
}