File tree Expand file tree Collapse file tree
src/main/java/org/unicitylabs/sdk Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import okhttp3 .*;
55import org .unicitylabs .sdk .serializer .UnicityObjectMapper ;
66
7+ import java .io .ByteArrayOutputStream ;
78import java .io .IOException ;
89import java .io .InputStream ;
910import java .nio .charset .StandardCharsets ;
@@ -158,13 +159,20 @@ private String readBounded(ResponseBody body) throws IOException {
158159 }
159160
160161 try (InputStream in = body .byteStream ()) {
161- // Read one byte past the limit: if that many bytes are available the body is too large.
162- byte [] bytes = in .readNBytes (this .maxResponseBytes + 1 );
163- if (bytes .length > this .maxResponseBytes ) {
164- throw new IOException ("JSON-RPC response exceeds the maximum allowed size." );
162+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
163+ byte [] buffer = new byte [8192 ];
164+ int total = 0 ;
165+ int read ;
166+ while ((read = in .read (buffer )) != -1 ) {
167+ total += read ;
168+ if (total > this .maxResponseBytes ) {
169+ throw new IOException ("JSON-RPC response exceeds the maximum allowed size." );
170+ }
171+ out .write (buffer , 0 , read );
165172 }
166173
167- return new String (bytes , StandardCharsets .UTF_8 );
174+ // ByteArrayOutputStream.toString(Charset) is post-API-31; construct the String directly.
175+ return new String (out .toByteArray (), StandardCharsets .UTF_8 );
168176 }
169177 }
170178}
Original file line number Diff line number Diff line change @@ -68,7 +68,17 @@ public static PaymentAssetCollection fromCbor(byte[] bytes) {
6868 * order of the raw id bytes, a shorter id ordered before a longer one that it is a prefix of.
6969 */
7070 private static int compareAssets (Asset a , Asset b ) {
71- return Arrays .compareUnsigned (a .getId ().getBytes (), b .getId ().getBytes ());
71+ byte [] x = a .getId ().getBytes ();
72+ byte [] y = b .getId ().getBytes ();
73+ int length = Math .min (x .length , y .length );
74+ for (int i = 0 ; i < length ; i ++) {
75+ int diff = (x [i ] & 0xFF ) - (y [i ] & 0xFF );
76+ if (diff != 0 ) {
77+ return diff ;
78+ }
79+ }
80+
81+ return x .length - y .length ;
7282 }
7383
7484 private static PaymentAssetCollection fromList (List <Asset > assets ) {
You can’t perform that action at this time.
0 commit comments