@@ -40,6 +40,42 @@ public static BigInteger readBigIntegerFromInputStream(InputStream inputStream)
40
40
return new BigInteger (receiveInputWithLengthPrefix (inputStream ));
41
41
}
42
42
43
+ /**
44
+ * Method to write a {@link BigInteger} array to an {@link OutputStream}.
45
+ * @param bigIntegers
46
+ * The {@link BigInteger} array to write. No null values are allowed.
47
+ * @param outputStream
48
+ * The {@link OutputStream} to write the instance to. No null values are allowed.
49
+ * @throws IOException
50
+ * If the {@link OutputStream} threw an exception while writing the data.
51
+ */
52
+ public static void writeArrayOfBigIntegersToOutputStream (BigInteger [] bigIntegers , OutputStream outputStream ) throws IOException {
53
+ outputStream .write (ByteBuffer .allocate (4 ).putInt (bigIntegers .length ).array ());
54
+ for (BigInteger bigInteger : bigIntegers ) {
55
+ writeBigIntegerToOutputStream (bigInteger , outputStream );
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Method to read a {@link BigInteger} array from an {@link OutputStream}.
61
+ * @param inputStream
62
+ * The {@link InputStream} to read the instance from. No null values are allowed.
63
+ * @return The resulting {@link BigInteger} array.
64
+ * @throws IOException
65
+ * If the {@link OutputStream} threw an exception while reading the data.
66
+ */
67
+ public static BigInteger [] readArrayOfBigIntegersFromInputStream (InputStream inputStream ) throws IOException {
68
+ ByteBuffer byteBuffer = ByteBuffer .wrap (inputStream .readNBytes (4 ));
69
+ int length = byteBuffer .getInt ();
70
+ byteBuffer .clear ();
71
+
72
+ BigInteger [] bigIntegers = new BigInteger [length ];
73
+ for (int i = 0 ; i < length ; i ++) {
74
+ bigIntegers [i ] = readBigIntegerFromInputStream (inputStream );
75
+ }
76
+ return bigIntegers ;
77
+ }
78
+
43
79
/**
44
80
* Method to read a byte array from an {@link OutputStream}.
45
81
* This method first reads a 4-byte long length prefix at the beginning of the resulting array.
@@ -48,6 +84,7 @@ public static BigInteger readBigIntegerFromInputStream(InputStream inputStream)
48
84
* The {@link InputStream} to read the instance from. No null values are allowed.
49
85
* @throws IOException
50
86
* If the {@link OutputStream} threw an exception while reading the data.
87
+ * @return The resulting byte array.
51
88
*/
52
89
public static byte [] readByteArrayFromInputStream (InputStream inputStream ) throws IOException {
53
90
return receiveInputWithLengthPrefix (inputStream );
0 commit comments