FileByteWriteResource.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_RESOURCE__FILE_BYTE_WRITE_RESOURCE
18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__FILE_BYTE_WRITE_RESOURCE
19 
21 
22 #include <boost/filesystem.hpp>
23 
24 namespace Balau::Resource {
25 
26 class File;
27 class Uri;
28 
36  public: explicit FileByteWriteResource(const File & file_);
37 
38  public: FileByteWriteResource(FileByteWriteResource && rhs) noexcept
39  : file(std::move(rhs.file))
40  , stream(std::move(rhs.stream)) {}
41 
42  public: ~FileByteWriteResource() override {
43  close();
44  }
45 
46  public: std::ostream & writeStream() override {
47  return *stream;
48  }
49 
50  public: const Uri & uri() const override;
51 
57  public: const File & getFile() const;
58 
59  public: void close() override {
60  stream->close();
61  }
62 
64 
65  private: std::unique_ptr<File> file;
66  private: std::unique_ptr<boost::filesystem::ofstream> stream;
67 };
68 
69 } // namespace Balau::Resource
70 
71 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__FILE_BYTE_WRITE_RESOURCE
A write-only resource which is written as bytes.
An abstract universal resource identifier.
Definition: Uri.hpp:131
A write only standard file on a file system which is written as bytes.
Definition: FileByteWriteResource.hpp:32
FileByteWriteResource(const File &file_)
Create a new file byte write resource from the supplied file URI.
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
A write-only resource which is written from bytes.
Definition: ByteWriteResource.hpp:29
const File & getFile() const
Get the file URI.
A file on the local file system.
Definition: File.hpp:35
std::ostream & writeStream() override
Get the output stream of the byte write resource.
Definition: FileByteWriteResource.hpp:46
const Uri & uri() const override
Get the URI associated with this resource.
void close() override
Close the stream(s) in the resource.
Definition: FileByteWriteResource.hpp:59