List of usage examples for java.math BigInteger intValue
public int intValue()
From source file:uniol.apt.analysis.synthesize.SynthesizePN.java
private static int bigIntToInt(BigInteger value) { if (value.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0 || value.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0) throw new ArithmeticException("Cannot represent value as int: " + value); return value.intValue(); }
From source file:com.onesignal.GenerateNotification.java
private static NotificationCompat.Builder getBaseNotificationCompatBuilder(JSONObject gcmBundle, boolean notify) { int notificationIcon = getSmallIconId(gcmBundle); int notificationDefaults = 0; if (OneSignal.getVibrate(currentContext)) notificationDefaults = Notification.DEFAULT_VIBRATE; String message = null;/*from w w w. j a v a 2 s .c om*/ try { message = gcmBundle.getString("alert"); } catch (Throwable t) { } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(currentContext).setAutoCancel(true) .setSmallIcon(notificationIcon) // Small Icon required or notification doesn't display .setContentTitle(getTitle(gcmBundle)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message); if (notify) notifBuilder.setTicker(message); // Android 5.0 accent color to use, only works when AndroidManifest.xml is // targetSdkVersion >= 21 if (gcmBundle.has("bgac")) { try { notifBuilder.setColor(new BigInteger(gcmBundle.getString("bgac"), 16).intValue()); } catch (Throwable t) { } // Can throw if an old android support lib is used or parse error. } BigInteger ledColor = null; if (notify && gcmBundle.has("ledc")) { try { ledColor = new BigInteger(gcmBundle.getString("ledc"), 16); notifBuilder.setLights(ledColor.intValue(), 2000, 5000); } catch (Throwable t) { notificationDefaults |= Notification.DEFAULT_LIGHTS; } // Can throw if an old android support lib is used or parse error. } else notificationDefaults |= Notification.DEFAULT_LIGHTS; try { int visibility = Notification.VISIBILITY_PUBLIC; if (gcmBundle.has("vis")) visibility = Integer.parseInt(gcmBundle.getString("vis")); notifBuilder.setVisibility(visibility); } catch (Throwable t) { } // Can throw if an old android support lib is used or parse error Bitmap largeIcon = getLargeIcon(gcmBundle); if (largeIcon != null) notifBuilder.setLargeIcon(largeIcon); Bitmap bigPictureIcon = getBitmapIcon(gcmBundle, "bicon"); if (bigPictureIcon != null) notifBuilder.setStyle( new NotificationCompat.BigPictureStyle().bigPicture(bigPictureIcon).setSummaryText(message)); if (notify && OneSignal.getSoundEnabled(currentContext)) { Uri soundUri = getCustomSound(gcmBundle); if (soundUri != null) notifBuilder.setSound(soundUri); else notificationDefaults |= Notification.DEFAULT_SOUND; } if (!notify) notificationDefaults = 0; notifBuilder.setDefaults(notificationDefaults); return notifBuilder; }
From source file:org.cesecore.certificates.util.AlgorithmTools.java
/** * Gets the key specification from a public key. Example: "2048" for a RSA * or DSA key or "secp256r1" for EC key. The EC curve is only detected * if <i>publickey</i> is an object known by the bouncy castle provider. * @param publicKey The public key to get the key specification from * @return The key specification, "unknown" if it could not be determined and * null if the key algorithm is not supported *//* w w w .ja v a 2s . co m*/ public static String getKeySpecification(final PublicKey publicKey) { if (log.isTraceEnabled()) { log.trace(">getKeySpecification"); } String keyspec = null; if (publicKey instanceof RSAPublicKey) { keyspec = Integer.toString(((RSAPublicKey) publicKey).getModulus().bitLength()); } else if (publicKey instanceof DSAPublicKey) { keyspec = Integer.toString(((DSAPublicKey) publicKey).getParams().getP().bitLength()); } else if (publicKey instanceof ECPublicKey) { final ECPublicKey ecPublicKey = (ECPublicKey) publicKey; if (ecPublicKey.getParams() instanceof ECNamedCurveSpec) { keyspec = ((ECNamedCurveSpec) ecPublicKey.getParams()).getName(); // Prefer to return a curve name alias that also works with the default and BC provider for (String keySpecAlias : getEcKeySpecAliases(keyspec)) { if (isNamedECKnownInDefaultProvider(keySpecAlias)) { keyspec = keySpecAlias; break; } } } else { keyspec = KEYSPEC_UNKNOWN; // Try to detect if it is a curve name known by BC even though the public key isn't a BC key final ECParameterSpec namedCurve = ecPublicKey.getParams(); if (namedCurve != null) { final int c1 = namedCurve.getCofactor(); final EllipticCurve ec1 = namedCurve.getCurve(); final BigInteger a1 = ec1.getA(); final BigInteger b1 = ec1.getB(); final int fs1 = ec1.getField().getFieldSize(); //final byte[] s1 = ec1.getSeed(); final ECPoint g1 = namedCurve.getGenerator(); final BigInteger ax1 = g1.getAffineX(); final BigInteger ay1 = g1.getAffineY(); final BigInteger o1 = namedCurve.getOrder(); if (log.isDebugEnabled()) { log.debug("a1=" + a1 + " b1=" + b1 + " fs1=" + fs1 + " ax1=" + ax1 + " ay1=" + ay1 + " o1=" + o1 + " c1=" + c1); } @SuppressWarnings("unchecked") final Enumeration<String> ecNamedCurves = ECNamedCurveTable.getNames(); while (ecNamedCurves.hasMoreElements()) { final String ecNamedCurveBc = ecNamedCurves.nextElement(); final ECNamedCurveParameterSpec parameterSpec2 = ECNamedCurveTable .getParameterSpec(ecNamedCurveBc); final ECCurve ec2 = parameterSpec2.getCurve(); final BigInteger a2 = ec2.getA().toBigInteger(); final BigInteger b2 = ec2.getB().toBigInteger(); final int fs2 = ec2.getFieldSize(); final org.bouncycastle.math.ec.ECPoint g2 = parameterSpec2.getG(); final BigInteger ax2 = g2.getX().toBigInteger(); final BigInteger ay2 = g2.getY().toBigInteger(); final BigInteger h2 = parameterSpec2.getH(); final BigInteger n2 = parameterSpec2.getN(); if (a1.equals(a2) && ax1.equals(ax2) && b1.equals(b2) && ay1.equals(ay2) && fs1 == fs2 && o1.equals(n2) && c1 == h2.intValue()) { // We have a matching curve here! if (log.isDebugEnabled()) { log.debug("a2=" + a2 + " b2=" + b2 + " fs2=" + fs2 + " ax2=" + ax2 + " ay2=" + ay2 + " h2=" + h2 + " n2=" + n2 + " " + ecNamedCurveBc); } // Since this public key is a SUN PKCS#11 pub key if we get here, we only return an alias if it is recognized by the provider if (isNamedECKnownInDefaultProvider(ecNamedCurveBc)) { keyspec = ecNamedCurveBc; break; } } } } } } if (log.isTraceEnabled()) { log.trace("<getKeySpecification: " + keyspec); } return keyspec; }
From source file:Main.java
public static int[] generateCompactWindowNaf(int width, BigInteger k) { if (width == 2) { return generateCompactNaf(k); }//from www . j a v a 2s. c o m if (width < 2 || width > 16) { throw new IllegalArgumentException("'width' must be in the range [2, 16]"); } if ((k.bitLength() >>> 16) != 0) { throw new IllegalArgumentException("'k' must have bitlength < 2^16"); } if (k.signum() == 0) { return EMPTY_INTS; } int[] wnaf = new int[k.bitLength() / width + 1]; // 2^width and a mask and sign bit set accordingly int pow2 = 1 << width; int mask = pow2 - 1; int sign = pow2 >>> 1; boolean carry = false; int length = 0, pos = 0; while (pos <= k.bitLength()) { if (k.testBit(pos) == carry) { ++pos; continue; } k = k.shiftRight(pos); int digit = k.intValue() & mask; if (carry) { ++digit; } carry = (digit & sign) != 0; if (carry) { digit -= pow2; } int zeroes = length > 0 ? pos - 1 : pos; wnaf[length++] = (digit << 16) | zeroes; pos = width; } // Reduce the WNAF array to its actual length if (wnaf.length > length) { wnaf = trim(wnaf, length); } return wnaf; }
From source file:com.livinglogic.ul4.FunctionFormat.java
public static String call(BigInteger obj, String formatString, Locale locale) { IntegerFormat format = new IntegerFormat(formatString); if (locale == null) locale = Locale.ENGLISH;/* ww w. j ava 2 s .c om*/ String output = null; boolean neg = obj.signum() < 0; if (neg) obj = obj.negate(); switch (format.type) { case 'b': output = obj.toString(2); break; case 'c': if (neg || obj.compareTo(new BigInteger("65535")) > 0) throw new RuntimeException("value out of bounds for c format"); output = Character.toString((char) obj.intValue()); break; case 'd': output = obj.toString(); break; case 'o': output = obj.toString(8); break; case 'x': output = obj.toString(16); break; case 'X': output = obj.toString(16).toUpperCase(); break; case 'n': // FIXME: locale formatting output = obj.toString(); break; } return formatIntegerString(output, neg, format); }
From source file:org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.java
private static byte[] computeHash2B(byte[] input, byte[] password, byte[] userKey) throws IOException { try {/* w w w . j a va 2 s . co m*/ MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] k = md.digest(input); byte[] e = null; for (int round = 0; round < 64 || ((int) e[e.length - 1] & 0xFF) > round - 32; round++) { byte[] k1; if (userKey != null && userKey.length >= 48) { k1 = new byte[64 * (password.length + k.length + 48)]; } else { k1 = new byte[64 * (password.length + k.length)]; } int pos = 0; for (int i = 0; i < 64; i++) { System.arraycopy(password, 0, k1, pos, password.length); pos += password.length; System.arraycopy(k, 0, k1, pos, k.length); pos += k.length; if (userKey != null && userKey.length >= 48) { System.arraycopy(userKey, 0, k1, pos, 48); pos += 48; } } byte[] kFirst = new byte[16]; byte[] kSecond = new byte[16]; System.arraycopy(k, 0, kFirst, 0, 16); System.arraycopy(k, 16, kSecond, 0, 16); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); SecretKeySpec keySpec = new SecretKeySpec(kFirst, "AES"); IvParameterSpec ivSpec = new IvParameterSpec(kSecond); cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); e = cipher.doFinal(k1); byte[] eFirst = new byte[16]; System.arraycopy(e, 0, eFirst, 0, 16); BigInteger bi = new BigInteger(1, eFirst); BigInteger remainder = bi.mod(new BigInteger("3")); String nextHash = HASHES_2B[remainder.intValue()]; md = MessageDigest.getInstance(nextHash); k = md.digest(e); } if (k.length > 32) { byte[] kTrunc = new byte[32]; System.arraycopy(k, 0, kTrunc, 0, 32); return kTrunc; } else { return k; } } catch (GeneralSecurityException e) { logIfStrongEncryptionMissing(); throw new IOException(e); } }
From source file:models.db.acentera.impl.ProjectImpl.java
public static Long getUniqueCloudId() { Session s = (Session) HibernateSessionFactory.getSession(); Random rand = new Random(); long cloudId = 0; boolean notUnique = true; while (notUnique) { cloudId = rand.nextInt(10000000); Query query = s.createSQLQuery("select count(1) from project where cloudId = :cloudId limit 1") .setParameter("cloudId", cloudId); List result = query.list(); BigInteger l = (BigInteger) result.get(0); if (l.intValue() <= 0) { notUnique = false;//from w w w . j av a2s . co m } } return cloudId; }
From source file:org.oscarehr.common.dao.BillingONCHeader1Dao.java
public int getNumberOfDemographicsWithInvoicesForProvider(String providerNo, Date startDate, Date endDate, boolean distinct) { String distinctStr = "distinct"; if (distinct == false) { distinctStr = StringUtils.EMPTY; }//from w w w . j a v a 2 s .c o m Query query = entityManager.createNativeQuery("select count(" + distinctStr + " demographic_no) from billing_on_cheader1 ch where ch.provider_no = ? and billing_date >= ? and billing_date <= ?"); query.setParameter(1, providerNo); query.setParameter(2, startDate); query.setParameter(3, endDate); BigInteger bint = (BigInteger) query.getSingleResult(); return bint.intValue(); }
From source file:org.apache.taverna.scufl2.translator.t2flow.defaultdispatchstack.ParallelizeParser.java
@Override public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean, ParserState parserState) throws ReaderException { ParallelizeConfig parallelConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", ParallelizeConfig.class); Configuration c = new Configuration(); c.setType(scufl2Uri.resolve("#Config")); BigInteger maxJobs = parallelConfig.getMaxJobs(); if (maxJobs != null && maxJobs.intValue() > 0 && maxJobs.intValue() != Defaults.maxJobs) { ObjectNode json = (ObjectNode) c.getJson(); json.put("maxJobs", maxJobs.intValue()); }/* w w w. j av a 2s . c om*/ return c; }
From source file:cn.mljia.common.notify.port.adapter.persistence.HibernateNotifyRecordRepository.java
@Override public Integer notifyRecordOfByPageCount(Integer maxNotifyTimes) throws NegativeException { // TODO Auto-generated method stub StringBuilder sql = new StringBuilder(); sql.append(//from w w w. j ava2 s . co m "select count(1) from tb_common_notify_record where 1 = 1 and status != 'SUCCESS' and status != 'FAILED' and notify_times < :maxNotifyTimes "); Query query = this.session().createSQLQuery(sql.toString()).setParameter("maxNotifyTimes", maxNotifyTimes); BigInteger count = (BigInteger) query.uniqueResult(); return count != null ? count.intValue() : 0; }