List of usage examples for java.math BigInteger valueOf
private static BigInteger valueOf(int val[])
From source file:javadz.beanutils.converters.NumberConverter.java
/** * Convert any Number object to the specified type for this * <i>Converter</i>.//w ww . ja va2s. c om * <p> * This method handles conversion to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The Number to convert. * * @return The converted value. */ private Number toNumber(Class sourceType, Class targetType, Number value) { // Correct Number type already if (targetType.equals(value.getClass())) { return value; } // Byte if (targetType.equals(Byte.class)) { long longValue = value.longValue(); if (longValue > Byte.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Byte.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Byte(value.byteValue()); } // Short if (targetType.equals(Short.class)) { long longValue = value.longValue(); if (longValue > Short.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Short.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Short(value.shortValue()); } // Integer if (targetType.equals(Integer.class)) { long longValue = value.longValue(); if (longValue > Integer.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Integer.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Integer(value.intValue()); } // Long if (targetType.equals(Long.class)) { return new Long(value.longValue()); } // Float if (targetType.equals(Float.class)) { if (value.doubleValue() > Float.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } return new Float(value.floatValue()); } // Double if (targetType.equals(Double.class)) { return new Double(value.doubleValue()); } // BigDecimal if (targetType.equals(BigDecimal.class)) { if (value instanceof Float || value instanceof Double) { return new BigDecimal(value.toString()); } else if (value instanceof BigInteger) { return new BigDecimal((BigInteger) value); } else { return BigDecimal.valueOf(value.longValue()); } } // BigInteger if (targetType.equals(BigInteger.class)) { if (value instanceof BigDecimal) { return ((BigDecimal) value).toBigInteger(); } else { return BigInteger.valueOf(value.longValue()); } } String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'"; if (log().isWarnEnabled()) { log().warn(" " + msg); } throw new ConversionException(msg); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.excelimport.EntityDataImporter.java
private Object readPropertyValue(Cell nonEmptyCell, PropertyExpression<?> nonReleasenameProperty) { if (nonReleasenameProperty instanceof EnumerationPropertyExpression) { return getEnumPropertyValue(nonEmptyCell, nonReleasenameProperty); } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.INTEGER)) { Double doubleValue = getCellValueOfType(nonEmptyCell, Double.class); return doubleValue == null ? null : BigInteger.valueOf(doubleValue.longValue()); } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.DECIMAL)) { Double doubleValue = getCellValueOfType(nonEmptyCell, Double.class); return doubleValue == null ? null : BigDecimal.valueOf(doubleValue.doubleValue()); } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.DATE)) { return getCellValueOfType(nonEmptyCell, Date.class); } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.BOOLEAN)) { String stringValue = getCellValueOfType(nonEmptyCell, String.class); return Boolean.valueOf(Boolean.parseBoolean(stringValue)); } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.STRING)) { return getStringPropertyValue(nonEmptyCell, nonReleasenameProperty); } else {/*from ww w. j av a 2 s. c om*/ LOGGER.info("Property type for Java enum: {0}", nonReleasenameProperty.getClass().getName()); return resolveJavaEnum(nonReleasenameProperty.getType().getName(), ExcelUtils.getCellValue(nonEmptyCell, false)); } }
From source file:gov.nih.nci.firebird.service.signing.DigitalSigningHelper.java
private X509V3CertificateGenerator buildX509V3CertificateGenerator(PublicKey publicKey, X509Certificate caCert, DigitalSigningDistinguishedName distinguishedName, long serialNumber, int validDays) throws CertificateEncodingException, CertificateParsingException { X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator(); // Calculate Expiration Date Calendar notBeforeCal = Calendar.getInstance(); Date notBeforeDate = notBeforeCal.getTime(); Calendar notAfterCal = Calendar.getInstance(); notAfterCal.add(Calendar.DAY_OF_YEAR, validDays); Date notAfterDate = notAfterCal.getTime(); ///*from w w w . j a v a 2 s . c o m*/ // create the certificate - version 3 // v3CertGen.reset(); v3CertGen.setSerialNumber(BigInteger.valueOf(serialNumber)); v3CertGen.setIssuerDN(PrincipalUtil.getSubjectX509Principal(caCert)); v3CertGen.setNotBefore(notBeforeDate); v3CertGen.setNotAfter(notAfterDate); v3CertGen.setSubjectDN(new X509Principal(getAttributeOrder(), buildAttributes(distinguishedName))); v3CertGen.setPublicKey(publicKey); v3CertGen.setSignatureAlgorithm("SHA256WithRSAEncryption"); // // extensions // v3CertGen.addExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(publicKey)); v3CertGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(caCert)); v3CertGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(0)); return v3CertGen; }
From source file:org.guanxi.sp.engine.form.RegisterGuardFormController.java
/** * Handles the nitty gritty of signing a CSR * * @param rootCert The certificate of the root authority who will vouch for the entity * @param rootPrivKey The private key of the root authority who will vouch for the entity * @param csr The entitie's CSR//from w w w. jav a2 s .co m * @param keyType The type of the key, e.g. "RSA", "DSA" * @return A certificate chain as an array of X509Certificate instances or null if an * error occurred */ private X509Certificate[] createSignedCert(X509Certificate rootCert, PrivateKey rootPrivKey, PKCS10CertificationRequest csr, String keyType) { X509V3CertificateGenerator certGen = new X509V3CertificateGenerator(); try { Date validFrom = new Date(); validFrom.setTime(validFrom.getTime() - (10 * 60 * 1000)); Date validTo = new Date(); validTo.setTime(validTo.getTime() + (20 * (24 * 60 * 60 * 1000))); certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis())); certGen.setIssuerDN(rootCert.getSubjectX500Principal()); certGen.setNotBefore(validFrom); certGen.setNotAfter(validTo); certGen.setSubjectDN(csr.getCertificationRequestInfo().getSubject()); certGen.setPublicKey(csr.getPublicKey("BC")); if (keyType.toLowerCase().equals("rsa")) certGen.setSignatureAlgorithm("SHA256WithRSAEncryption"); if (keyType.toLowerCase().equals("dsa")) certGen.setSignatureAlgorithm("DSAWithSHA1"); certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(rootCert)); certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(csr.getPublicKey("BC"))); certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(false)); certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment)); certGen.addExtension(X509Extensions.ExtendedKeyUsage, true, new ExtendedKeyUsage(KeyPurposeId.id_kp_clientAuth)); X509Certificate issuedCert = certGen.generate(rootPrivKey, "BC"); return new X509Certificate[] { issuedCert, rootCert }; } catch (Exception e) { logger.error(e); return null; } }
From source file:piuk.MyRemoteWallet.java
public void parseMultiAddr(String response) throws Exception { transactions.clear();/* w w w .j av a2s .c om*/ Map<String, Object> top = (Map<String, Object>) JSONValue.parse(response); Map<String, Object> info_obj = (Map<String, Object>) top.get("info"); Map<String, Object> block_obj = (Map<String, Object>) info_obj.get("latest_block"); if (block_obj != null) { Sha256Hash hash = new Sha256Hash(Hex.decode((String) block_obj.get("hash"))); int blockIndex = ((Number) block_obj.get("block_index")).intValue(); int blockHeight = ((Number) block_obj.get("height")).intValue(); long time = ((Number) block_obj.get("time")).longValue(); MyBlock block = new MyBlock(); block.height = blockHeight; block.hash = hash; block.blockIndex = blockIndex; block.time = time; this.latestBlock = block; } List<JSONObject> multiAddrBalances = (List<JSONObject>) top.get("addresses"); Map<String, JSONObject> multiAddrBalancesRoot = new HashMap<String, JSONObject>(); for (JSONObject obj : multiAddrBalances) { multiAddrBalancesRoot.put((String) obj.get("address"), obj); } this.multiAddrBalancesRoot = multiAddrBalancesRoot; Map<String, Object> symbol_local = (Map<String, Object>) info_obj.get("symbol_local"); if (symbol_local != null && symbol_local.containsKey("code")) { String currencyCode = (String) symbol_local.get("code"); Double currencyConversion = (Double) symbol_local.get("conversion"); if (currencyConversion == null) currencyConversion = 0d; if (this.currencyCode == null || !this.currencyCode.equals(currencyCode) || this.currencyConversion != currencyConversion) { this.currencyCode = currencyCode; this.currencyConversion = currencyConversion; } } if (top.containsKey("mixer_fee")) { sharedFee = ((Number) top.get("mixer_fee")).doubleValue(); } Map<String, Object> wallet_obj = (Map<String, Object>) top.get("wallet"); this.final_balance = BigInteger.valueOf(((Number) wallet_obj.get("final_balance")).longValue()); this.total_sent = BigInteger.valueOf(((Number) wallet_obj.get("total_sent")).longValue()); this.total_received = BigInteger.valueOf(((Number) wallet_obj.get("total_received")).longValue()); List<Map<String, Object>> transactions = (List<Map<String, Object>>) top.get("txs"); MyTransaction newestTransaction = null; if (transactions != null) { for (Map<String, Object> transactionDict : transactions) { MyTransaction tx = MyTransaction.fromJSONDict(transactionDict); if (tx == null) continue; if (newestTransaction == null) newestTransaction = tx; addTransaction(tx); } } }
From source file:com.kactech.otj.Utils.java
public static BigInteger base62Decode(final String string) { if (string.length() == 0) { throw new IllegalArgumentException("string must not be empty"); }//from www . j av a 2 s . co m BigInteger result = BigInteger.ZERO; int digits = string.length(); for (int index = 0; index < digits; index++) { int digit = B62_DIGITS.indexOf(string.charAt(digits - index - 1)); result = result.add(BigInteger.valueOf(digit).multiply(B62_BASE.pow(index))); } return result; }
From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java
private BigInteger step2cComputeLowerBound(final BigInteger r, final BigInteger modulus, final BigInteger upperIntervalBound) { BigInteger lowerBound = BigInteger.valueOf(2).multiply(this.bigB); lowerBound = lowerBound.add(r.multiply(modulus)); lowerBound = lowerBound.divide(upperIntervalBound); return lowerBound; }
From source file:com.aqnote.shared.cryptology.cert.gen.CertGenerator.java
private X509Certificate createMiddleCaCert(X500Name subject, PublicKey pubKey, KeyPair pKeyPair, X500Name issuer) throws Exception { BigInteger sno = BigInteger.valueOf(3); Date nb = new Date(System.currentTimeMillis() - HALF_DAY); Date na = new Date(nb.getTime() + TWENTY_YEAR); X509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(issuer, sno, nb, na, subject, pubKey);/*from www . j a v a 2 s. com*/ addSubjectKID(certBuilder, pubKey); addAuthorityKID(certBuilder, pKeyPair.getPublic()); certBuilder.addExtension(Extension.basicConstraints, true, new BasicConstraints(3)); certBuilder.addExtension(Extension.extendedKeyUsage, false, new ExtendedKeyUsage(BASE_EKU)); X509Certificate certificate = signCert(certBuilder, pKeyPair.getPrivate()); certificate.checkValidity(new Date()); certificate.verify(pKeyPair.getPublic()); setPKCS9Info(certificate); return certificate; }
From source file:net.pms.util.Rational.java
/** * Returns an instance that represents the value of {@code value}. * * @param value the value.// ww w. j av a 2 s . c om * @return An instance that represents the value of {@code value}. */ @Nonnull public static Rational valueOf(long value) { BigInteger numerator = BigInteger.valueOf(value); return new Rational(numerator, BigInteger.ONE, BigInteger.ONE, numerator, BigInteger.ONE); }
From source file:burstcoin.observer.service.ATService.java
public static String toUnsignedLong(long objectId) { if (objectId >= 0) { return String.valueOf(objectId); }//w ww . ja v a2 s . co m BigInteger id = BigInteger.valueOf(objectId).add(two64); return id.toString(); }