Buffer the Outputstream for response

Add html header to /players
This commit is contained in:
Rsl1122 2017-07-29 22:30:15 +03:00
parent dd299cd8ee
commit 50e3d839e3
2 changed files with 12 additions and 9 deletions

View File

@ -17,10 +17,7 @@ import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.ChatColor;
import javax.net.ssl.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.*;
@ -97,9 +94,15 @@ public class WebServer {
String content = response.getContent();
exchange.sendResponseHeaders(response.getCode(), content.length());
os = exchange.getResponseBody();
os.write(content.getBytes());
try (BufferedOutputStream out = new BufferedOutputStream(exchange.getResponseBody())) {
try (ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) {
byte[] buffer = new byte[2048];
int count;
while ((count = bis.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
}
}
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
throw e;

View File

@ -20,7 +20,7 @@ public class PlayersPageResponse extends Response {
}
public static String buildContent(List<UserData> cached) {
StringBuilder html = new StringBuilder("<h1>Cached Players</h1><p>");
StringBuilder html = new StringBuilder("<!DOCTYPE html><html><body><h1>Cached Players</h1><p>");
int size = cached.size();
html.append(size)
@ -37,7 +37,7 @@ public class PlayersPageResponse extends Response {
}
i++;
}
html.append("</tr></table>");
html.append("</tr></table></body></html>");
return html.toString();
}
}