Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.Charset;

/**
* Represents the information for a single app or package
Expand Down Expand Up @@ -40,8 +41,14 @@ public PICSProductInfo(CMsgClientPICSProductInfoResponse.Builder parentResponse,

keyValues = new KeyValue();
if (appInfo.hasBuffer() && !appInfo.getBuffer().isEmpty()) {
// we don't want to read the trailing null byte
try (MemoryStream ms = new MemoryStream(appInfo.getBuffer().toByteArray(), 0, appInfo.getBuffer().size() - 1)) {
try {
// get the buffer as a string using the jvm's default charset.
// note: IDK why, but we have to encode this using the default charset
String bufferString = appInfo.getBuffer().toString(Charset.defaultCharset());
// get the buffer as a byte array using utf-8 as a supported charset
byte[] byteBuffer = bufferString.getBytes("UTF-8");
// we don't want to read the trailing null byte
MemoryStream ms = new MemoryStream(byteBuffer, 0, byteBuffer.length - 1);
keyValues.readAsText(ms);
} catch (IOException e) {
throw new IllegalArgumentException("failed to read buffer", e);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/in/dragonbra/javasteam/types/KVTextReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import in.dragonbra.javasteam.util.Passable;
import in.dragonbra.javasteam.util.Strings;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
Expand Down Expand Up @@ -139,7 +140,7 @@ public String readToken(Passable<Boolean> wasQuoted, Passable<Boolean> wasCondit
// "
read();

StringBuilder sb = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();

while (!endOfStream()) {
if (peek() == '\\') {
Expand All @@ -152,7 +153,7 @@ public String readToken(Passable<Boolean> wasQuoted, Passable<Boolean> wasCondit
replacedChar = escapedChar;
}

sb.append(replacedChar);
baos.write(replacedChar);

continue;
}
Expand All @@ -161,13 +162,14 @@ public String readToken(Passable<Boolean> wasQuoted, Passable<Boolean> wasCondit
break;
}

sb.append((char) read());
baos.write(read());
}

// "
read();

return sb.toString();
// convert the output stream as an utf-8 supported string.
return baos.toString("UTF-8");
}

if (next == '{' || next == '}') {
Expand Down