2
2
3
3
import com .google .gson .Gson ;
4
4
import io .goodforgod .api .etherscan .error .EtherScanKeyException ;
5
+ import io .goodforgod .api .etherscan .error .EtherScanParseException ;
5
6
import io .goodforgod .api .etherscan .http .EthHttpClient ;
6
7
import io .goodforgod .api .etherscan .http .impl .UrlEthHttpClient ;
7
8
import io .goodforgod .api .etherscan .manager .RequestQueueManager ;
8
9
import io .goodforgod .api .etherscan .util .BasicUtils ;
9
10
import io .goodforgod .gson .configuration .GsonConfiguration ;
11
+ import java .io .ByteArrayInputStream ;
12
+ import java .io .IOException ;
13
+ import java .io .InputStreamReader ;
10
14
import java .nio .charset .StandardCharsets ;
11
15
import java .util .function .Supplier ;
12
16
import org .jetbrains .annotations .NotNull ;
@@ -30,8 +34,11 @@ final class EthScanAPIBuilder implements EtherScanAPI.Builder {
30
34
31
35
@ Override
32
36
public <T > @ NotNull T fromJson (byte [] jsonAsByteArray , @ NotNull Class <T > type ) {
33
- final String jsonAsString = new String (jsonAsByteArray , StandardCharsets .UTF_8 );
34
- return gson .fromJson (jsonAsString , type );
37
+ try (InputStreamReader isr = new InputStreamReader (new ByteArrayInputStream (jsonAsByteArray ))) {
38
+ return gson .fromJson (isr , type );
39
+ } catch (IOException e ) {
40
+ throw new EtherScanParseException (e .getMessage (), e , new String (jsonAsByteArray , StandardCharsets .UTF_8 ));
41
+ }
35
42
}
36
43
};
37
44
0 commit comments