protected InputStream resetStream(InputStream imageStream, ImageDecodingInfo decodingInfo)
     throws IOException {
   try {
     imageStream.reset();
   } catch (IOException e) {
     IoUtils.closeSilently(imageStream);
     imageStream = getImageStream(decodingInfo);
   }
   return imageStream;
 }
  /**
   * Decodes image from URI into {@link Bitmap}. Image is scaled close to incoming {@linkplain
   * ImageSize target size} during decoding (depend on incoming parameters).
   *
   * @param decodingInfo Needed data for decoding image
   * @return Decoded bitmap
   * @throws IOException if some I/O exception occurs during image reading
   * @throws UnsupportedOperationException if image URI has unsupported scheme(protocol)
   */
  @Override
  public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException {
    Bitmap decodedBitmap;
    ImageFileInfo imageInfo;

    InputStream imageStream = getImageStream(decodingInfo);
    try {
      imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
      imageStream = resetStream(imageStream, decodingInfo);
      Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize, decodingInfo);
      decodedBitmap = BitmapFactory.decodeStream(imageStream, null, decodingOptions);
    } finally {
      IoUtils.closeSilently(imageStream);
    }

    if (decodedBitmap == null) {
      L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey());
    } else {
      decodedBitmap =
          considerExactScaleAndOrientatiton(
              decodedBitmap, decodingInfo, imageInfo.exif.rotation, imageInfo.exif.flipHorizontal);
    }
    return decodedBitmap;
  }