Skip to content

Commit d69840b

Browse files
committed
Fixed #251
1 parent 23e9afd commit d69840b

1 file changed

Lines changed: 27 additions & 22 deletions

File tree

lib/src/main/java/xyz/gianlu/librespot/dealer/DealerClient.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,36 @@ private void handleMessage(@NotNull JsonObject obj) {
121121
JsonArray payloads = obj.getAsJsonArray("payloads");
122122
byte[] decodedPayload;
123123
if (payloads != null) {
124-
String[] payloadsStr = new String[payloads.size()];
125-
for (int i = 0; i < payloads.size(); i++) payloadsStr[i] = payloads.get(i).getAsString();
126-
127-
InputStream in = BytesArrayList.streamBase64(payloadsStr);
128-
if ("gzip".equals(headers.get("Transfer-Encoding"))) {
129-
try {
130-
in = new GZIPInputStream(in);
131-
} catch (IOException ex) {
132-
LOGGER.warn("Failed decompressing message! {uri: {}}", uri, ex);
133-
return;
124+
if ("application/json".equals(headers.get("Content-Type"))) {
125+
if (payloads.size() > 1) throw new UnsupportedOperationException();
126+
decodedPayload = payloads.get(0).getAsJsonObject().toString().getBytes();
127+
} else {
128+
String[] payloadsStr = new String[payloads.size()];
129+
for (int i = 0; i < payloads.size(); i++) payloadsStr[i] = payloads.get(i).getAsString();
130+
131+
InputStream in = BytesArrayList.streamBase64(payloadsStr);
132+
if ("gzip".equals(headers.get("Transfer-Encoding"))) {
133+
try {
134+
in = new GZIPInputStream(in);
135+
} catch (IOException ex) {
136+
LOGGER.warn("Failed decompressing message! {uri: {}}", uri, ex);
137+
return;
138+
}
134139
}
135-
}
136140

137-
try {
138-
ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
139-
byte[] buffer = new byte[1024];
140-
int read;
141-
while ((read = in.read(buffer)) != -1) out.write(buffer, 0, read);
142-
decodedPayload = out.toByteArray();
143-
} catch (IOException ex) {
144-
throw new IllegalStateException(ex);
145-
} finally {
146141
try {
147-
in.close();
148-
} catch (IOException ignored) {
142+
ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
143+
byte[] buffer = new byte[1024];
144+
int read;
145+
while ((read = in.read(buffer)) != -1) out.write(buffer, 0, read);
146+
decodedPayload = out.toByteArray();
147+
} catch (IOException ex) {
148+
throw new IllegalStateException(ex);
149+
} finally {
150+
try {
151+
in.close();
152+
} catch (IOException ignored) {
153+
}
149154
}
150155
}
151156
} else {

0 commit comments

Comments
 (0)