void FileTransferReplyBuffer::onFileListReply()
{
  UINT8 compressionLevel = 0;
  UINT32 compressedSize = 0;
  UINT32 uncompressedSize = 0;

  UINT8 *buffer = NULL;

  {
    omni_mutex_lock l(*m_readMutex);

    compressionLevel = m_dataInputStream->readUInt8();
    compressedSize = m_dataInputStream->readUInt32();
    uncompressedSize = m_dataInputStream->readUInt32();

    buffer = readCompressedDataBlock(compressedSize,
                                     uncompressedSize,
                                     compressionLevel);
  }

  ByteArrayInputStream memoryInputStream((char *)buffer, uncompressedSize);
  DataInputStream filesInfoReader(&memoryInputStream);

  if (m_filesInfo != NULL) {
    delete[] m_filesInfo;
  }

  try {
    m_filesInfoCount = filesInfoReader.readUInt32();
    m_filesInfo = new FileInfo[m_filesInfoCount];

    for (UINT32 i = 0; i < m_filesInfoCount; i++) {
      FileInfo *fileInfo = &m_filesInfo[i];

      fileInfo->setSize(filesInfoReader.readUInt64());
      fileInfo->setLastModified(filesInfoReader.readUInt64());
      fileInfo->setFlags(filesInfoReader.readUInt16());

      StringStorage t;
      filesInfoReader.readUTF8(&t);

      fileInfo->setFileName(t.getString());
    } 
  } catch (IOException &ioEx) {

    delete[] buffer;

    throw ioEx;
  } 

  Log::info(_T("Recieved file list reply: \n")
            _T("\t files count = %d\n")
            _T("\t use compression = %d\n"),
            m_filesInfoCount, compressionLevel);

  delete[] buffer;
}
void FileTransferReplyBuffer::onFileListReply()
{
  UINT8 compressionLevel = 0;
  UINT32 compressedSize = 0;
  UINT32 uncompressedSize = 0;

  vector<UINT8> buffer;

  {
    compressionLevel = m_input->readUInt8();
    compressedSize = m_input->readUInt32();
    uncompressedSize = m_input->readUInt32();

    buffer = readCompressedDataBlock(compressedSize,
                                     uncompressedSize,
                                     compressionLevel);
  }

  // FIXME: type conversion in C-style
  ByteArrayInputStream memoryInputStream((const char *)(&buffer.front()),
                                         uncompressedSize);
  DataInputStream filesInfoReader(&memoryInputStream);

  if (m_filesInfo != NULL) {
    delete[] m_filesInfo;
  }

  m_filesInfoCount = filesInfoReader.readUInt32();
  m_filesInfo = new FileInfo[m_filesInfoCount];

  for (UINT32 i = 0; i < m_filesInfoCount; i++) {
    FileInfo *fileInfo = &m_filesInfo[i];

    fileInfo->setSize(filesInfoReader.readUInt64());
    fileInfo->setLastModified(filesInfoReader.readUInt64());
    fileInfo->setFlags(filesInfoReader.readUInt16());

    StringStorage t;
    filesInfoReader.readUTF8(&t);

    fileInfo->setFileName(t.getString());
  } // for all newly created file's info

  m_logWriter->info(_T("Received file list reply: \n")
                    _T("\t files count = %d\n")
                    _T("\t use compression = %d\n"),
                    m_filesInfoCount, compressionLevel);

}
// use wxTextInputStream to exercise wxMBConv interface
// (this reveals some bugs in certain wxMBConv subclasses)
void MBConvTestCase::TestStreamDecoder(
                                       const wchar_t* wideBuffer,  // the same character sequence as multiBuffer, encoded as wchar_t
                                       size_t         wideChars,   // the number of wide characters at wideBuffer
                                       const char*    multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter"
                                       size_t         multiBytes,  // the byte length of the multibyte character sequence that can be decoded by "converter"
                                       wxMBConv*      converter    // the wxMBConv object that can decode multiBuffer into a wide character sequence
                                       )
{
    // this isn't meant to test wxMemoryInputStream or wxTextInputStream
    // it's meant to test the way wxTextInputStream uses wxMBConv
    // (which has exposed some problems with wxMBConv)
    wxMemoryInputStream memoryInputStream( multiBuffer, multiBytes );
    wxTextInputStream textInputStream( memoryInputStream, wxT(""), *converter );
    for ( size_t i = 0; i < wideChars; i++ )
    {
        wxChar wc = textInputStream.GetChar();
        CPPUNIT_ASSERT( wc == wideBuffer[i] );
    }
    CPPUNIT_ASSERT( 0 == textInputStream.GetChar() );
    CPPUNIT_ASSERT( memoryInputStream.Eof() );
}