Java BigInteger Create toBigInteger(UUID uuid)

Here you can find the source of toBigInteger(UUID uuid)

Description

to Big Integer

License

Open Source License

Declaration

public static BigInteger toBigInteger(UUID uuid) 

Method Source Code

//package com.java2s;
/***********************************************
 This file is part of the Edge Home Theater project (https://github.com/parlock/Edge-Home-Theater).
    /*from w  ww  . j  a  va2 s  .  co m*/
Edge Home Theater is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
Edge Home Theater is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Edge Home Theater.  If not, see <http://www.gnu.org/licenses/>.
    
***********************************************/

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

import java.io.IOException;

import java.math.BigInteger;
import java.util.UUID;

public class Main {
    public static BigInteger toBigInteger(UUID uuid) {
        return new BigInteger(1, toByteArray(uuid));
    }

    public static byte[] toByteArray(UUID uuid) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        try {
            dos.writeLong(uuid.getMostSignificantBits());
            dos.writeLong(uuid.getLeastSignificantBits());

            return baos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e); //should never happen
        }
    }
}

Related

  1. toBigInteger(int[] x, int bitsPerDigit)
  2. toBigInteger(List integerVector)
  3. toBigInteger(long value)
  4. toBigInteger(Object o)
  5. toBigInteger(Object value)