Example usage for java.math BigInteger valueOf

List of usage examples for java.math BigInteger valueOf

Introduction

In this page you can find the example usage for java.math BigInteger valueOf.

Prototype

private static BigInteger valueOf(int val[]) 

Source Link

Document

Returns a BigInteger with the given two's complement representation.

Usage

From source file:com.sourcesense.opencmis.server.HstCmisRepository.java

/**
 * CMIS getContentStream./* w  ww  .j av  a2s  .  c  o  m*/
 */
public ContentStream getContentStream(CallContext context, String objectId, BigInteger offset,
        BigInteger length, HttpServletRequest servletRequest)
        throws ObjectBeanManagerException, RepositoryException {
    debug("getContentStream");
    checkUser(context, false);

    if ((offset != null) || (length != null)) {
        throw new CmisInvalidArgumentException("Offset and Length are not supported!");
    }
    HstRequestContext requestContext = getRequestContext(servletRequest);
    ObjectBeanPersistenceManager contentPersistenceManager = getContentPersistenceManager(requestContext);
    HippoBean bean = (HippoBean) contentPersistenceManager.getObjectByUuid(objectId);

    if (!bean.isHippoDocumentBean()) {
        throw new CmisStreamNotSupportedException("Not a Hippo Bean!");
    }

    try {
        File tempFile = File.createTempFile("cmis", ".temp");
        FileOutputStream fos = new FileOutputStream(tempFile);
        String path = bean.getPath();

        contentPersistenceManager.getSession().exportDocumentView(path, fos, false, false);
        fos.flush();

        // compile data
        ContentStreamImpl result = new ContentStreamImpl();
        result.setFileName(bean.getName());
        result.setLength(BigInteger.valueOf(tempFile.length()));
        result.setMimeType(MIMETypes.getMIMEType("text/xml"));
        result.setStream(new FileInputStream(tempFile));

        return result;

    } catch (Exception e) {
        sendCmisServiceError(e);
        return null;
    }
}

From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java

public BigInteger addCell(EventSender evt, String adminVIP, String dataVIP) throws MgmtException {

    logger.info("MC: addCell adminVip " + adminVIP + ", dataVIP = " + dataVIP);
    byte res = -1;

    ////  w ww.j  a  va 2 s.co m
    // First check this cell has 16 nodes
    //
    boolean acceptMC8Nodes = config.getPropertyAsBoolean(ConfigPropertyNames.PROP_ACCEPT_8_NODES);
    //
    // FIXME - use MAX NODES property
    //
    if (numNodes < 16) {
        if (acceptMC8Nodes) {
            logger.info("MC: cluster is not 16 nodes but is " + "configured to accept mc configuration");
        } else {
            try {
                evt.sendAsynchronousEvent("Need to 16 nodes cell to be " + "able to add more cells");
            } catch (Exception ignore) {
                logger.severe("failed to send the async " + "event ");
            }
            return BigInteger.valueOf(-1);
        }
    }

    MultiCellIntf api = MultiCellIntf.Proxy.getMultiCellAPI();
    if (api == null) {
        logger.severe("failed to grab multicellAPI");
        return BigInteger.valueOf(-1);
    }
    try {
        res = api.addCellStart(adminVIP, dataVIP);
        evt.sendAsynchronousEvent("Successfully established connection with " + "the remote cell");

        res = api.addCellSchemaValidation();
        evt.sendAsynchronousEvent("Successfully checked schema is " + "identical on both cells");

        res = api.addCellPropertiesValidation();
        evt.sendAsynchronousEvent("Successfully checked properties are " + "identical on both cells");

        res = api.addCellUpdateHiveConfig();
        evt.sendAsynchronousEvent("Successfully updated the hive " + "configuration ");

        return BigInteger.valueOf(res);
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, "failed to add cell in the hive", ioe);
        //
        // Internationalize here
        //
        throw new MgmtException("Internal error while adding the new cell " + "in the hive");
    } catch (MultiCellException mue) {
        logger.log(Level.SEVERE, "failed to add cell in the hive", mue);
        throw new MgmtException(mue.getMessage());
    } catch (ManagedServiceException mse) {
        logger.log(Level.SEVERE, "failed to add cell in the hive", mse);
        throw new MgmtException("Internal error while adding the new cell " + "in the hive");
    }
}

From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java

private BigInteger step2cComputeUpperBound(final BigInteger r, final BigInteger modulus,
        final BigInteger lowerIntervalBound) {
    BigInteger upperBound = BigInteger.valueOf(3).multiply(this.bigB);
    upperBound = upperBound.add(r.multiply(modulus));
    upperBound = upperBound.divide(lowerIntervalBound);

    return upperBound;
}

From source file:co.rsk.blockchain.utils.BlockGenerator.java

public static Block createBlock(int number, int ntxs) {
    Bloom logBloom = new Bloom();
    Block parent = BlockGenerator.getGenesisBlock();

    List<Transaction> txs = new ArrayList<>();

    for (int ntx = 0; ntx < ntxs; ntx++)
        txs.add(new SimpleRskTransaction(null));

    byte[] parentMGP = (parent.getMinimumGasPrice() != null) ? parent.getMinimumGasPrice()
            : BigInteger.valueOf(10L).toByteArray();
    BigInteger minimumGasPrice = new MinimumGasPriceCalculator().calculate(new BigInteger(1, parentMGP),
            BigInteger.valueOf(100L));

    return new Block(parent.getHash(), // parent hash
            EMPTY_LIST_HASH, // uncle hash
            parent.getCoinbase(), // coinbase
            logBloom.getData(), // logs bloom
            parent.getDifficulty(), // difficulty
            number, parent.getGasLimit(), parent.getGasUsed(), parent.getTimestamp() + ++count,
            EMPTY_BYTE_ARRAY, // extraData
            EMPTY_BYTE_ARRAY, // mixHash
            BigInteger.ZERO.toByteArray(), // provisory nonce
            EMPTY_TRIE_HASH, // receipts root
            EMPTY_TRIE_HASH, // transaction receipts
            EMPTY_TRIE_HASH, // state root
            txs, // transaction list
            null, // uncle list
            minimumGasPrice.toByteArray());
}

From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java

private static String intToHostAddress(int addressAsInt) {
    String hostAddress = "";
    byte[] ipAddress = BigInteger.valueOf(Integer.reverseBytes(addressAsInt)).toByteArray();
    try {//from  w  w  w. ja  v  a 2  s. c  om
        InetAddress inetAddress = InetAddress.getByAddress(ipAddress);
        hostAddress = InetAddressToString(inetAddress);
    } catch (UnknownHostException e) {
    }
    return hostAddress;
}

From source file:burstcoin.jminer.core.round.Round.java

private static int calcScoopNumber(long blockNumber, byte[] generationSignature) {
    if (blockNumber > 0 && generationSignature != null) {
        ByteBuffer buf = ByteBuffer.allocate(32 + 8);
        buf.put(generationSignature);//from   w ww . j a v  a 2s  .c o m
        buf.putLong(blockNumber);

        // generate new scoop number
        Shabal256 md = new Shabal256();
        md.update(buf.array());

        BigInteger hashnum = new BigInteger(1, md.digest());
        return hashnum.mod(BigInteger.valueOf(MiningPlot.SCOOPS_PER_PLOT)).intValue();
    }
    return 0;
}

From source file:com.aqnote.shared.cryptology.cert.gen.CertGenerator.java

private X509Certificate createEndCert(X500Name subject, PublicKey pubKey, KeyPair pKeyPair, X500Name issuer)
        throws Exception {

    PublicKey pPubKey = pKeyPair.getPublic();
    PrivateKey pPrivKey = pKeyPair.getPrivate();

    BigInteger sno = BigInteger.valueOf(System.currentTimeMillis());
    Date nb = new Date(System.currentTimeMillis() - HALF_DAY);
    Date na = new Date(nb.getTime() + FIVE_YEAR);

    X509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(issuer, sno, nb, na, subject,
            pubKey);//from ww w .jav  a  2 s. c om

    addSubjectKID(certBuilder, pubKey);
    addAuthorityKID(certBuilder, pPubKey);
    certBuilder.addExtension(Extension.extendedKeyUsage, false, new ExtendedKeyUsage(BASE_EKU));
    certBuilder.addExtension(Extension.keyUsage, false, new KeyUsage(END_KEY_USAGE));

    X509Certificate certificate = signCert(certBuilder, pPrivKey);
    certificate.checkValidity(new Date());
    certificate.verify(pPubKey);

    setPKCS9Info(certificate);

    return certificate;
}

From source file:com.jagornet.dhcp.client.ClientSimulatorV4.java

private byte[] buildChAddr(long id) {
    byte[] bid = BigInteger.valueOf(id).toByteArray();
    byte[] chAddr = new byte[6];
    chAddr[0] = (byte) 0xde;
    chAddr[1] = (byte) 0xb1;
    if (bid.length == 4) {
        chAddr[2] = bid[0];//w w  w. j ava 2  s  . c o  m
        chAddr[3] = bid[1];
        chAddr[4] = bid[2];
        chAddr[5] = bid[3];
    } else if (bid.length == 3) {
        chAddr[2] = 0;
        chAddr[3] = bid[0];
        chAddr[4] = bid[1];
        chAddr[5] = bid[2];
    } else if (bid.length == 2) {
        chAddr[2] = 0;
        chAddr[3] = 0;
        chAddr[4] = bid[0];
        chAddr[5] = bid[1];
    } else if (bid.length == 1) {
        chAddr[2] = 0;
        chAddr[3] = 0;
        chAddr[4] = 0;
        chAddr[5] = bid[0];
    }
    return chAddr;
}

From source file:com.jagornet.dhcp.client.ClientSimulatorV6.java

private String buildDuid(long id) {
    byte[] bid = BigInteger.valueOf(id).toByteArray();
    byte[] chAddr = new byte[6];
    chAddr[0] = (byte) 0xde;
    chAddr[1] = (byte) 0xb1;
    if (bid.length == 4) {
        chAddr[2] = bid[0];/* w  ww .j a  va  2 s  .co m*/
        chAddr[3] = bid[1];
        chAddr[4] = bid[2];
        chAddr[5] = bid[3];
    } else if (bid.length == 3) {
        chAddr[2] = 0;
        chAddr[3] = bid[0];
        chAddr[4] = bid[1];
        chAddr[5] = bid[2];
    } else if (bid.length == 2) {
        chAddr[2] = 0;
        chAddr[3] = 0;
        chAddr[4] = bid[0];
        chAddr[5] = bid[1];
    } else if (bid.length == 1) {
        chAddr[2] = 0;
        chAddr[3] = 0;
        chAddr[4] = 0;
        chAddr[5] = bid[0];
    }
    return "clientid-" + Util.toHexString(chAddr);
}

From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java

private void stepThree(final int i) throws Exception {
    BigInteger n = this.pubKey.getModulus();
    BigInteger r;//from  w ww.  ja  v  a 2s .  co m
    BigInteger upperBound;
    BigInteger lowerBound;
    BigInteger max;
    BigInteger min;
    BigInteger[] tmp;
    ArrayList<Interval> ms = new ArrayList<>(15);

    for (Interval interval : this.m) {
        upperBound = step3ComputeUpperBound(this.si, n, interval.upper);
        lowerBound = step3ComputeLowerBound(this.si, n, interval.lower);

        r = lowerBound;
        // lowerBound <= r <= upperBound
        while (r.compareTo(upperBound) < 1) {
            // ceil((2*B+r*n)/si)
            max = (BigInteger.valueOf(2).multiply(this.bigB)).add(r.multiply(n));
            tmp = max.divideAndRemainder(this.si);
            if (BigInteger.ZERO.compareTo(tmp[1]) != 0) {
                max = tmp[0].add(BigInteger.ONE);
            } else {
                max = tmp[0];
            }

            // floor((3*B-1+r*n)/si
            min = BigInteger.valueOf(3).multiply(this.bigB);
            min = min.subtract(BigInteger.ONE);
            min = min.add(r.multiply(n));
            min = min.divide(this.si);

            // build new interval
            if (interval.lower.compareTo(max) > 0) {
                max = interval.lower;
            }
            if (interval.upper.compareTo(min) < 0) {
                min = interval.upper;
            }
            if (max.compareTo(min) <= 0) {
                ms.add(new Interval(max, min));
            }
            // one further....
            r = r.add(BigInteger.ONE);
        }
    }

    loggerInstance.log(getClass(), " # of intervals for M" + i + ": " + ms.size(), Logger.LogLevel.INFO);

    if (ms.size() == 0) {
        throw new Exception("Zero intervals left, validity oracle seems to be wrong!");
    }

    this.m = ms.toArray(new Interval[ms.size()]);
}