Skip to content

Commit c67c3b4

Browse files
emopersWajihulhassan
authored andcommitted
Fixing usage of DataOutputStream
Signed-off-by: Wajihulhassan <wajih.lums@gmail.com>
1 parent 4c28d24 commit c67c3b4

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/wire/MqttSubscribe.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public byte[] getPayload() throws MqttException {
128128
encodeUTF8(dos,names[i]);
129129
dos.writeByte(qos[i]);
130130
}
131+
dos.flush();
131132
return baos.toByteArray();
132133
} catch (IOException ex) {
133134
throw new MqttException(ex);

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/wire/MqttUnsubscribe.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,17 @@ protected byte[] getVariableHeader() throws MqttException {
9999
}
100100

101101
public byte[] getPayload() throws MqttException {
102-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
103-
DataOutputStream dos = new DataOutputStream(baos);
104-
for (int i=0; i<names.length; i++) {
105-
encodeUTF8(dos, names[i]);
102+
try {
103+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
104+
DataOutputStream dos = new DataOutputStream(baos);
105+
for (int i=0; i<names.length; i++) {
106+
encodeUTF8(dos, names[i]);
107+
}
108+
dos.flush();
109+
return baos.toByteArray();
110+
} catch (IOException ex) {
111+
throw new MqttException(ex);
106112
}
107-
return baos.toByteArray();
108113
}
109114

110115
public boolean isRetryable() {

0 commit comments

Comments
 (0)