URLInputStream.cpp

Go to the documentation of this file.
00001 #include "StringUtil.h"
00002 #include "CS240Exception.h"
00003 #include "HTTPInputStream.h"
00004 #include "FileInputStream.h"
00005 #include "URLInputStream.h"
00006 #include "InputStream.h"
00007 
00008 using namespace std;
00009 
00010 InputStream * URLInputStream::StreamFactory(const string & url) {
00011     string tempUrl = StringUtil::ToLowerCopy(url);
00012     if (StringUtil::IsPrefix(tempUrl, "file:/")) {
00013         return new FileInputStream(url);
00014     }
00015     else if (StringUtil::IsPrefix(tempUrl, "http://")) {
00016         return new HTTPInputStream(url);
00017     }
00018     else {
00019         throw InvalidURLException(url);
00020     }
00021     
00022 }
00023 
00024 URLInputStream::URLInputStream(const std::string & Url) : 
00025                                  mStream(URLInputStream::StreamFactory(Url))
00026 {
00027 }
00028 
00029 URLInputStream::~URLInputStream()
00030 {
00031     if(mStream && mStream->IsOpen())
00032     {
00033         mStream->Close();
00034         
00035     }
00036     
00037     delete mStream;
00038 }
00039 
00040 
00041     
00042 char URLInputStream::Peek()
00043 {
00044     return mStream->Peek();
00045 }
00046         
00047 char URLInputStream::Read()
00048 {
00049     return mStream->Read();
00050 }
00051 
00052 void URLInputStream::Close()
00053 {
00054     
00055     return mStream->Close();
00056 }
00057 
00058 bool URLInputStream::IsOpen()const
00059 {
00060     return mStream->IsOpen();
00061 }
00062 
00063 bool URLInputStream::IsDone()const
00064 {
00065     return mStream->IsDone();
00066 }
00067 
00068 std::string URLInputStream::GetLocation() const
00069 {
00070     return mStream->GetLocation();
00071 }
00072 
00073             
00074 
00075 

Generated on Wed Jul 7 16:30:27 2010 for CS240Utils by  doxygen 1.5.8