Skip to content

Commit

Permalink
Fix character encoding for binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Jan 29, 2025
1 parent 9c3658e commit a25e4f9
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.*;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
Expand Down Expand Up @@ -242,6 +241,12 @@ public Response queryResult(String rsURL, String queryId, QueryRequest queryRequ
);

byte[] content = httpClientUtil.readBytesFromResponse(resourcesResponse);
FileOutputStream fos = new FileOutputStream("/tmp/test.avro");
fos.write(content);

String contentString = new String(content, StandardCharsets.ISO_8859_1);
logger.info("Query result:");
logger.info(contentString);
if (resourcesResponse.getStatusLine().getStatusCode() != 200) {
logger.error("ResourceRS did not return a 200");
HttpClientUtil.throwResponseError(resourcesResponse, rsURL);
Expand All @@ -250,6 +255,10 @@ public Response queryResult(String rsURL, String queryId, QueryRequest queryRequ
} catch (JsonProcessingException e) {
logger.error("Unable to encode resource credentials");
throw new NotAuthorizedException("Unable to encode resource credentials", e);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
closeHttpResponse(resourcesResponse);
}
Expand Down

0 comments on commit a25e4f9

Please sign in to comment.