FileByteReadResource.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_READ_RESOURCE
18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__FILE_BYTE_READ_RESOURCE
19 
21 
22 #include <boost/filesystem.hpp>
23 
24 namespace Balau::Resource {
25 
26 class File;
27 class Uri;
28 
38  public: explicit FileByteReadResource(const File & file_);
39 
40  public: FileByteReadResource(FileByteReadResource && rhs) noexcept
41  : file(std::move(rhs.file))
42  , stream(std::move(rhs.stream)) {}
43 
44  public: ~FileByteReadResource() override {
45  close();
46  }
47 
48  public: std::istream & readStream() override {
49  return *stream;
50  }
51 
52  public: const Uri & uri() const override;
53 
59  public: const File & getFile() const;
60 
61  public: void close() override {
62  stream->close();
63  }
64 
66 
67  private: std::unique_ptr<File> file;
68  private: std::unique_ptr<boost::filesystem::ifstream> stream;
69 };
70 
71 } // namespace Balau::Resource
72 
73 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__FILE_BYTE_READ_RESOURCE
const File & getFile() const
Get the file URI.
A read-only resource which is read as bytes.
Definition: ByteReadResource.hpp:29
std::istream & readStream() override
Get the input stream of the byte read resource.
Definition: FileByteReadResource.hpp:48
void close() override
Close the stream(s) in the resource.
Definition: FileByteReadResource.hpp:61
An abstract universal resource identifier.
Definition: Uri.hpp:131
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
A read-only standard file on a file system which is read as bytes.
Definition: FileByteReadResource.hpp:32
const Uri & uri() const override
Get the URI associated with this resource.
A file on the local file system.
Definition: File.hpp:35
FileByteReadResource(const File &file_)
Create a new file byte read resource from the supplied file URI.
A read-only resource which is read as bytes.