29 std::ifstream dataStream(
filename.c_str(), std::ios::in | std::ios::binary);
31 throw std::invalid_argument(
"FileDescriptor::isAscii() - Unable to open file '" +
filename +
"'");
50 const std::streampos startPos =
data.tellg();
54 while (counter < nbytes) {
61 auto ch =
static_cast<unsigned long>(byte);
82 auto dataArray =
new char[nbytes];
83 const char *pend = &dataArray[fread(dataArray, 1, nbytes, file)];
84 int retval = fseek(file, 0, SEEK_SET);
86 throw std::runtime_error(
"FileDescriptor::isAscii - Cannot change position "
87 "to the beginning of the file with fseek");
92 for (
char *p = dataArray; p < pend; ++p) {
93 auto ch =
static_cast<unsigned long>(*p);
110 std::ifstream file(
filename.c_str());
113 throw std::invalid_argument(
"FileDescriptor::isEmpty() - Unable to open file '" +
filename +
"'");
116 return file.peek() == std::ifstream::traits_type::eof();
130 throw std::invalid_argument(
"FileDescriptor() - Empty filename '" +
filename +
"'");
132 if (!std::filesystem::exists(
filename)) {
133 throw std::invalid_argument(
"FileDescriptor() - File '" +
filename +
"' does not exist");
182 throw std::runtime_error(
"FileDescriptor::initialize - Cannot open file '" +
filename +
"' for reading");
std::string m_extension
Extension.
bool isAscii() const
Returns true if the descriptor is looking at an ascii file.
void resetStreamToStart()
Reset the file stream to the start of the file.
static bool isEmpty(const std::string &filename)
Returns true if the file is empty.
FileDescriptor()=delete
Disable default constructor.
const std::string & filename() const
Access the filename.
void initialize(const std::string &filename)
Open the file and cache description elements.
std::istream & data()
Access the open file stream.
bool isXML() const
Returns true if the descriptor is looking at an XML file.
const std::string & extension() const
Access the file extension.
std::string m_filename
Full filename.
bool m_ascii
Flag indicating the file is pure ascii.
~FileDescriptor()
Destructor.
std::ifstream m_file
Open file stream.
MANTID_KERNEL_DLL std::string toLower(const std::string &input)
Converts string to all lowercase.