ByteArrayInputStream(data).use {
ImageIO.read(it)
}?.let {
- elementCache.get(uri.toString().decode().normalize()) {
+ elementCache.get(uri.toString()) {
LinkedElement(uri.toString(), properties = mapOf("type" to "image", "size" to data.size, "sizeHuman" to data.size.human))
.apply {
logger.fine("Downloaded image from $link: size=${properties["size"]}.")
}
mimeType.baseType == "text/html" -> {
val document = Jsoup.parse(data.toString(Charset.forName(mimeType.getParameter("charset") ?: "UTF-8")))
- elementCache.get(uri.toString().decode().normalize()) {
+ elementCache.get(uri.toString()) {
LinkedElement(uri.toString(), properties = mapOf(
"type" to "html", "size" to data.size, "sizeHuman" to data.size.human,
"title" to document.title().emptyToNull,
}
override fun failed(uri: FreenetURI) {
- failureCache.put(uri.toString().decode().normalize(), true)
+ failureCache.put(uri.toString(), true)
removeLoadingLink(uri)
logger.fine { "Download failed for $uri." }
}
private fun removeLoadingLink(uri: FreenetURI) {
synchronized(loadingLinks) {
- loadingLinks.invalidate(uri.toString().decode().normalize())
+ loadingLinks.invalidate(uri.toString())
}
}
}
}
if (loadingLinks.getIfPresent(normalizedLink) == null) {
loadingLinks.put(normalizedLink, true)
- freenetInterface.startFetch(FreenetURI(link), callback)
+ freenetInterface.startFetch(FreenetURI(normalizedLink), callback)
}
}
return LinkedElement(link, loading = true)
}
}
+ @Test
+ fun `element loader decodes and normalizes link`() {
+ runWithCallback(decomposedKey) { _, _, _, fetchedUris ->
+ assertThat(fetchedUris(), contains(FreenetURI(normalizedKey)))
+ }
+ }
+
private fun read(resource: String): ByteArray =
javaClass.getResourceAsStream(resource)?.use { input ->
ByteArrayOutputStream().use {