2012-04-29 20:52:25 +02:00
|
|
|
//
|
|
|
|
// FilePartSource.cpp
|
|
|
|
//
|
|
|
|
// $Id: //poco/1.4/Net/src/FilePartSource.cpp#1 $
|
|
|
|
//
|
|
|
|
// Library: Net
|
|
|
|
// Package: Messages
|
|
|
|
// Module: FilePartSource
|
|
|
|
//
|
|
|
|
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
|
|
|
// and Contributors.
|
|
|
|
//
|
2014-05-04 21:02:42 +02:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2012-04-29 20:52:25 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "Poco/Net/FilePartSource.h"
|
|
|
|
#include "Poco/Path.h"
|
2013-12-04 21:19:20 +01:00
|
|
|
#include "Poco/File.h"
|
2012-04-29 20:52:25 +02:00
|
|
|
#include "Poco/Exception.h"
|
|
|
|
|
|
|
|
|
|
|
|
using Poco::Path;
|
|
|
|
using Poco::OpenFileException;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Poco {
|
|
|
|
namespace Net {
|
|
|
|
|
|
|
|
|
|
|
|
FilePartSource::FilePartSource(const std::string& path):
|
2013-12-04 21:19:20 +01:00
|
|
|
_path(path), _istr(path)
|
2012-04-29 20:52:25 +02:00
|
|
|
{
|
|
|
|
Path p(path);
|
|
|
|
_filename = p.getFileName();
|
|
|
|
if (!_istr.good())
|
|
|
|
throw OpenFileException(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FilePartSource::FilePartSource(const std::string& path, const std::string& mediaType):
|
|
|
|
PartSource(mediaType),
|
2013-12-04 21:19:20 +01:00
|
|
|
_path(path),
|
2012-04-29 20:52:25 +02:00
|
|
|
_istr(path)
|
|
|
|
{
|
|
|
|
Path p(path);
|
|
|
|
_filename = p.getFileName();
|
|
|
|
if (!_istr.good())
|
|
|
|
throw OpenFileException(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FilePartSource::FilePartSource(const std::string& path, const std::string& filename, const std::string& mediaType):
|
|
|
|
PartSource(mediaType),
|
2013-12-04 21:19:20 +01:00
|
|
|
_path(path),
|
2012-04-29 20:52:25 +02:00
|
|
|
_filename(filename),
|
|
|
|
_istr(path)
|
|
|
|
{
|
|
|
|
Path p(path);
|
|
|
|
if (!_istr.good())
|
|
|
|
throw OpenFileException(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FilePartSource::~FilePartSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::istream& FilePartSource::stream()
|
|
|
|
{
|
|
|
|
return _istr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-17 18:41:15 +01:00
|
|
|
const std::string& FilePartSource::filename() const
|
2012-04-29 20:52:25 +02:00
|
|
|
{
|
|
|
|
return _filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-04 21:19:20 +01:00
|
|
|
std::streamsize FilePartSource::getContentLength() const
|
|
|
|
{
|
|
|
|
Poco::File p(_path);
|
|
|
|
return p.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-29 20:52:25 +02:00
|
|
|
} } // namespace Poco::Net
|