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);

}
void FileTransferReplyBuffer::onDownloadDataReply()
{
  UINT8 coLevel = m_input->readUInt8();
  UINT32 coBufferSize = m_input->readUInt32();
  UINT32 uncoBufferSize = m_input->readUInt32();

  m_downloadBuffer = readCompressedDataBlock(coBufferSize, uncoBufferSize, coLevel);
  m_downloadBufferSize = uncoBufferSize;

  m_logWriter->info(_T("Received download data reply:\n")
                    _T("\tcompressed size: %d\n")
                    _T("\tuncompressed size: %d\n")
                    _T("\tuse compression: %d\n"),
                    coBufferSize, uncoBufferSize, coLevel);
}
void FileTransferReplyBuffer::onDownloadDataReply()
{
  omni_mutex_lock l(*m_readMutex);

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

  UINT8 coLevel = m_dataInputStream->readUInt8();
  UINT32 coBufferSize = m_dataInputStream->readUInt32();
  UINT32 uncoBufferSize = m_dataInputStream->readUInt32();

  m_downloadBuffer = readCompressedDataBlock(coBufferSize, uncoBufferSize, coLevel);
  m_downloadBufferSize = uncoBufferSize;

  Log::info(_T("Recieved download data reply:\n")
            _T("\tcompressed size: %d\n")
            _T("\tuncompressed size: %d\n")
            _T("\tuse compression: %d\n"),
            coBufferSize, uncoBufferSize, coLevel);
}