Example usage for java.math BigInteger toString

List of usage examples for java.math BigInteger toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the decimal String representation of this BigInteger.

Usage

From source file:com.netflix.imfutility.cpl._2013.Cpl2013ContextBuilderStrategy.java

private void processResourceRepeat(TrackFileResourceType trackFileResource, long repeat) {
    // 1. init resource context
    ResourceUUID resourceId = ResourceUUID.create(trackFileResource.getId(), repeat);
    ResourceKey resourceKey = ResourceKey.create(currentSegmentUuid, currentSequenceUuid, currentSequenceType);
    contextProvider.getResourceContext().initResource(resourceKey, resourceId);

    // 2. Init essence parameter in Edit Units (as defined in CPL)
    // Check that we have a corresponding track file in assetmap
    // asset map already contains full absolute paths
    UUID trackId = UUID.create(trackFileResource.getTrackFileId());
    String assetPath = assetMap.getAsset(trackId);
    if (assetPath == null) {
        throw new ConversionException(
                String.format("Resource track file '%s' isn't present in assetmap.xml", trackId));
    }/*from  w w  w. jav  a2  s. com*/
    assetMap.markAssetReferenced(trackId);
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.ESSENCE, assetPath);

    // 3. init edit rate parameter
    BigFraction editRate = ((trackFileResource.getEditRate() != null)
            && !trackFileResource.getEditRate().isEmpty())
                    ? ConversionHelper.parseEditRate(trackFileResource.getEditRate())
                    : compositionEditRate;
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.EDIT_RATE, ConversionHelper.toEditRate(editRate));

    // 4. Init startTime parameter
    BigInteger startTimeEditUnit = trackFileResource.getEntryPoint() != null ? trackFileResource.getEntryPoint()
            : BigInteger.valueOf(0);
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.START_TIME_EDIT_UNIT, startTimeEditUnit.toString());

    // 5. init duration parameter
    BigInteger durationEditUnit;
    if (trackFileResource.getSourceDuration() != null) {
        durationEditUnit = trackFileResource.getSourceDuration();
    } else {
        durationEditUnit = trackFileResource.getIntrinsicDuration().subtract(startTimeEditUnit);
    }
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.DURATION_EDIT_UNIT, durationEditUnit.toString());

    // 6. init endTime parameter
    BigInteger endTimeEditUnit = startTimeEditUnit.add(durationEditUnit);
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.END_TIME_EDIT_UNIT, endTimeEditUnit.toString());

    // 7. init total repeat count parameter
    BigInteger repeatCount = trackFileResource.getRepeatCount() != null ? trackFileResource.getRepeatCount()
            : BigInteger.ONE;
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.REPEAT_COUNT, repeatCount.toString());

    // 8. init trackFile ID
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.TRACK_FILE_ID, trackId.getUuid());

    // 9. init essence descriptor ID
    String essenceDescId = trackFileResource.getSourceEncoding();
    contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId,
            ResourceContextParameters.ESSENCE_DESC_ID, essenceDescId);
}

From source file:com.openvcx.webcall.ConferenceCreateServlet.java

private synchronized String createConferenceNumber() {
    int index = 0;
    String strResult = "";

    while (index < CONFERENCE_NUMBER_LENGTH) {
        BigInteger bi = new BigInteger(4 * 8, m_rand);
        String str = bi.toString();
        int end = Math.min(CONFERENCE_NUMBER_LENGTH - index, str.length());
        str = str.substring(0, end);/*w ww . j  a v a 2s  . c  o  m*/
        strResult += str;
        index += str.length();
    }

    return strResult;
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

public static String convertToString(BigInteger o) {
    return o.toString();
}

From source file:co.rsk.validators.BlockTxsValidationRule.java

@Override
public boolean isValid(Block block, Block parent) {
    if (block == null || parent == null) {
        return false;
    }/*from w ww . j  a v  a 2  s . c om*/

    List<Transaction> txs = block.getTransactionsList();
    if (CollectionUtils.isEmpty(txs))
        return true;

    Repository parentRepo = repository.getSnapshotTo(parent.getStateRoot());

    Map<ByteArrayWrapper, BigInteger> curNonce = new HashMap<>();

    for (Transaction tx : txs) {
        byte[] txSender = tx.getSender();
        ByteArrayWrapper key = new ByteArrayWrapper(txSender);
        BigInteger expectedNonce = curNonce.get(key);
        if (expectedNonce == null) {
            expectedNonce = parentRepo.getNonce(txSender);
        }
        curNonce.put(key, expectedNonce.add(ONE));
        BigInteger txNonce = new BigInteger(1, tx.getNonce());

        if (!expectedNonce.equals(txNonce)) {
            logger.error("Invalid transaction: Tx nonce {} != expected nonce {} (parent nonce: {}): {}",
                    txNonce, expectedNonce, parentRepo.getNonce(txSender), tx);

            panicProcessor.panic("invalidtransaction",
                    String.format(
                            "Invalid transaction: Tx nonce %s != expected nonce %s (parent nonce: %s): %s",
                            txNonce.toString(), expectedNonce.toString(),
                            parentRepo.getNonce(txSender).toString(), Hex.toHexString(tx.getHash())));

            return false;
        }
    }

    return true;
}

From source file:org.opendaylight.genius.itm.impl.ItmUtils.java

public static String getLogicalTunnelGroupName(BigInteger srcDpnId, BigInteger destDpnId) {
    String tunnelTypeStr = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
    String groupName = String.format("%s:%s:%s", srcDpnId.toString(), destDpnId.toString(), tunnelTypeStr);
    LOG.trace("logical tunnel group name is {}", groupName);
    groupName = String.format("%s%s", TUNNEL, getUniqueIdString(groupName));
    return groupName;
}

From source file:com.netscape.cms.publish.publishers.FileBasedPublisher.java

/**
 * Unpublishes a object to the ldap directory.
 *
 * @param conn the Ldap connection/*from  w ww . j  a v a  2s .  c om*/
 *            (null if LDAP publishing is not enabled)
 * @param dn dn of the ldap entry to unpublish cert
 *            (null if LDAP publishing is not enabled)
 * @param object object to unpublish
 *            (java.security.cert.X509Certificate)
 */
public void unpublish(LDAPConnection conn, String dn, Object object) throws ELdapException {
    CMS.debug("FileBasedPublisher: unpublish");
    String name = mDir + File.separator;
    String fileName;

    if (object instanceof X509Certificate) {
        X509Certificate cert = (X509Certificate) object;
        BigInteger sno = cert.getSerialNumber();
        name += "cert-" + sno.toString();
    } else if (object instanceof X509CRL) {
        X509CRL crl = (X509CRL) object;
        String[] namePrefix = getCrlNamePrefix(crl, mTimeStamp.equals("GMT"));
        name += namePrefix[0];

        fileName = name + ".zip";
        File f = new File(fileName);
        f.delete();
    }
    fileName = name + ".der";
    File f = new File(fileName);
    f.delete();

    fileName = name + ".b64";
    f = new File(fileName);
    f.delete();
}

From source file:org.apache.pig.builtin.Utf8StorageConverter.java

@Override
public byte[] toBytes(BigInteger bi) throws IOException {
    return bi.toString().getBytes();
}

From source file:com.amazonaws.services.kinesis.clientlibrary.proxies.KinesisLocalFileProxy.java

/**
 * {@inheritDoc}//from  www.  j a  v a 2  s  .c  om
 */
@Override
public PutRecordResult put(String exclusiveMinimumSequenceNumber, String explicitHashKey, String partitionKey,
        ByteBuffer data) throws ResourceNotFoundException, InvalidArgumentException {
    PutRecordResult output = new PutRecordResult();

    BigInteger startingPosition = BigInteger.ONE;

    if (exclusiveMinimumSequenceNumber != null) {
        startingPosition = new BigInteger(exclusiveMinimumSequenceNumber).add(BigInteger.ONE);
    }

    output.setSequenceNumber(startingPosition.toString());
    return output;
}

From source file:com.kinesis.datavis.utils.StreamUtils.java

/**
 * Split a shard by dividing the hash key space in half.
 *
 * @param streamName Name of the stream that contains the shard to split.
 * @param shardId The id of the shard to split.
 *
 * @throws IllegalArgumentException When either streamName or shardId are null or empty.
 * @throws LimitExceededException Shard limit for the account has been reached.
 * @throws ResourceNotFoundException The stream or shard cannot be found.
 * @throws InvalidArgumentException If the shard is closed and no eligible for splitting.
 * @throws AmazonClientException Error communicating with Amazon Kinesis.
 *
 *///from   w  ww  .  j  ava 2 s .co m
public void splitShardEvenly(String streamName, String shardId) throws LimitExceededException,
        ResourceNotFoundException, AmazonClientException, InvalidArgumentException, IllegalArgumentException {
    if (streamName == null || streamName.isEmpty()) {
        throw new IllegalArgumentException("stream name is required");
    }
    if (shardId == null || shardId.isEmpty()) {
        throw new IllegalArgumentException("shard id is required");
    }

    DescribeStreamResult result = kinesis.describeStream(streamName);
    StreamDescription description = result.getStreamDescription();

    // Find the shard we want to split
    Shard shardToSplit = null;
    for (Shard shard : description.getShards()) {
        if (shardId.equals(shard.getShardId())) {
            shardToSplit = shard;
            break;
        }
    }

    if (shardToSplit == null) {
        throw new ResourceNotFoundException(
                "Could not find shard with id '" + shardId + "' in stream '" + streamName + "'");
    }

    // Check if the shard is still open. Open shards do not have an ending sequence number.
    if (shardToSplit.getSequenceNumberRange().getEndingSequenceNumber() != null) {
        throw new InvalidArgumentException("Shard is CLOSED and is not eligible for splitting");
    }

    // Calculate the median hash key to use as the new starting hash key for the shard.
    BigInteger startingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getStartingHashKey());
    BigInteger endingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getEndingHashKey());
    BigInteger[] medianHashKey = startingHashKey.add(endingHashKey).divideAndRemainder(new BigInteger("2"));
    BigInteger newStartingHashKey = medianHashKey[0];

    if (!BigInteger.ZERO.equals(medianHashKey[1])) {
        // In order to more evenly distributed the new hash key ranges across the new shards we will "round up" to
        // the next integer when our current hash key range is not evenly divisible by 2.
        newStartingHashKey = newStartingHashKey.add(BigInteger.ONE);
    }

    // Submit the split shard request
    kinesis.splitShard(streamName, shardId, newStartingHashKey.toString());
}

From source file:com.alertlogic.aws.analytics.poc.StreamUtils.java

/**
 * Split a shard by dividing the hash key space in half.
 *
 * @param streamName Name of the stream that contains the shard to split.
 * @param shardId The id of the shard to split.
 *
 * @throws IllegalArgumentException When either streamName or shardId are null or empty.
 * @throws LimitExceededException Shard limit for the account has been reached.
 * @throws ResourceNotFoundException The stream or shard cannot be found.
 * @throws InvalidArgumentException If the shard is closed and no eligible for splitting.
 * @throws AmazonClientException Error communicating with Amazon Kinesis.
 *
 *//*from  w w w.  j  a  va2  s. c o m*/
public void splitShardEvenly(String streamName, String shardId) throws LimitExceededException,
        ResourceNotFoundException, AmazonClientException, InvalidArgumentException, IllegalArgumentException {
    if (streamName == null || streamName.isEmpty()) {
        throw new IllegalArgumentException("stream name is required");
    }
    if (shardId == null || shardId.isEmpty()) {
        throw new IllegalArgumentException("shard id is required");
    }

    DescribeStreamResult result = kinesis.describeStream(streamName);
    StreamDescription description = result.getStreamDescription();

    // Find the shard we want to split
    Shard shardToSplit = null;
    for (Shard shard : description.getShards()) {
        if (shardId.equals(shard.getShardId())) {
            shardToSplit = shard;
            break;
        }
    }

    if (shardToSplit == null) {
        throw new ResourceNotFoundException(
                "Could not find shard with id '" + shardId + "' in stream '" + streamName + "'");
    }

    // Check if the shard is still open. Open shards do not have an ending sequence number.
    if (shardToSplit.getSequenceNumberRange().getEndingSequenceNumber() != null) {
        throw new InvalidArgumentException("Shard is CLOSED and is not eligible for splitting");
    }

    // Calculate the median hash key to use as the new starting hash key for the shard.
    BigInteger startingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getStartingHashKey());
    BigInteger endingHashKey = new BigInteger(shardToSplit.getHashKeyRange().getEndingHashKey());
    BigInteger[] medianHashKey = startingHashKey.add(endingHashKey).divideAndRemainder(new BigInteger("2"));
    BigInteger newStartingHashKey = medianHashKey[0];
    if (!BigInteger.ZERO.equals(medianHashKey[1])) {
        // In order to more evenly distributed the new hash key ranges across the new shards we will "round up" to
        // the next integer when our current hash key range is not evenly divisible by 2.
        newStartingHashKey = newStartingHashKey.add(BigInteger.ONE);
    }

    // Submit the split shard request
    kinesis.splitShard(streamName, shardId, newStartingHashKey.toString());
}