Java Convert via ByteBuffer toBytesAsString(UUID uuid)

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

Description

to Bytes As String

License

Open Source License

Declaration

public static String toBytesAsString(UUID uuid) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;
import java.util.UUID;

public class Main {
    public static String toBytesAsString(UUID uuid) {
        return bytesToString(toByteArray(uuid));
    }//from  www .  jav a  2 s.c om

    public static String bytesToString(byte[] array) {
        if (array == null)
            return null;
        return new String(ByteBuffer.wrap(array).asCharBuffer().array());
    }

    public static byte[] toByteArray(UUID uuid) {
        return uuid == null ? null
                : ByteBuffer.wrap(new byte[16]).putLong(uuid.getMostSignificantBits())
                        .putLong(uuid.getLeastSignificantBits()).array();
    }
}

Related

  1. toBytes(Number value)
  2. toBytes(Object obj)
  3. toBytes(String str, boolean wideChar)
  4. toBytes(String value)
  5. toBytes(UUID id)
  6. toChars(byte[] bytes)
  7. toChars(byte[] bytes)
  8. toChars(byte[] bytes)
  9. toDirectBuffer(String s)