StreamCopier.h 2.6 KB

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