Skip to content

Commit

Permalink
Improved reading of input
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Aug 30, 2024
1 parent 9c744a2 commit 4a97bd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions FROST-Server.Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>de.grundid.opendatalab</groupId>
<artifactId>geojson-jackson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import de.fraunhofer.iosb.ilt.frostserver.util.user.PrincipalExtended;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
Expand All @@ -34,13 +35,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An abstract request for the Service.
*/
public class ServiceRequest {

private static final Logger LOGGER = LoggerFactory.getLogger(ServiceRequest.class);
private static final ThreadLocal<ServiceRequest> LOCAL_REQUEST = new ThreadLocal<>();

private String requestType;
Expand Down Expand Up @@ -102,9 +106,13 @@ public String getContentString() {
if (contentString != null) {
return contentString;
}
return new BufferedReader(new InputStreamReader(contentBinary, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
try {
return IOUtils.toString(contentBinary, StandardCharsets.UTF_8);
} catch (IOException ex) {
LOGGER.debug("Failed to convert input to a string", ex);
LOGGER.error("Failed to convert input to a string: " + ex.getMessage());
throw new IllegalStateException("Failed to read input.");
}
}

/**
Expand Down

0 comments on commit 4a97bd8

Please sign in to comment.