unicode fix
This commit is contained in:
parent
bb1517901b
commit
80c7e0961a
2 changed files with 31 additions and 1 deletions
|
@ -57,10 +57,13 @@ public class FileServer implements IRequestCatcher, RequestHandler.Listener {
|
|||
}
|
||||
|
||||
private String fileContent(Request request, String s) {
|
||||
String r = request.context.file(s);
|
||||
String r;
|
||||
if(!s.endsWith(".html") && !s.endsWith(".htm")) {
|
||||
r = request.context.file(s);
|
||||
r = "<pre>" + r.replace("<", "<").replace(">", ">") + "</pre>";
|
||||
}
|
||||
else
|
||||
r = request.context.fileUTF(s);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.tudbut.tryumph.server;
|
|||
|
||||
import static de.tudbut.async.Async.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -145,6 +146,32 @@ public class BrowserContext {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue