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
21using Poco::Path;
22using Poco::OpenFileException;
23
24
25namespace Poco {
26namespace Net {
27
28
29FilePartSource::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
39FilePartSource::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
51FilePartSource::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
63FilePartSource::~FilePartSource()
64{
65}
66
67
68std::istream& FilePartSource::stream()
69{
70 return _istr;
71}
72
73
74const std::string& FilePartSource::filename() const
75{
76 return _filename;
77}
78
79
80std::streamsize FilePartSource::getContentLength() const
81{
82 Poco::File p(_path);
83 return p.getSize();
84}
85
86
87} } // namespace Poco::Net
88