Here you can find the source of writeBigInteger(ByteArrayOutputStream stream, BigInteger num)
private static void writeBigInteger(ByteArrayOutputStream stream, BigInteger num) throws IOException
//package com.java2s; /*/* ww w. java 2 s . c o m*/ * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigInteger; public class Main { private static void writeBigInteger(ByteArrayOutputStream stream, BigInteger num) throws IOException { int length = num.toByteArray().length; byte[] data = new byte[4]; data[0] = (byte) ((length >> 24) & 0xFF); data[1] = (byte) ((length >> 16) & 0xFF); data[2] = (byte) ((length >> 8) & 0xFF); data[3] = (byte) (length & 0xFF); stream.write(data); stream.write(num.toByteArray()); } }