StreamCopier.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifndef Foundation_StreamCopier_INCLUDED
  16. #define Foundation_StreamCopier_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include <istream>
  19. #include <ostream>
  20. #include <cstddef>
  21. namespace Poco {
  22. class Foundation_API StreamCopier
  23. /// This class provides static methods to copy the contents from one stream
  24. /// into another.
  25. {
  26. public:
  27. static std::streamsize copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192);
  28. /// Writes all bytes readable from istr to ostr, using an internal buffer.
  29. ///
  30. /// Returns the number of bytes copied.
  31. #if defined(POCO_HAVE_INT64)
  32. static Poco::UInt64 copyStream64(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192);
  33. /// Writes all bytes readable from istr to ostr, using an internal buffer.
  34. ///
  35. /// Returns the number of bytes copied as a 64-bit unsigned integer.
  36. ///
  37. /// Note: the only difference to copyStream() is that a 64-bit unsigned
  38. /// integer is used to count the number of bytes copied.
  39. #endif
  40. static std::streamsize copyStreamUnbuffered(std::istream& istr, std::ostream& ostr);
  41. /// Writes all bytes readable from istr to ostr.
  42. ///
  43. /// Returns the number of bytes copied.
  44. #if defined(POCO_HAVE_INT64)
  45. static Poco::UInt64 copyStreamUnbuffered64(std::istream& istr, std::ostream& ostr);
  46. /// Writes all bytes readable from istr to ostr.
  47. ///
  48. /// Returns the number of bytes copied as a 64-bit unsigned integer.
  49. ///
  50. /// Note: the only difference to copyStreamUnbuffered() is that a 64-bit unsigned
  51. /// integer is used to count the number of bytes copied.
  52. #endif
  53. static std::streamsize copyToString(std::istream& istr, std::string& str, std::size_t bufferSize = 8192);
  54. /// Appends all bytes readable from istr to the given string, using an internal buffer.
  55. ///
  56. /// Returns the number of bytes copied.
  57. #if defined(POCO_HAVE_INT64)
  58. static Poco::UInt64 copyToString64(std::istream& istr, std::string& str, std::size_t bufferSize = 8192);
  59. /// Appends all bytes readable from istr to the given string, using an internal buffer.
  60. ///
  61. /// Returns the number of bytes copied as a 64-bit unsigned integer.
  62. ///
  63. /// Note: the only difference to copyToString() is that a 64-bit unsigned
  64. /// integer is used to count the number of bytes copied.
  65. #endif
  66. };
  67. } // namespace Poco
  68. #endif // Foundation_StreamCopier_INCLUDED