printer.cpp
An example for
URLInputStream of the
IO module.
#include <iostream>
#include "URLInputStream.h"
#include "CS240Exception.h"
void print_contents (InputStream &stream);
int main (int argc, char* argv [])
{
for(int i = 1;i<argc;++i)
{
std::string path=argv[i];
std::cout << "Printing: " << path << std::endl;
std::cout << "=======================================" << std::endl;
try
{
URLInputStream stream (path);
print_contents (stream);
path = stream.GetLocation();
std::cout << "=======================================" << std::endl;
std::cout << "Actual Location: " << path << std::endl;
}
catch (std::exception &e)
{
std::cout << "Exception Occurred:" << e.what() << std::endl;
}
catch (CS240Exception &e)
{
std::cout << "Exception Occurred:" << e.GetMessage() << std::endl;
}
catch (...)
{
std::cout << "Unknown Exception Occurred" << std::endl;
}
}
return 0;
}
void print_contents (InputStream &stream)
{
while (!stream.IsDone())
{
std::cout << stream.Read();
}
}