Skip to content

Commit

Permalink
Improve performance plain-text generation GET /blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels-NTG committed Dec 14, 2022
1 parent 963c4f2 commit 30021fb
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ public void internalHandle(HttpExchange httpExchange) throws IOException {

// construct response
String method = httpExchange.getRequestMethod().toLowerCase();
String responseString = "";
String responseString;

if (method.equals("put")) {
InputStream bodyStream = httpExchange.getRequestBody();
List<String> body = new BufferedReader(new InputStreamReader(bodyStream))
.lines().collect(Collectors.toList());
.lines().toList();

List<String> returnValues = new LinkedList<>();

Expand Down Expand Up @@ -163,6 +163,7 @@ public void internalHandle(HttpExchange httpExchange) throws IOException {
}
} else if (method.equals("get")) {
JsonArray jsonArray = new JsonArray();
StringBuilder responseStringBuilder = new StringBuilder();
for (int rangeX = x; rangeX < x + dx; rangeX++) {
for (int rangeY = y; rangeY < y + dy; rangeY++) {
for (int rangeZ = z; rangeZ < z + dz; rangeZ++) {
Expand All @@ -182,22 +183,28 @@ public void internalHandle(HttpExchange httpExchange) throws IOException {
}
jsonArray.add(json);
} else {
responseString += rangeX + " " + rangeY + " " + rangeZ + " " + blockId;
responseStringBuilder.append(rangeX);
responseStringBuilder.append(' ');
responseStringBuilder.append(rangeY);
responseStringBuilder.append(' ');
responseStringBuilder.append(rangeZ);
responseStringBuilder.append(' ');
responseStringBuilder.append(getBlockAsStr(blockPos));
if (includeState) {
responseString += getBlockStateAsStr(blockPos);
responseStringBuilder.append(getBlockStateAsStr(blockPos));
}
if (includeData) {
responseString += getBlockDataAsStr(blockPos);
responseStringBuilder.append(getBlockDataAsStr(blockPos));
}
responseString += "\n";
responseStringBuilder.append('\n');
}
}
}
}
if (returnJson) {
responseString = new Gson().toJson(jsonArray);
} else {
responseString = responseString.trim();
responseString = responseStringBuilder.deleteCharAt(responseStringBuilder.length() - 1).toString();
}

} else if (method.equals("options")) {
Expand Down

0 comments on commit 30021fb

Please sign in to comment.