unicode fix

This commit is contained in:
Daniella / Tove 2022-07-08 09:17:02 +02:00
parent bb1517901b
commit 80c7e0961a
2 changed files with 31 additions and 1 deletions

View file

@ -57,10 +57,13 @@ public class FileServer implements IRequestCatcher, RequestHandler.Listener {
} }
private String fileContent(Request request, String s) { private String fileContent(Request request, String s) {
String r = request.context.file(s); String r;
if(!s.endsWith(".html") && !s.endsWith(".htm")) { if(!s.endsWith(".html") && !s.endsWith(".htm")) {
r = request.context.file(s);
r = "<pre>" + r.replace("<", "&lt;").replace(">", "&gt;") + "</pre>"; r = "<pre>" + r.replace("<", "&lt;").replace(">", "&gt;") + "</pre>";
} }
else
r = request.context.fileUTF(s);
return r; return r;
} }

View file

@ -2,6 +2,7 @@ package de.tudbut.tryumph.server;
import static de.tudbut.async.Async.*; import static de.tudbut.async.Async.*;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -145,6 +146,32 @@ public class BrowserContext {
} }
return builder.toString(); return builder.toString();
} }
public String fileUTF(String file) {
if(cache.containsKey(file))
return cache.get(file);
String st = null;
try {
InputStream stream = requestCatcher.getClass().getClassLoader().getResourceAsStream(file);
if(stream == null)
stream = new FileInputStream(file);
ByteArrayOutputStream s = new ByteArrayOutputStream();
int i = 0;
while((i = stream.read()) != -1) {
s.write(i);
}
stream.close();
s.close();
st = new String(s.toByteArray());
if(!TryConfig.nocache)
cache.put(file, st);
} catch (IOException e) {
st = "\n<br/><h1>---CUT---</h1><br/>\n";
st+= "Error reading rest of file! Sorry.";
}
return st;
}
} }