コード例 #1
0
ファイル: StringUtilities.cpp プロジェクト: Tom-VdE/opticks
string toXmlString(const Blob& val, bool* pError)
{
   if (pError != NULL)
   {
      *pError = false;
   }

   // A copy from vector<unsigned char> to XMLByte* is not required because XMLByte is typedef'd to unsigned char.
   // If this ever changes, this will fail to build; in this case, a copy will need to be made.
   const vector<XMLByte>& values = val.get();
   if (values.empty())
   {
      return string();
   }

   XMLSize_t outlen;
   XMLByte* pBase64 =
      XERCES_CPP_NAMESPACE_QUALIFIER Base64::encode(&values[0], values.size() * sizeof(values[0]), &outlen);
   if (outlen == 0 || pBase64 == NULL)
   {
      if (pError != NULL)
      {
         *pError = true;
      }

      return string();
   }

   string xmlString(reinterpret_cast<char*>(pBase64), outlen);

   // Use ::operator delete() per Xerces documentation.
   ::operator delete(pBase64);
   return xmlString;
}
コード例 #2
0
ファイル: blob.cpp プロジェクト: aalex/tempi
int main(int argc, char *argv[])
{
    Blob *blob = new Blob;

    char foo[] = { 'f', 'o', 'o' };
    char bar[] = { 'b', 'a', 'r' };
    char egg[] = { 'e', 'g', 'g' };
    char spam[] = { 's', 'p', 'a', 'm' };

    blob->debugPrint();
    debugText(foo, sizeof(foo));
    blob->append(foo, sizeof(foo));
    blob->debugPrint();
    debugText(bar, sizeof(bar));
    blob->append(bar, sizeof(bar));
    blob->debugPrint();
    debugText(egg, sizeof(egg));
    blob->append(egg, sizeof(egg));
    blob->append('x');
    blob->debugPrint();
    debugText(spam, sizeof(spam));
    blob->append(spam, sizeof(spam));
    blob->debugPrint();

    std::cout << "text: " << blob->get() << std::endl;

    delete blob;

    return 0;
}
コード例 #3
0
ファイル: FileUtil.cpp プロジェクト: veladan/StreamLib
void FileUtil::Buffer2File(const Blob<char>& blob,const std::string& filePath)
{
	CFileOutputStream fileOut(filePath.c_str());

	fileOut.write((unsigned char*)blob.get(),blob.size());

	fileOut.close();
}
コード例 #4
0
ファイル: FileUtil.cpp プロジェクト: veladan/StreamLib
Blob<char> FileUtil::File2Buffer(const std::string& filePath)
{
	CFileInputStream fileIn(filePath.c_str());

	long fileLength = fileIn.available();

	Blob<char> blob;

	blob.setData(auto_array_ptr<char>(new char[fileLength]),fileLength);

	fileIn.read((unsigned char*)blob.get(),fileLength);

	fileIn.close();

	return blob;
}
コード例 #5
0
ファイル: B64OutputStream.cpp プロジェクト: veladan/StreamLib
void B64OutputStream::push(Blob<unsigned char>& blob)
{
	int length = blob.length();
	int index = 0;
	int toWrite = 0;
	
	while(length > 0)
	{
		
		toWrite = m_charsPerLine > length?length:m_charsPerLine;
		
		toWrite -= m_lastCharOfLine;
		
		if(toWrite <=0)
		{
			if(m_charsPerLine != -1)
			{
				toWrite = m_charsPerLine > length?length:m_charsPerLine;
			}
			else
			{
				toWrite = length;
			}
		}

		m_output->write(blob.get() + index,toWrite);
		
		m_lastCharOfLine += toWrite;
		if((m_lastCharOfLine == m_charsPerLine)&&(m_charsPerLine != -1))
			m_output->write((unsigned char*)m_newLineChar.c_str(),m_newLineChar.length());

		index += toWrite;
		length -= toWrite;

		

		if(m_lastCharOfLine >= m_charsPerLine)
		{
			m_lastCharOfLine -= m_charsPerLine;
		}
		
	}
}