| 1 | // |
| 2 | // FilePartSource.cpp |
| 3 | // |
| 4 | // Library: Net |
| 5 | // Package: Messages |
| 6 | // Module: FilePartSource |
| 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/FilePartSource.h" |
| 16 | #include "Poco/Path.h" |
| 17 | #include "Poco/File.h" |
| 18 | #include "Poco/Exception.h" |
| 19 | |
| 20 | |
| 21 | using Poco::Path; |
| 22 | using Poco::OpenFileException; |
| 23 | |
| 24 | |
| 25 | namespace Poco { |
| 26 | namespace Net { |
| 27 | |
| 28 | |
| 29 | FilePartSource::FilePartSource(const std::string& path): |
| 30 | _path(path), _istr(path) |
| 31 | { |
| 32 | Path p(path); |
| 33 | _filename = p.getFileName(); |
| 34 | if (!_istr.good()) |
| 35 | throw OpenFileException(path); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | FilePartSource::FilePartSource(const std::string& path, const std::string& mediaType): |
| 40 | PartSource(mediaType), |
| 41 | _path(path), |
| 42 | _istr(path) |
| 43 | { |
| 44 | Path p(path); |
| 45 | _filename = p.getFileName(); |
| 46 | if (!_istr.good()) |
| 47 | throw OpenFileException(path); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | FilePartSource::FilePartSource(const std::string& path, const std::string& filename, const std::string& mediaType): |
| 52 | PartSource(mediaType), |
| 53 | _path(path), |
| 54 | _filename(filename), |
| 55 | _istr(path) |
| 56 | { |
| 57 | Path p(path); |
| 58 | if (!_istr.good()) |
| 59 | throw OpenFileException(path); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | FilePartSource::~FilePartSource() |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | |
| 68 | std::istream& FilePartSource::stream() |
| 69 | { |
| 70 | return _istr; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | const std::string& FilePartSource::filename() const |
| 75 | { |
| 76 | return _filename; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | std::streamsize FilePartSource::getContentLength() const |
| 81 | { |
| 82 | Poco::File p(_path); |
| 83 | return p.getSize(); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | } } // namespace Poco::Net |
| 88 | |