InputStream.h

Go to the documentation of this file.
00001 #ifndef INPUT_STREAM_H
00002 #define INPUT_STREAM_H
00003 
00004 #include <string>
00005 
00006 
00007 //!@defgroup io IO: Local and Remote
00008 //!The Local/Remote IO Module is a set of classes that make accessing local files and
00009 //!remote files (through HTTP) transparent.
00010 //!They provide support for reading one byte at a time (InputStream::Read), one character 
00011 //!look ahead (InputStream::Peek) and for retrieving
00012 //!the absolute location of the inpout source (InputStream::GetLocation)
00013 //!
00014 //!The URLInputStream class takes care of creating the correct type of input stream 
00015 //!(FileInputStream or HTTPInputStream)for you.
00016 //!For Example, the following code will print all data from a URL, wether it is
00017 //!a file:// or http:// URL.
00018 //!@code
00019 //!
00020 //! URLInputStream stream (url);
00021 //!  
00022 //! while(! stream).IsDone()) 
00023 //!     std::cout << stream.Read() << std::endl;
00024 //!
00025 //!@endcode
00026 //!
00027 //!There are many kinds of error conditions that can occur when a program 
00028 //!accesses documents on the web. The methods on the web access classes 
00029 //!throw exceptions when errors occur. Examples of exceptions that might be thrown are:
00030 //!InvalidURLException, FileException, NetworkException, and IllegalStateException.
00031 //!Your code must be prepared to handle these exceptions when they occur, or your 
00032 //!program will terminate abnormally.
00033 //!
00034 //!The following is a more in depth example of using the URLInputSteam class.
00035 //!@include printer.cpp
00036 
00037 //!@example printer.cpp
00038 //!An example for ::URLInputStream of the @link io IO @endlink module.
00039 
00040 
00041 //!@ingroup io
00042 //!InputStream is an abstract interface for reading data from a stream. 
00043 class InputStream {
00044 public:
00045     virtual ~InputStream() {}
00046 
00047     
00048     //!@return The next byte of data from the document without advancing the stream.
00049     //!throws IllegalStateException - If the stream is closed
00050     //!throws IllegalStateException - If the last byte has already been read from the stream
00051     //!throws FileException, NetworkException, IllegalStateException - Implementation Specific
00052     virtual char Peek() = 0;
00053     
00054     //!@return The next byte of data from the document and advances the stream.
00055     //!throws IllegalStateException - If the stream is closed
00056     //!throws IllegalStateException - If the last byte has already been read from the stream
00057     //!throws FileException, NetworkException, IllegalStateException - Implementation Specific
00058     virtual char Read() = 0;
00059 
00060     //!Closes the stream if it is not already closed. All system resources used by the stream are released.
00061     virtual void Close() = 0;
00062 
00063     //!@return true if the stream is open, and false if it is closed.
00064     virtual bool IsOpen() const = 0;
00065 
00066     //!@return true if the end of the stream has been reached, and false if there are still more bytes to be read.
00067     virtual bool IsDone() const = 0;
00068 
00069     //!@return An identifier for the source of this input stream.
00070     virtual std::string GetLocation() const = 0;
00071 };
00072 
00073 
00074 #endif

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