docs: @Override
    public CloseableReference<Bitmap> decodeJPEGFromEncodedImageWithColorSpace(
        EncodedImage encodedImage,
        Bitmap.Config bitmapConfig,
        @Nullable Rect regionToDecode,
        int length,
        @Nullable final ColorSpace colorSpace) {
      boolean isJpegComplete = encodedImage.isCompleteAt(length);
      final BitmapFactory.Options options = getDecodeOptionsForStream(encodedImage, bitmapConfig);
      InputStream jpegDataStream = encodedImage.getInputStream();
      // At this point the InputStream from the encoded image should not be null since in the
      // pipeline,this comes from a call stack where this was checked before. Also this method needs
      // the InputStream to decode the image so this can't be null.
      Preconditions.checkNotNull(jpegDataStream);
      if (encodedImage.getSize() > length) {
        jpegDataStream = new LimitedInputStream(jpegDataStream, length);
      }
      if (!isJpegComplete) {
        jpegDataStream = new TailAppendingInputStream(jpegDataStream, EOI_TAIL);
      }
      boolean retryOnFail = options.inPreferredConfig != Bitmap.Config.ARGB_8888;
      try {
        return decodeFromStream(jpegDataStream, options, regionToDecode, colorSpace);
      } catch (RuntimeException re) {
        if (retryOnFail) {
          return decodeJPEGFromEncodedImageWithColorSpace(
              encodedImage, Bitmap.Config.ARGB_8888, regionToDecode, length, colorSpace);
        }
        throw re;
      }
    }