Skip to content

Commit

Permalink
javafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Dec 8, 2023
1 parent 0e94263 commit 9a11fc7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions std-bits/base/src/main/java/org/enso/base/net/URIHelpers.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.enso.base.net;

import org.apache.http.client.utils.URIBuilder;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import org.apache.http.client.utils.URIBuilder;

public class URIHelpers {
public record NameValuePair(String name, String value) {}

public static URI addQueryParameters(URI uri, List<NameValuePair> params) throws URISyntaxException {
public static URI addQueryParameters(URI uri, List<NameValuePair> params)
throws URISyntaxException {
URIBuilder builder = new URIBuilder(uri);
for (NameValuePair param : params) {
builder.addParameter(param.name(), param.value());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.enso.shttp;

import com.sun.net.httpserver.HttpExchange;

import java.io.IOException;
import java.util.Base64;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.enso.shttp;

import com.sun.net.httpserver.HttpExchange;

import java.io.IOException;

public class CrashingTestHandler extends SimpleHttpHandler {
@Override
public void doHandle(HttpExchange exchange) throws IOException {
// This exception will be logged by SimpleHttpHandler, but that's OK - let's know that this crash is happening.
// This exception will be logged by SimpleHttpHandler, but that's OK - let's know that this
// crash is happening.
throw new RuntimeException("This handler crashes on purpose.");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.enso.shttp;

import com.sun.net.httpserver.HttpExchange;
import org.apache.http.client.utils.URIBuilder;

import java.io.IOException;
import java.net.URI;
import org.apache.http.client.utils.URIBuilder;

public class HeaderTestHandler extends SimpleHttpHandler {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
import sun.misc.Signal;
import sun.misc.SignalHandler;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;
import sun.misc.Signal;
import sun.misc.SignalHandler;

public class SimpleHTTPBin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -31,7 +30,8 @@ public final void handle(HttpExchange exchange) throws IOException {

public abstract void doHandle(HttpExchange exchange) throws IOException;

protected final void sendResponse(int code, String message, HttpExchange exchange) throws IOException {
protected final void sendResponse(int code, String message, HttpExchange exchange)
throws IOException {
byte[] response = message.getBytes(StandardCharsets.UTF_8);
exchange.getResponseHeaders().add("Content-Type", "text/plain; charset=utf-8");
exchange.sendResponseHeaders(code, response.length);
Expand Down
23 changes: 15 additions & 8 deletions tools/simple-httpbin/src/main/java/org/enso/shttp/TestHandler.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.enso.shttp;

import com.sun.net.httpserver.HttpExchange;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -17,6 +13,9 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;

public class TestHandler extends SimpleHttpHandler {
private final HttpMethod expectedMethod;
Expand Down Expand Up @@ -79,7 +78,8 @@ public void doHandle(HttpExchange exchange) throws IOException {

response.append("\n");
response.append(" },\n");
response.append(" \"origin\": \"" + exchange.getRemoteAddress().getAddress().getHostAddress() + "\",\n");
response.append(
" \"origin\": \"" + exchange.getRemoteAddress().getAddress().getHostAddress() + "\",\n");
response.append(" \"path\": \"" + StringEscapeUtils.escapeJson(uri.getPath()) + "\",\n");
if (uri.getQuery() != null) {
URIBuilder builder = new URIBuilder(uri);
Expand All @@ -89,7 +89,12 @@ public void doHandle(HttpExchange exchange) throws IOException {
NameValuePair param = params.get(i);
String key = StringEscapeUtils.escapeJson(param.getName());
String value = StringEscapeUtils.escapeJson(param.getValue());
response.append(" {\"name\": \"").append(key).append("\", \"value\": \"").append(value).append("\"}");
response
.append(" {\"name\": \"")
.append(key)
.append("\", \"value\": \"")
.append(value)
.append("\"}");
boolean isLast = i == params.size() - 1;
if (!isLast) {
response.append(",\n");
Expand All @@ -108,8 +113,10 @@ public void doHandle(HttpExchange exchange) throws IOException {
response.append(" \"form\": null,\n");
response.append(" \"files\": null,\n");
String value = readBody(exchange.getRequestBody(), textEncoding);
response.append(" \"data\": \"").append(value == null ? "" : StringEscapeUtils.escapeJson(value)).append(
"\",\n");
response
.append(" \"data\": \"")
.append(value == null ? "" : StringEscapeUtils.escapeJson(value))
.append("\",\n");
}
response.append(" \"args\": {}\n");
response.append("}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.enso.shttp;

import com.sun.net.httpserver.HttpExchange;

import java.io.IOException;
import java.util.List;

Expand Down

0 comments on commit 9a11fc7

Please sign in to comment.