Java Formatter Usage toUUIDFormat(byte[] bytes)

Here you can find the source of toUUIDFormat(byte[] bytes)

Description

to UUID Format

License

Apache License

Declaration

public static String toUUIDFormat(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Formatter;

public class Main {
    public static String toUUIDFormat(byte[] bytes) {
        byte[] switched = new byte[] { bytes[3], bytes[2], bytes[1], bytes[0], bytes[5], bytes[4], bytes[7],
                bytes[6], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15] };

        StringBuilder sb = new StringBuilder(bytes.length * 2);
        Formatter formatter = new Formatter(sb);
        for (byte b : switched) {
            formatter.format("%02x", b);
        }//w ww  . j  av  a2 s .  c om
        sb.insert(8, "-");
        sb.insert(13, "-");
        sb.insert(18, "-");
        sb.insert(23, "-");

        String temp = sb.toString().toUpperCase();
        formatter.close();
        return temp;
    }
}

Related

  1. showVxlanHeaderOutput()
  2. substitution(Formatter formatter, int flags, int width, int precision, StringBuilder obj)
  3. toHexString(final byte[] data)
  4. toReadableSize(long bytes)
  5. toTwoDigit(double f)
  6. validateCondition(boolean condition, String messageFormat, Object... messageArgs)
  7. warnfErr(String format, String... params)