FileReader.cpp 879 B

12345678910111213141516171819202122232425262728293031323334353637
  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-18
  7. *
  8. * */
  9. #include <fstream>
  10. #include "FileReader.hpp"
  11. #include "../exception/FileNotFoundException.hpp"
  12. #include "../exception/FileOperationException.hpp"
  13. ls_std::FileReader::FileReader(File &_file) : Class("FileReader"),
  14. file(_file)
  15. {
  16. if(!_file.exists()) {
  17. throw ls_std::FileNotFoundException {};
  18. }
  19. }
  20. ls_std::byte * ls_std::FileReader::read()
  21. {
  22. ls_std::byte* data;
  23. std::ifstream inputStream {this->file.getAbsoluteFilePath(), std::ifstream::binary};
  24. int length = this->file.getSize();
  25. data = new ls_std::byte[length];
  26. inputStream.read(data, length);
  27. if(!inputStream) {
  28. throw ls_std::FileOperationException {};
  29. }
  30. inputStream.close();
  31. return data;
  32. }