Java BigInteger Calculate writeBigInteger(BigInteger integer, DataOutputStream out)

Here you can find the source of writeBigInteger(BigInteger integer, DataOutputStream out)

Description

Write a (reasonably short) BigInteger to a stream.

License

Open Source License

Declaration

public static void writeBigInteger(BigInteger integer, DataOutputStream out) throws IOException 

Method Source Code

//package com.java2s;
/*/*from w w  w.  j  a va  2 s . c om*/
 *   This file is part of dhcp4java, a DHCP API for the Java language.
 *   (c) 2006 Stephan Hadinger
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 2.1 of the License, or (at your option) any later version.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.io.DataOutputStream;
import java.io.IOException;
import java.math.BigInteger;

public class Main {
    /**
     * Write a (reasonably short) BigInteger to a stream.
     *  <at> param integer the BigInteger to write
     *  <at> param out the stream to write it to
     */
    public static void writeBigInteger(BigInteger integer, DataOutputStream out) throws IOException {
        if (integer.signum() == -1) {
            //dump("Negative BigInteger", Logger.ERROR, true);
            throw new IllegalStateException("Negative BigInteger!");
        }
        byte[] buf = integer.toByteArray();
        if (buf.length > Short.MAX_VALUE) {
            throw new IllegalStateException("Too long: " + buf.length);
        }
        out.writeShort((short) buf.length);
        out.write(buf);
    }
}

Related

  1. trimToPrecision(BigInteger number, int precision)
  2. uint64ToByteStreamLE(BigInteger val, OutputStream stream)
  3. unsignedBigIntergerToByteArray(BigInteger bigInteger)
  4. unsignedLongToBigInteger(byte[] source)
  5. unsignedToBigInteger(long l)
  6. writeBigInteger(BigInteger m, int n, OutputStream os)
  7. writeBigInteger(ByteArrayOutputStream baos, BigInteger bi)
  8. writeBigInteger(ByteArrayOutputStream stream, BigInteger num)
  9. writeBigInteger(OutputStream output, BigInteger value)