-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Labels
Description
#2501 # Description
I am using a custom decoder for encrypted images. My Decoder decrypts the encrypted input stream and then decodes Images just like it is done in DefaultImageDecoder. I noticed that images fetched using this decoder are not saved in cache and is fetched from network every time. I would like to cache these images just like others
Reproduction
class MyImageDecoder(private val elementToDecrypt: ElementToDecrypt?) : ImageDecoder {
private val poolFactory: PoolFactory by inject(PoolFactory::class.java)
val defaultDecoder: DefaultImageDecoder by inject(DefaultImageDecoder::class.java)
override fun decode(
encodedImage: EncodedImage,
length: Int,
qualityInfo: QualityInfo,
options: ImageDecodeOptions
): CloseableImage {
var decryptedInputStream: InputStream? = null
var clearEncodedImage: EncodedImage? = null
try {
val inputStream = encodedImage.inputStream
decryptedInputStream = elementToDecrypt?.let {
DecryptStore.decryptStream(inputStream, elementToDecrypt)
} ?: inputStream
val bytes = poolFactory.pooledByteBufferFactory.newByteBuffer(decryptedInputStream)
val bytesClosable = CloseableReference.of(bytes)
clearEncodedImage = EncodedImage(bytesClosable)
var imageFormat = encodedImage.imageFormat
if (imageFormat == null || imageFormat === ImageFormat.UNKNOWN) {
imageFormat =
ImageFormatChecker.getImageFormat_WrapIOException(clearEncodedImage.inputStream)
encodedImage.imageFormat = imageFormat
}
when {
imageFormat === DefaultImageFormats.JPEG -> {
return defaultDecoder.decodeJpeg(clearEncodedImage, length, qualityInfo, options)
}
imageFormat === DefaultImageFormats.GIF -> {
return defaultDecoder.decodeGif(clearEncodedImage, length, qualityInfo, options)
}
imageFormat === DefaultImageFormats.WEBP_ANIMATED -> {
return defaultDecoder.decodeAnimatedWebp(clearEncodedImage, length, qualityInfo, options)
}
imageFormat === ImageFormat.UNKNOWN -> {
throw DecodeException("unknown image format", clearEncodedImage)
}
else -> {
throw DecodeException("unknown image format", clearEncodedImage)
}
}
} catch (ex: Exception) {
Timber.e("Something went wrong decoding the image")
throw ex
} finally {
decryptedInputStream?.close()
clearEncodedImage?.close()
}
}
}
Additional Information
- Fresco version: 2.3.0