code: public int readFile(String filename, boolean validate) {
      int result = 0;
  
      try {
        if (Files.exists(Paths.get(filename))) {
          data = new TiffInputStream(new File(filename));
  
          tiffModel = new TiffDocument();
          validation = new ValidationResult(validate);
          tiffModel.setSize(data.size());
          boolean correctHeader = readHeader();
          if (correctHeader) {
            if (tiffModel.getMagicNumber() < 42) {
              validation
                  .addError("Incorrect tiff magic number", "Header", tiffModel.getMagicNumber());
            } else if (tiffModel.getMagicNumber() == 43) {
              validation.addErrorLoc("Big tiff file not yet supported", "Header");
            } else if (validation.isCorrect()) {
              readIFDs();
  
              if (validate) {
                BaselineProfile bp = new BaselineProfile(tiffModel);
                bp.validate();
                getBaselineValidation().add(bp.getValidation());
              }
            }
          }
  
          if (getBaselineValidation().getFatalError()) {
            tiffModel.setFatalError(true, getBaselineValidation().getFatalErrorMessage());
          }
  
          data.close();
        } else {
          // File not found
          result = -1;
          tiffModel.setFatalError(true, "File not found");
        }
      } catch (Exception ex) {
        // IO exception
        result = -2;
        tiffModel.setFatalError(true, "IO Exception");
      }
  
      return result;
    }
docs: Parses a Tiff File and create an internal model representation.
  
  @param filename the Tiff filename
  @return Error code (0: successful, -1: file not found, -2: IO exception)