Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
URL Viewer : decode raw text using the eventual response charset.
luccioman1b3c169a9c3b
diff --git a/htroot/ViewFile.java b/htroot/ViewFile.javaindex 9a7262ac2..bfa6c4a65 100644--- a/htroot/ViewFile.java+++ b/htroot/ViewFile.java@@ -29,6 +29,9 @@import java.io.IOException;import java.net.MalformedURLException;+import java.nio.charset.Charset;+import java.nio.charset.IllegalCharsetNameException;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import java.util.Collection;import java.util.Date;@@ -202,7 +205,20 @@ public class ViewFile {// TODO: how to handle very large files here ?String content;try {- content = UTF8.String(response.getContent());+ String charsetName = response.getCharacterEncoding();+ try {+ if(charsetName == null) {+ /* Encoding is unknown from response headers : default decode using UTF-8 */+ charsetName = StandardCharsets.UTF_8.name();+ } else if(!Charset.isSupported(charsetName)) {+ /* Encoding is known but not supported on this system : default decode using UTF-8 */+ charsetName = StandardCharsets.UTF_8.name();+ }+ } catch(IllegalCharsetNameException e) {+ /* Encoding is known but charset name is not valid : default decode using UTF-8 */+ charsetName = StandardCharsets.UTF_8.name();+ }+ content = new String(response.getContent(), charsetName);} catch (final Exception e) {prop.put("error", "4");prop.putHTML("error_errorText", e.getMessage());