Logo Search packages:      
Sourcecode: djvulibre version File versions

void DataPool::load_file ( void   ) 

Loads data from the file into memory. This function is only useful for DataPool::s getting data from a file. It descends the DataPool::s hierarchy until it either reaches a file-connected DataPool# or DataPool# containing the real data. In the latter case it does nothing, in the first case it makes the DataPool# read all data from the file into memory and stop using the file.

This may be useful when you want to overwrite the file and leave existing DataPool::s with valid data.

Definition at line 1405 of file DataPool.cpp.

References ByteStream::create(), FCPools::del_pool(), GURL::is_local_file_url(), and set_eof().

Referenced by DjVmDoc::expand(), DjVuDocument::save_as(), DjVuDocEditor::save_as(), and DjVmDoc::save_file().

{
   DEBUG_MSG("DataPool::load_file() called\n");
   DEBUG_MAKE_INDENT(3);

   if (pool)
   {
      DEBUG_MSG("passing the request down.\n");
      pool->load_file();
   } else if (furl.is_local_file_url())
   {
      DEBUG_MSG("loading the data from \""<<(const char *)furl<<"\".\n");

      GCriticalSectionLock lock1(&class_stream_lock);
      GP<OpenFiles_File> f=fstream;
      if (!f)
      {
        fstream=f=OpenFiles::get()->request_stream(furl, this);
      }
      {  // Scope to de-allocate lock2 before stream gets released
         GCriticalSectionLock lock2(&(f->stream_lock));

         data=ByteStream::create();
         block_list->clear();
         FCPools::get()->del_pool(furl, this);
         furl=GURL();

         const GP<ByteStream> gbs=f->stream;
         gbs->seek(0, SEEK_SET);
         data=gbs->duplicate();
         added_data(0,data->size());   
         set_eof();
//         char buffer[1024];
//         int length;
//         while((length=f->stream->read(buffer, 1024)))
//             add_data(buffer, length);
            // No need to set EOF. It should already be set.
        OpenFiles::get()->stream_released(f->stream, this);
      }
      fstream=0;
   } else DEBUG_MSG("Not connected\n");
}


Generated by  Doxygen 1.6.0   Back to index