MICO Platform
 All Classes Namespaces Functions Variables Friends
URLStream.hpp
1 #ifndef HAVE_URL_STREAM_H
2 #define HAVE_URL_STREAM_H 1
3 
4 #include <istream>
5 #include <ostream>
6 #include <streambuf>
7 
8 namespace mico {
9  namespace io {
10 
11  /*
12  * Internal data types and functions.
13  */
14  namespace {
15  enum URLType {
16  URL_TYPE_UNKNOWN = 0,
17  URL_TYPE_FILE = 1,
18  URL_TYPE_HTTP = 2,
19  URL_TYPE_FTP = 3,
20  URL_TYPE_HDFS = 4
21  };
22 
23  /*
24  * Parsed URL components
25  *
26  * @param port The port number. 0 means not specified.
27  */
28  struct url_components {
29  std::string scheme;
30  std::string host;
31  uint16_t port;
32  std::string path;
33  std::string username;
34  std::string password;
35  };
36 
37  /*
38  * Takes an URL or absolute path (with UNIX style delimiters) to parse it. It does no validation of the
39  * URL/path, therefore the result of malformed (or maybe even unusual) input can lead to incorrect results.
40  *
41  * @param url The URL string to parse
42  * @return The identified URL components. If everything is empty (and port == 0) the URL could not be parsed.
43  */
44  static url_components getURLComponents(const char* url);
45 
46  /*
47  * Returns the URL type.
48  *
49  * @param url The parsed URL.
50  * @return URL type.
51  */
52  static URLType getType(url_components url);
53  }
54 
59  class url_ostream : public std::ostream {
60  public:
61  url_ostream(const char* url);
62  url_ostream(std::string url) : url_ostream(url.c_str()) {};
63  ~url_ostream();
64 
65  private:
66  static std::streambuf* getStreamHandler(const char* url);
67  };
68 
69 
74  class url_istream : public std::istream {
75  public:
76  url_istream(const char* url);
77  url_istream(std::string url) : url_istream(url.c_str()) {};
78  ~url_istream();
79 
80  private:
81  static std::streambuf* getStreamHandler(const char* url);
82  };
83 
88  int remove(const char* url);
89  int remove(std::string url);
90  }
91 }
92 
93 #endif
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Definition: http_client.cpp:23
Main type for opening an output stream to an URL for writing.
Definition: URLStream.hpp:59
Main type for opening an input stream to an URL for reading.
Definition: URLStream.hpp:74