Java BigInteger from Stream readBigInteger(int n, DataInput dis)

Here you can find the source of readBigInteger(int n, DataInput dis)

Description

read Big Integer

License

Open Source License

Declaration

public static BigInteger readBigInteger(int n, DataInput dis) throws IOException 

Method Source Code


//package com.java2s;
import java.io.DataInput;

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

public class Main {
    public static BigInteger readBigInteger(int n, DataInput dis) throws IOException {
        BigInteger ret = BigInteger.ZERO;

        byte[] temp = new byte[n];
        dis.readFully(temp, 0, n);/*www  .  jav  a2 s. c  o  m*/

        for (int j = n - 1; j >= 0; j--) {
            ret = ret.or(BigInteger.valueOf(0xFF & temp[j]));
            ret = ret.shiftLeft(8);
        }
        ret = ret.shiftRight(8);

        return ret;
    }

    public static BigInteger readBigInteger(DataInput ois) throws IOException {
        int length = ois.readInt();
        byte[] bytes = new byte[length];
        ois.readFully(bytes, 0, length);

        return new BigInteger(bytes);
    }
}

Related

  1. readBigInteger(ByteArrayInputStream bais)
  2. readBigInteger(DataInputStream dis)
  3. readBigInteger(InputStream input)
  4. readLineAsBigInteger(BufferedReader br)
  5. readLuposBigInteger(final int numberOfBits, final InputStream is)