Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Fix a pairing issue in which HAP-Java could listen on a different interface than that which it advertises [#67](https://github.com/hap-java/HAP-Java/pull/67)
* Allow window covering to be used without optional characteristics. The inclusion of `HoldPositionCharacteristic` did terrible things, and we're still not sure why. Addressed [#56](https://github.com/hap-java/HAP-Java/pull/56)
* Air Purifier didn't support rotation speed characteristics. [#124](https://github.com/hap-java/HAP-Java/pull/124)
* Close JsonWriters [#148](https://github.com/hap-java/HAP-Java/pull/148)

## New and improved

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.*;

public class AccessoryController {

Expand Down Expand Up @@ -64,9 +61,9 @@ public HttpResponse listing() throws Exception {
.add("services", serviceArrayBuilders.get(accessory.getId())));
}

try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Json.createWriter(baos)
.write(Json.createObjectBuilder().add("accessories", accessories).build());
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonWriter jsonWriter = Json.createWriter(baos)) {
jsonWriter.write(Json.createObjectBuilder().add("accessories", accessories).build());
return new HapJsonResponse(baos.toByteArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public HttpResponse get(HttpRequest request) throws Exception {
"Accessory " + aid + " has no characteristics or does not exist. Request: " + uri);
}
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Json.createWriter(baos)
.write(
Json.createObjectBuilder().add("characteristics", characteristics.build()).build());
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonWriter jsonWriter = Json.createWriter(baos)) {
jsonWriter.write(
Json.createObjectBuilder().add("characteristics", characteristics.build()).build());
return new HapJsonResponse(baos.toByteArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import io.github.hapjava.server.impl.http.HttpResponse;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.*;

public class EventController {

Expand All @@ -24,8 +21,9 @@ public HttpResponse getMessage(int accessoryId, int iid, EventableCharacteristic

JsonObject data = Json.createObjectBuilder().add("characteristics", characteristics).build();

try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Json.createWriter(baos).write(data);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonWriter jsonWriter = Json.createWriter(baos)) {
jsonWriter.write(data);
byte[] dataBytes = baos.toByteArray();

return new EventResponse(dataBytes);
Expand All @@ -45,8 +43,9 @@ public HttpResponse getMessage(ArrayList<PendingNotification> notifications) thr

JsonObject data = Json.createObjectBuilder().add("characteristics", characteristics).build();

try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Json.createWriter(baos).write(data);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonWriter jsonWriter = Json.createWriter(baos)) {
jsonWriter.write(data);
byte[] dataBytes = baos.toByteArray();

return new EventResponse(dataBytes);
Expand Down