1 | // |
---|---|
2 | // download.cpp |
3 | // |
4 | // This sample demonstrates the URIStreamOpener class. |
5 | // |
6 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
7 | // and Contributors. |
8 | // |
9 | // SPDX-License-Identifier: BSL-1.0 |
10 | // |
11 | |
12 | |
13 | #include "Poco/URIStreamOpener.h" |
14 | #include "Poco/StreamCopier.h" |
15 | #include "Poco/Path.h" |
16 | #include "Poco/URI.h" |
17 | #include "Poco/Exception.h" |
18 | #include "Poco/Net/HTTPStreamFactory.h" |
19 | #include "Poco/Net/FTPStreamFactory.h" |
20 | #include <memory> |
21 | #include <iostream> |
22 | |
23 | |
24 | using Poco::URIStreamOpener; |
25 | using Poco::StreamCopier; |
26 | using Poco::Path; |
27 | using Poco::URI; |
28 | using Poco::Exception; |
29 | using Poco::Net::HTTPStreamFactory; |
30 | using Poco::Net::FTPStreamFactory; |
31 | |
32 | |
33 | int main(int argc, char** argv) |
34 | { |
35 | HTTPStreamFactory::registerFactory(); |
36 | FTPStreamFactory::registerFactory(); |
37 | |
38 | if (argc != 2) |
39 | { |
40 | Path p(argv[0]); |
41 | std::cerr << "usage: "<< p.getBaseName() << " <uri>"<< std::endl; |
42 | std::cerr << " Download <uri> to standard output."<< std::endl; |
43 | std::cerr << " Works with http, ftp and file URIs."<< std::endl; |
44 | return 1; |
45 | } |
46 | |
47 | try |
48 | { |
49 | URI uri(argv[1]); |
50 | std::unique_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri)); |
51 | StreamCopier::copyStream(*pStr.get(), std::cout); |
52 | } |
53 | catch (Exception& exc) |
54 | { |
55 | std::cerr << exc.displayText() << std::endl; |
56 | return 1; |
57 | } |
58 | |
59 | return 0; |
60 | } |
61 |