DataURIStream.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // DataURIStream.h
  3. //
  4. // Library: Foundation
  5. // Package: Streams
  6. // Module: DataURIStreamFactory
  7. //
  8. // Definition of the DataURIStream class.
  9. //
  10. // Copyright (c) 2019, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_DataURIStream_INCLUDED
  16. #define Foundation_DataURIStream_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include <istream>
  19. #include <memory>
  20. namespace Poco {
  21. class Base64Decoder;
  22. class MemoryInputStream;
  23. class URI;
  24. class Foundation_API DataURIStreamIOS: public virtual std::ios
  25. /// The base class for DataURIStream.
  26. ///
  27. /// This class is needed to ensure the correct initialization
  28. /// order of the stream buffer and base classes.
  29. {
  30. public:
  31. DataURIStreamIOS(const URI& uri);
  32. ~DataURIStreamIOS();
  33. std::streambuf* rdbuf();
  34. protected:
  35. std::streambuf* _buf;
  36. private:
  37. DataURIStreamIOS(const DataURIStreamIOS&);
  38. DataURIStreamIOS& operator = (const DataURIStreamIOS&);
  39. std::string _data;
  40. std::unique_ptr<MemoryInputStream> _memoryStream;
  41. std::unique_ptr<Base64Decoder> _base64Decoder;
  42. };
  43. class Foundation_API DataURIStream: public DataURIStreamIOS, public std::istream
  44. /// An input stream for reading data from a data URI.
  45. /// For example, when constructed from "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D" it reads "Hello, World!".
  46. {
  47. public:
  48. DataURIStream(const URI& uri);
  49. /// Creates a DataURIStream for the given data URI,
  50. /// ready for reading data.
  51. /// Throws a DataFormatException exception if the data is incorrect format.
  52. ~DataURIStream();
  53. /// Destroys the DataURIStream.
  54. private:
  55. DataURIStream(const DataURIStream&);
  56. DataURIStream& operator = (const DataURIStream&);
  57. };
  58. } // namespace Poco
  59. #endif // Foundation_DataURIStream_INCLUDED