/**
   * *****************************************************************************************************************
   *
   * @param delegate
   * @throws IOException
   *     <p>*****************************************************************************
   */
  public CRWImageInputStream(ImageInputStream delegate) throws IOException {
    super(delegate);
    crwInputStream = delegate;

    if (delegate instanceof FileImageInputStream2) {
      File file = ((FileImageInputStream2) delegate).getFile();
      File thmFile = null;
      String path = file.getAbsolutePath();

      int i = path.lastIndexOf('.');

      if (i > 0) {
        path = path.substring(0, i + 1);
      }

      for (i = 0; i < THM_EXTENSIONS.length; i++) {
        String thmPath = path + THM_EXTENSIONS[i];
        thmFile = new File(thmPath);

        if (thmFile.exists()) {
          break;
        }
      }

      if (!thmFile.exists()) {
        logger.warning("File " + thmFile + " does not exist");
      } else {
        logger.fine("THM file is %s", thmFile);
        thmInputStream = new FileImageInputStream(thmFile);
      }
    } else {
      logger.warning("delegate is " + delegate + ", won't be able to manage .THM file");
    }
  }
  /**
   * *****************************************************************************************************************
   *
   * <p>Post-processes a raw image using the installed postprocessor, if any.
   *
   * @param image the raw image to postprocess
   * @return the post-processed image
   *     <p>****************************************************************************************************************
   */
  protected void postProcessMetadata(
      final @Nonnull RAWMetadataSupport metadata, final @Nonnull RAWImageReadParam readParam) {
    logger.fine("postProcessMetadata(%s, %s)", metadata.getClass(), readParam);
    final Source source = readParam.lookup(Source.class);
    final PostProcessor postProcessor =
        !source.needsPostProcessor() ? null : postProcessorMapBySpiClass.get(getClass());
    logger.finer(">>>> source: %s, postProcessor: %s", source, postProcessor);

    if (postProcessor != null) {
      postProcessor.processMetadata(metadata, readParam);
    }
  }
  /**
   * *****************************************************************************************************************
   *
   * <p>Post-processes a raw image using the installed postprocessor, if any.
   *
   * @param image the raw image to postprocess
   * @return the post-processed image
   *     <p>****************************************************************************************************************
   */
  @Nonnull
  protected BufferedImage postProcess(
      final @Nonnull BufferedImage image,
      final @Nonnull RAWMetadataSupport metadata,
      final @Nonnull RAWImageReadParam readParam) {
    logger.fine("postProcess(%s, %s, %s)", image, metadata.getClass(), readParam);
    final Source source = readParam.lookup(Source.class);
    final PostProcessor postProcessor =
        !source.needsPostProcessor() ? null : postProcessorMapBySpiClass.get(getClass());
    logger.finer(">>>> source: %s, postProcessor: %s", source, postProcessor);

    return (postProcessor != null) ? postProcessor.process(image, metadata, readParam) : image;
  }