• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/DcRetrieveFile.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 
00005 Beesnest is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 Beesnest is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with Beesnest; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 
00021 /**
00022  * DcRetrieveFile.cpp: Implamentation of CdcRetrieveFile class.
00023  * for documentation see the header file.
00024  */
00025 
00026 #include "DcRetrieveFile.h"
00027 
00028 CdcFileCacher CdcRetrieveFile::oFileCache;
00029 
00030 CdcBuffer CdcRetrieveFile::GetData () throw (CdcException)
00031 {
00032     if (oFileAttrib.IsFileFound () == false)
00033         throw (CdcExceptionFile (CdcString ("Cannot find the file - ") +
00034             oFileAttrib.GetURL (), DC_FILE_NOT_FOUND_EXP));
00035     CdcBuffer data; // GetFileSize ()
00036     /* Look for the file in the cache. */
00037     if (oFileAttrib.IsNotToCache () == false &&
00038         oFileCache.GetFile (oFileAttrib.GetFullName (),
00039             oFileAttrib.GetLastModified (), data) == true)
00040             return data;
00041     /* File is not in cache. */
00042     char temp [1024];
00043     int ret, mode = ios::in | ios::binary;
00044     /* Open file if it is not open. */
00045     if (oFile.is_open () == 0)
00046         oFile.open (oFileAttrib.GetFullName ().GetBuffer (), mode);
00047     if (oFile.is_open () == 0)
00048         throw (CdcExceptionFile (CdcString ("Cannot open the file - ") +
00049             oFileAttrib.GetURL (), DC_FILE_NOT_FOUND_EXP));
00050     /* Read file. */
00051     while (oFile.eof () == 0)
00052     {
00053         oFile.read (temp, 1000);
00054         ret = oFile.gcount ();
00055         data.Append (temp, ret);
00056     }
00057     oFile.close ();
00058     /* Put file in the cache. */
00059     if (oFileAttrib.IsNotToCache () == false)
00060         oFileCache.PutFile (oFileAttrib.GetFullName (),
00061             oFileAttrib.GetLastModified (), data);
00062     return data;
00063 }

Generated on Mon Oct 11 2010 16:23:24 for Beesnest by  doxygen 1.7.2