77import java .util .stream .*;
88
99public class MerkleNode {
10+
1011 public final Multihash hash ;
1112 public final Optional <String > name ;
1213 public final Optional <Integer > size ;
14+ public final Optional <String > largeSize ;
1315 public final Optional <Integer > type ;
1416 public final List <MerkleNode > links ;
1517 public final Optional <byte []> data ;
1618
17- public MerkleNode (String hash ) {
18- this (hash , Optional .empty ());
19- }
20-
21- public MerkleNode (String hash , Optional <String > name ) {
22- this (hash , name , Optional .empty (), Optional .empty (), Arrays .asList (), Optional .empty ());
23- }
24-
25- public MerkleNode (String hash , Optional <String > name , Optional <Integer > size , Optional <Integer > type , List <MerkleNode > links , Optional <byte []> data ) {
19+ public MerkleNode (String hash ,
20+ Optional <String > name ,
21+ Optional <Integer > size ,
22+ Optional <String > largeSize ,
23+ Optional <Integer > type ,
24+ List <MerkleNode > links ,
25+ Optional <byte []> data ) {
2626 this .name = name ;
2727 this .hash = Cid .decode (hash );
2828 this .size = size ;
29+ this .largeSize = largeSize ;
2930 this .type = type ;
3031 this .links = links ;
3132 this .data = data ;
3233 }
3334
35+ public MerkleNode (String hash ) {
36+ this (hash , Optional .empty ());
37+ }
38+
39+ public MerkleNode (String hash , Optional <String > name ) {
40+ this (hash , name , Optional .empty (), Optional .empty (), Optional .empty (), Arrays .asList (), Optional .empty ());
41+ }
42+
3443 @ Override
3544 public boolean equals (Object b ) {
3645 if (!(b instanceof MerkleNode ))
@@ -51,13 +60,25 @@ public static MerkleNode fromJSON(Object rawjson) {
5160 String hash = (String )json .get ("Hash" );
5261 if (hash == null )
5362 hash = (String )json .get ("Key" );
54- Optional <String > name = json .containsKey ("Name" ) ? Optional .of ((String ) json .get ("Name" )): Optional .empty ();
55- Optional <Integer > size = json .containsKey ("Size" ) ? Optional .<Integer >empty ().of ((Integer ) json .get ("Size" )): Optional .<Integer >empty ().empty ();
56- Optional <Integer > type = json .containsKey ("Type" ) ? Optional .<Integer >empty ().of ((Integer ) json .get ("Type" )): Optional .<Integer >empty ().empty ();
63+ Optional <String > name = json .containsKey ("Name" ) ?
64+ Optional .of ((String ) json .get ("Name" )) :
65+ Optional .empty ();
66+ Object rawSize = json .get ("Size" );
67+ Optional <Integer > size = rawSize instanceof Integer ?
68+ Optional .of ((Integer ) rawSize ) :
69+ Optional .empty ();
70+ Optional <String > largeSize = rawSize instanceof String ?
71+ Optional .of ((String ) json .get ("Size" )) :
72+ Optional .empty ();
73+ Optional <Integer > type = json .containsKey ("Type" ) ?
74+ Optional .of ((Integer ) json .get ("Type" )) :
75+ Optional .empty ();
5776 List <Object > linksRaw = (List <Object >) json .get ("Links" );
58- List <MerkleNode > links = linksRaw == null ? Collections .EMPTY_LIST : linksRaw .stream ().map (x -> MerkleNode .fromJSON (x )).collect (Collectors .toList ());
77+ List <MerkleNode > links = linksRaw == null ?
78+ Collections .emptyList () :
79+ linksRaw .stream ().map (x -> MerkleNode .fromJSON (x )).collect (Collectors .toList ());
5980 Optional <byte []> data = json .containsKey ("Data" ) ? Optional .of (((String )json .get ("Data" )).getBytes ()): Optional .empty ();
60- return new MerkleNode (hash , name , size , type , links , data );
81+ return new MerkleNode (hash , name , size , largeSize , type , links , data );
6182 }
6283
6384 public Object toJSON () {
@@ -69,7 +90,7 @@ public Object toJSON() {
6990 if (name .isPresent ())
7091 res .put ("Name" , name .get ());
7192 if (size .isPresent ())
72- res .put ("Size" , size .get ());
93+ res .put ("Size" , size .isPresent () ? size . get () : largeSize . get ());
7394 if (type .isPresent ())
7495 res .put ("Type" , type .get ());
7596 return res ;
0 commit comments