1111import java .nio .charset .StandardCharsets ;
1212import java .nio .file .Files ;
1313import java .nio .file .Path ;
14+ import java .util .Arrays ;
1415import java .util .List ;
1516import java .util .Map ;
1617import java .util .Objects ;
@@ -51,7 +52,7 @@ public HttpTransport(HttpClient httpClient) {
5152 ///
5253 /// @param response the client response.
5354 /// @throws MatrixApiException when the server responds with an unsuccessful HTTP Code.
54- private void validateResponse (HttpResponse <String > response ) {
55+ private void validateResponse (HttpResponse <byte [] > response ) {
5556 var code = response .statusCode ();
5657 var body = response .body ();
5758 var headers = response .headers ();
@@ -60,7 +61,7 @@ private void validateResponse(HttpResponse<String> response) {
6061 return ;
6162 }
6263
63- if (body .isBlank ()) {
64+ if (Arrays . toString ( body ) .isBlank ()) {
6465 throw new MatrixException ("Server returned with HTTP Code:" + code );
6566 }
6667 ErrorResponse errorResponse ;
@@ -96,7 +97,7 @@ private void validateResponse(HttpResponse<String> response) {
9697 /// @throws MatrixIOException if an I/O error has occurred while sending the request.
9798 /// @throws MatrixInterruptedException if the operation has been interrupted.
9899 /// @throws MatrixApiException when the response from the server is not successful.
99- public String getRequest (URI path , @ Nullable String authToken ) {
100+ public byte [] getRequest (URI path , @ Nullable String authToken ) {
100101 var builderRequest =
101102 HttpRequest .newBuilder ().uri (path ).header (CONTENT_TYPE , APPLICATION_JSON ).GET ();
102103
@@ -105,9 +106,9 @@ public String getRequest(URI path, @Nullable String authToken) {
105106 }
106107 var request = builderRequest .build ();
107108
108- HttpResponse <String > response ;
109+ HttpResponse <byte [] > response ;
109110 try {
110- response = client .send (request , HttpResponse .BodyHandlers .ofString ());
111+ response = client .send (request , HttpResponse .BodyHandlers .ofByteArray ());
111112 } catch (IOException e ) {
112113 throw new MatrixIOException (
113114 "There has been an I/O error attempting to process this request" , e );
@@ -128,7 +129,7 @@ public String getRequest(URI path, @Nullable String authToken) {
128129 /// @throws MatrixIOException if an I/O error has occurred while sending the request.
129130 /// @throws MatrixInterruptedException if the operation has been interrupted.
130131 /// @throws MatrixApiException when the response from the server is not successful.
131- public String postRequest (URI path , @ Nullable String body , @ Nullable String authToken ) {
132+ public byte [] postRequest (URI path , @ Nullable String body , @ Nullable String authToken ) {
132133 var builderRequest = HttpRequest .newBuilder ().uri (path );
133134
134135 if (body != null ) {
@@ -145,9 +146,9 @@ public String postRequest(URI path, @Nullable String body, @Nullable String auth
145146 }
146147 var request = builderRequest .build ();
147148
148- HttpResponse <String > response ;
149+ HttpResponse <byte [] > response ;
149150 try {
150- response = client .send (request , HttpResponse .BodyHandlers .ofString ());
151+ response = client .send (request , HttpResponse .BodyHandlers .ofByteArray ());
151152 } catch (IOException e ) {
152153 throw new MatrixIOException (
153154 "There has been an I/O error attempting to process this request" , e );
@@ -170,7 +171,7 @@ public String postRequest(URI path, @Nullable String body, @Nullable String auth
170171 /// @throws MatrixInterruptedException if the operation has been interrupted or a server returned
171172 /// with unsuccessful HTTP Code.
172173 /// @throws MatrixApiException when the response from the server is not successful.
173- public String postAuth (URI path , @ Nullable String body ) {
174+ public byte [] postAuth (URI path , @ Nullable String body ) {
174175 var builderRequest = HttpRequest .newBuilder ().uri (path );
175176
176177 builderRequest .header (CONTENT_TYPE , "application/x-www-form-urlencoded" );
@@ -182,9 +183,9 @@ public String postAuth(URI path, @Nullable String body) {
182183
183184 var request = builderRequest .build ();
184185
185- HttpResponse <String > response ;
186+ HttpResponse <byte [] > response ;
186187 try {
187- response = client .send (request , HttpResponse .BodyHandlers .ofString ());
188+ response = client .send (request , HttpResponse .BodyHandlers .ofByteArray ());
188189 } catch (IOException e ) {
189190 throw new MatrixIOException (
190191 "There has been an I/O error attempting to process this request" , e );
@@ -206,7 +207,7 @@ public String postAuth(URI path, @Nullable String body) {
206207 /// @throws MatrixInterruptedException if the operation has been interrupted or a server returned
207208 /// with unsuccessful HTTP Code.
208209 /// @throws MatrixApiException when the response from the server is not successful.
209- public String putRequest (URI path , @ Nullable String body , String authToken ) {
210+ public byte [] putRequest (URI path , @ Nullable String body , String authToken ) {
210211
211212 var builderRequest =
212213 HttpRequest .newBuilder ()
@@ -219,9 +220,9 @@ public String putRequest(URI path, @Nullable String body, String authToken) {
219220 : HttpRequest .BodyPublishers .noBody ());
220221 var request = builderRequest .build ();
221222
222- HttpResponse <String > response ;
223+ HttpResponse <byte [] > response ;
223224 try {
224- response = client .send (request , HttpResponse .BodyHandlers .ofString ());
225+ response = client .send (request , HttpResponse .BodyHandlers .ofByteArray ());
225226 } catch (IOException e ) {
226227 throw new MatrixIOException (
227228 "There has been an I/O error attempting to process this request" , e );
@@ -245,7 +246,7 @@ public String putRequest(URI path, @Nullable String body, String authToken) {
245246 /// @throws MatrixInterruptedException if the operation has been interrupted or a server returned
246247 /// with unsuccessful HTTP Code.
247248 /// @throws MatrixApiException when the response from the server is not successful.
248- public String putResource (URI path , Path resource , String authToken ) {
249+ public byte [] putResource (URI path , Path resource , String authToken ) {
249250 HttpRequest uploadRequest ;
250251 try {
251252 uploadRequest =
@@ -260,9 +261,9 @@ public String putResource(URI path, Path resource, String authToken) {
260261 "There has been an I/O error attempting to process this request" , e );
261262 }
262263
263- HttpResponse <String > response ;
264+ HttpResponse <byte [] > response ;
264265 try {
265- response = client .send (uploadRequest , HttpResponse .BodyHandlers .ofString ());
266+ response = client .send (uploadRequest , HttpResponse .BodyHandlers .ofByteArray ());
266267 } catch (IOException e ) {
267268 throw new MatrixIOException (
268269 "There has been an I/O error attempting to process this request" , e );
@@ -283,17 +284,17 @@ public String putResource(URI path, Path resource, String authToken) {
283284 /// @throws MatrixInterruptedException if the operation has been interrupted or a server returned
284285 /// with unsuccessful HTTP Code.
285286 /// @throws MatrixApiException when the response from the server is not successful.
286- public String deleteRequest (URI path , String authToken ) {
287+ public byte [] deleteRequest (URI path , String authToken ) {
287288 HttpRequest deleteRequest =
288289 HttpRequest .newBuilder ()
289290 .uri (path )
290291 .header (AUTHORIZATION , BEARER + authToken )
291292 .DELETE ()
292293 .build ();
293294
294- HttpResponse <String > response ;
295+ HttpResponse <byte [] > response ;
295296 try {
296- response = client .send (deleteRequest , HttpResponse .BodyHandlers .ofString ());
297+ response = client .send (deleteRequest , HttpResponse .BodyHandlers .ofByteArray ());
297298 } catch (IOException e ) {
298299 throw new MatrixIOException (
299300 "There has been an I/O error attempting to process this request" , e );
@@ -328,7 +329,7 @@ public URI generateEncodedURI(String baseUrl, String path, @Nullable Map<String,
328329 return new URI (
329330 base .getScheme (), base .getAuthority (), path , query .isEmpty () ? null : query , null );
330331 } catch (URISyntaxException e ) {
331- throw new MatrixIOException ("Failure parsing URI" , e );
332+ throw new MatrixException ("Failure parsing URI" , e );
332333 }
333334 }
334335
@@ -347,7 +348,7 @@ public URI generateRawURI(String baseUrl, String path, @Nullable Map<String, Obj
347348 return new URI (
348349 base .getScheme (), base .getAuthority (), path , query .isEmpty () ? null : query , null );
349350 } catch (URISyntaxException e ) {
350- throw new MatrixIOException ("Failure parsing URI" , e );
351+ throw new MatrixException ("Failure parsing URI" , e );
351352 }
352353 }
353354
0 commit comments