------------------------------------------------------------------------------
| 264 | |
| 265 | //------------------------------------------------------------------------------ |
| 266 | int vtkNrrdReader::ReadHeaderInternal(vtkCharArray* headerBuffer) |
| 267 | { |
| 268 | if (!this->FileName) |
| 269 | { |
| 270 | vtkErrorMacro(<< "No filename set."); |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | vtksys::ifstream file(this->FileName, ios::in | ios::binary); |
| 275 | // Read in 4 MB. Assuming that the header will be smaller than that. |
| 276 | headerBuffer->SetNumberOfTuples(0x400000); |
| 277 | file.read(headerBuffer->GetPointer(0), 0x400000 - 1); |
| 278 | vtkIdType buffersize = file.gcount(); |
| 279 | headerBuffer->SetValue(buffersize, '\0'); |
| 280 | headerBuffer->SetNumberOfTuples(buffersize + 1); |
| 281 | |
| 282 | // Find a blank line (which signals the end of the header). Be careful |
| 283 | // because line endings can be "\n", "\r\n", or both. It is possible that |
| 284 | // the entire file is the header (happens with "detached headers"). |
| 285 | char* bufferStart = headerBuffer->GetPointer(0); |
| 286 | char* s = bufferStart; |
| 287 | while ((s = strchr(s + 1, '\n')) != nullptr) |
| 288 | { |
| 289 | // If you find a double line ending, terminate the string and shorten the |
| 290 | // buffer. |
| 291 | if (s[1] == '\n') |
| 292 | { |
| 293 | s[2] = '\0'; |
| 294 | headerBuffer->SetNumberOfTuples(static_cast<vtkIdType>(s + 3 - bufferStart)); |
| 295 | break; |
| 296 | } |
| 297 | if ((s[1] == '\r') && (s[2] == '\n')) |
| 298 | { |
| 299 | s[3] = '\0'; |
| 300 | headerBuffer->SetNumberOfTuples(static_cast<vtkIdType>(s + 4 - bufferStart)); |
| 301 | break; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return 1; |
| 306 | } |
| 307 | |
| 308 | //------------------------------------------------------------------------------ |
| 309 | int vtkNrrdReader::ReadHeader() |
no test coverage detected