Here you can find the source of writeBigInteger(BigInteger m, int n, OutputStream os)
public static void writeBigInteger(BigInteger m, int n, OutputStream os) throws Exception
//package com.java2s; import java.math.*; import java.io.*; public class Main { public static void writeBigInteger(BigInteger m, int n, OutputStream os) throws Exception { byte[] temp = new byte[n]; BigInteger mask = BigInteger.valueOf(0xFF); for (int j = 0; j < n; j++) { temp[j] = (byte) m.and(mask).intValue(); m = m.shiftRight(8);/*w ww .ja va2 s .c o m*/ } os.write(temp); } public static void writeBigInteger(BigInteger m, ObjectOutputStream oos) throws Exception { byte[] bytes = m.toByteArray(); oos.writeInt(bytes.length); oos.write(bytes); } }