32
32
import net .minecraft .nbt .NbtOps ;
33
33
import net .minecraft .nbt .Tag ;
34
34
import net .minecraft .network .PacketByteBuf ;
35
+ import org .apache .commons .io .serialization .ValidatingObjectInputStream ;
36
+ import reborncore .RebornCore ;
35
37
36
38
import java .io .ByteArrayInputStream ;
37
39
import java .io .ByteArrayOutputStream ;
38
- import java .io .ObjectInputStream ;
40
+ import java .io .IOException ;
39
41
import java .io .ObjectOutputStream ;
40
42
import java .math .BigInteger ;
41
43
@@ -52,23 +54,25 @@ protected Object readObject() {
52
54
return ObjectBufferUtils .readObject (this );
53
55
}
54
56
57
+ @ Deprecated // Remove in 1.17
55
58
public void writeBigInt (BigInteger bigInteger ) {
56
- try {
57
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
59
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream ()) {
58
60
ObjectOutputStream outputStream = new ObjectOutputStream (baos );
59
61
outputStream .writeObject (bigInteger );
60
62
writeByteArray (baos .toByteArray ());
61
- } catch (Exception e ) {
62
- throw new RuntimeException ( "Failed to write big int" );
63
+ } catch (IOException e ) {
64
+ RebornCore . LOGGER . error ( e );
63
65
}
64
66
}
65
67
66
- public BigInteger readBigInt () {
67
- try {
68
- ObjectInputStream inputStream = new ObjectInputStream (new ByteArrayInputStream (readByteArray ()));
68
+ @ Deprecated // Remove in 1.17
69
+ public BigInteger readBigInt (){
70
+ try (ValidatingObjectInputStream inputStream = new ValidatingObjectInputStream (new ByteArrayInputStream (readByteArray ()))) {
71
+ inputStream .accept (BigInteger .class );
69
72
return (BigInteger ) inputStream .readObject ();
70
- } catch (Exception e ) {
71
- throw new RuntimeException ("Failed to read big int" );
73
+ } catch (IOException | ClassNotFoundException e ) {
74
+ RebornCore .LOGGER .error (e );
75
+ return BigInteger .ZERO ;
72
76
}
73
77
}
74
78
0 commit comments