FileWriter.cpp 738 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-17
  6. * Changed: 2020-08-17
  7. *
  8. * */
  9. #include <fstream>
  10. #include "FileWriter.hpp"
  11. #include "../exception/FileNotFoundException.hpp"
  12. ls_std::FileWriter::FileWriter(ls_std::File &_file) : Class("FileWriter"),
  13. file(_file)
  14. {
  15. if(!_file.exists()) {
  16. throw ls_std::FileNotFoundException {};
  17. }
  18. }
  19. bool ls_std::FileWriter::write(const ls_std::byte* _data)
  20. {
  21. std::ofstream outputStream {};
  22. outputStream.open(this->file.getAbsoluteFilePath());
  23. bool succeeded {};
  24. if(outputStream << _data) {
  25. succeeded = true;
  26. }
  27. outputStream.close();
  28. return succeeded;
  29. }