| 1 | // |
| 2 | // StreamCopier.h |
| 3 | // |
| 4 | // Library: Foundation |
| 5 | // Package: Streams |
| 6 | // Module: StreamCopier |
| 7 | // |
| 8 | // Definition of class StreamCopier. |
| 9 | // |
| 10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 11 | // and Contributors. |
| 12 | // |
| 13 | // SPDX-License-Identifier: BSL-1.0 |
| 14 | // |
| 15 | |
| 16 | |
| 17 | #ifndef Foundation_StreamCopier_INCLUDED |
| 18 | #define Foundation_StreamCopier_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Foundation.h" |
| 22 | #include <istream> |
| 23 | #include <ostream> |
| 24 | #include <cstddef> |
| 25 | |
| 26 | |
| 27 | namespace Poco { |
| 28 | |
| 29 | |
| 30 | class Foundation_API StreamCopier |
| 31 | /// This class provides static methods to copy the contents from one stream |
| 32 | /// into another. |
| 33 | { |
| 34 | public: |
| 35 | static std::streamsize copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192); |
| 36 | /// Writes all bytes readable from istr to ostr, using an internal buffer. |
| 37 | /// |
| 38 | /// Returns the number of bytes copied. |
| 39 | |
| 40 | #if defined(POCO_HAVE_INT64) |
| 41 | static Poco::UInt64 copyStream64(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192); |
| 42 | /// Writes all bytes readable from istr to ostr, using an internal buffer. |
| 43 | /// |
| 44 | /// Returns the number of bytes copied as a 64-bit unsigned integer. |
| 45 | /// |
| 46 | /// Note: the only difference to copyStream() is that a 64-bit unsigned |
| 47 | /// integer is used to count the number of bytes copied. |
| 48 | #endif |
| 49 | |
| 50 | static std::streamsize copyStreamUnbuffered(std::istream& istr, std::ostream& ostr); |
| 51 | /// Writes all bytes readable from istr to ostr. |
| 52 | /// |
| 53 | /// Returns the number of bytes copied. |
| 54 | |
| 55 | #if defined(POCO_HAVE_INT64) |
| 56 | static Poco::UInt64 copyStreamUnbuffered64(std::istream& istr, std::ostream& ostr); |
| 57 | /// Writes all bytes readable from istr to ostr. |
| 58 | /// |
| 59 | /// Returns the number of bytes copied as a 64-bit unsigned integer. |
| 60 | /// |
| 61 | /// Note: the only difference to copyStreamUnbuffered() is that a 64-bit unsigned |
| 62 | /// integer is used to count the number of bytes copied. |
| 63 | #endif |
| 64 | |
| 65 | static std::streamsize copyToString(std::istream& istr, std::string& str, std::size_t bufferSize = 8192); |
| 66 | /// Appends all bytes readable from istr to the given string, using an internal buffer. |
| 67 | /// |
| 68 | /// Returns the number of bytes copied. |
| 69 | |
| 70 | #if defined(POCO_HAVE_INT64) |
| 71 | static Poco::UInt64 copyToString64(std::istream& istr, std::string& str, std::size_t bufferSize = 8192); |
| 72 | /// Appends all bytes readable from istr to the given string, using an internal buffer. |
| 73 | /// |
| 74 | /// Returns the number of bytes copied as a 64-bit unsigned integer. |
| 75 | /// |
| 76 | /// Note: the only difference to copyToString() is that a 64-bit unsigned |
| 77 | /// integer is used to count the number of bytes copied. |
| 78 | #endif |
| 79 | }; |
| 80 | |
| 81 | |
| 82 | } // namespace Poco |
| 83 | |
| 84 | |
| 85 | #endif // Foundation_StreamCopier_INCLUDED |
| 86 | |