Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[misc] ascii encoding improvement
  • Loading branch information
rusher committed Oct 19, 2022
1 parent 2ca2b89 commit 2bf5502
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -343,8 +343,14 @@ public void writeLength(long length) throws IOException {
}

public void writeAscii(String str) throws IOException {
byte[] arr = str.getBytes(StandardCharsets.US_ASCII);
writeBytes(arr, 0, arr.length);
int len = str.length();
if (len > buf.length - pos) {
byte[] arr = str.getBytes(StandardCharsets.US_ASCII);
writeBytes(arr, 0, arr.length);
}
for (int off = 0; off < len; ) {
this.buf[this.pos++] = (byte) str.charAt(off++);
}
}

public void writeString(String str) throws IOException {
Expand Down

0 comments on commit 2bf5502

Please sign in to comment.