| 1 | // |
|---|---|
| 2 | // PartStore.cpp |
| 3 | // |
| 4 | // Library: Net |
| 5 | // Package: Messages |
| 6 | // Module: PartStore |
| 7 | // |
| 8 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
| 9 | // and Contributors. |
| 10 | // |
| 11 | // SPDX-License-Identifier: BSL-1.0 |
| 12 | // |
| 13 | |
| 14 | |
| 15 | #include "Poco/Net/PartStore.h" |
| 16 | #include "Poco/TemporaryFile.h" |
| 17 | #include "Poco/File.h" |
| 18 | #include "Poco/Exception.h" |
| 19 | |
| 20 | |
| 21 | namespace Poco { |
| 22 | namespace Net { |
| 23 | |
| 24 | |
| 25 | // |
| 26 | // PartStore |
| 27 | // |
| 28 | |
| 29 | |
| 30 | PartStore::PartStore(const std::string& mediaType): PartSource(mediaType) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | |
| 35 | PartStore::~PartStore() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | |
| 40 | // |
| 41 | // FilePartStore |
| 42 | // |
| 43 | |
| 44 | |
| 45 | FilePartStore::FilePartStore(const std::string& content, const std::string& mediaType, const std::string& filename): |
| 46 | PartStore(mediaType), |
| 47 | _filename(filename), |
| 48 | _path(TemporaryFile::tempName()), |
| 49 | _fstr(_path) |
| 50 | { |
| 51 | _fstr << content << std::flush; |
| 52 | _fstr.seekg(0, std::ios::beg); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | FilePartStore::~FilePartStore() |
| 57 | { |
| 58 | try |
| 59 | { |
| 60 | _fstr.close(); |
| 61 | File(_path).remove(); |
| 62 | } |
| 63 | catch (...) |
| 64 | { |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | std::istream& FilePartStore::stream() |
| 70 | { |
| 71 | return _fstr; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | const std::string& FilePartStore::filename() const |
| 76 | { |
| 77 | return _filename; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | const std::string& FilePartStore::path() const |
| 82 | { |
| 83 | return _path; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | } } // namespace Poco::Net |
| 88 |