URLInputStream.h

Go to the documentation of this file.
00001 #ifndef URLINPUTSTREAM_H
00002 #define URLINPUTSTREAM_H
00003 
00004 #include <string>
00005 #include "InputStream.h"
00006 
00007 //!@ingroup io
00008 //!InputStream that can handle both file and http url's.
00009 class URLInputStream : public InputStream
00010 {
00011     
00012     public:
00013         //!@param url A valid URL using the file: or http: scheme
00014         URLInputStream(const std::string & url);
00015         
00016         virtual ~URLInputStream();
00017         
00018         
00019         
00020         //!@return The next byte of data from the document without advancing the stream.
00021         //!throws IllegalStateException - If the stream is closed
00022         //!throws IllegalStateException - If the last byte has already been read from the stream
00023         //!throws FileException, NetworkException, IllegalStateException - Implementation Specific
00024         virtual char Peek();
00025         
00026         //!@return The next byte of data from the document.
00027         //!throws IllegalStateException - If the stream is closed
00028         //!throws IllegalStateException - If the last byte has already been read from the stream
00029         //!throws FileException, NetworkException, IllegalStateException - Implementation Specific
00030         virtual char Read();
00031 
00032         //!Closes the stream if it is not already closed. All system resources used by the stream are released.
00033         virtual void Close();
00034 
00035         //!@return true if the stream is open, and false if it is closed.
00036         virtual bool IsOpen()const;
00037 
00038         //!@return true if the end of the stream has been reached, and false if there are still more bytes to be read.
00039         virtual bool IsDone()const;
00040 
00041         virtual std::string GetLocation() const;
00042 
00043         
00044     private:
00045         InputStream * mStream;
00046         
00047         //!The ::StreamFactory is used to open an InputStream that can be used to read the contents of a web document.
00048         //!It takes the URL of the document to be acccessed, and returns an InputStream object that can be used to read
00049         //!the contents of the document. The URL can be either an HTTP URL or a file URL.
00050         //!Examples are "http://www.cnn.com/index.html" and "file:/public_html/index.html".
00051         //!
00052         //!
00053         //!The InputStream object returned by ::StreamFactory provides methods for reading the data stored in the web document,
00054         //!and to close the stream when the program has finished reading the document's data. The following code fragment shows 
00055         //!how to read a web document and print its contents to standard output.
00056         //!@code
00057         //!#include "InputStream.h"
00058         //!     
00059         //!InputStream * doc = StreamFactory("http://www.cnn.com/index.html");
00060         //!
00061         //!while (!doc->IsDone()) {
00062         //! char c = doc->Read();
00063         //! cout << c;
00064         //!}
00065         //!
00066         //!doc->Close();
00067         //!delete doc;
00068         //!@endcode
00069         //!
00070         //!
00071         //!@param url - URL of the document to be downloaded as its only parameter. The file must be either a file URL or an HTTP URL. The caller must call the Close method on the returned InputStream when they are finished reading data from the document, and then delete the object.
00072         //!@return An open InputStream object that can be used to read the contents of the document
00073         //!@return Transfers ownership of InputStream
00074         //!@throws InvalidURLException, FileException, NetworkException, IllegalStateException. 
00075         
00076         static InputStream * StreamFactory(const std::string & url);
00077                 
00078         
00079         
00080     
00081     
00082 };
00083 
00084 
00085 
00086 #endif 

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