Here you can find the source of readLuposBigInteger(final int numberOfBits, final InputStream is)
readLuposBigInteger.
Parameter | Description |
---|---|
numberOfBits | a int. |
is | a java.io.InputStream object. |
Parameter | Description |
---|
public final static BigInteger readLuposBigInteger(final int numberOfBits, final InputStream is) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; public class Main { /**//from w w w .j a va2 s .c om * <p>readLuposBigInteger.</p> * * @param numberOfBits a int. * @param is a {@link java.io.InputStream} object. * @return a {@link java.math.BigInteger} object. * @throws java.io.IOException if any. */ public final static BigInteger readLuposBigInteger(final int numberOfBits, final InputStream is) throws IOException { BigInteger result = BigInteger.ZERO; BigInteger factor = BigInteger.ONE; final BigInteger BYTE = BigInteger.valueOf(256); int remainingBits = numberOfBits; while (remainingBits > 0) { final int currentValueByte = is.read(); if (currentValueByte < 0) { // EOF reached! return null; } final BigInteger currentValue = BigInteger.valueOf(currentValueByte); result = result.add(currentValue.multiply(factor)); factor = factor.multiply(BYTE); remainingBits -= 8; } return result; } }