GUIDGenerator.java 2.48 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.aemfd.watchfolder.job;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Random;

public class GUIDGenerator {
    public static final int GUID_LENGTH = 26;
    private static final byte[] GUID_OBFUSCATION_MASK = new byte[]{-28, 124, -14, 61, 11, -87, 88, 37, -63, -101, -113, 48};
    private static final char[] GUID_DIGITS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    private static int s_guidCount = new Random(System.currentTimeMillis()).nextInt();
    private static int s_guidAddress;

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public static String generate(char prefix) {
        StringBuffer buffer = new StringBuffer();
        byte[] guid = new byte[12];
        Class<GUIDGenerator> class_ = GUIDGenerator.class;
        synchronized (GUIDGenerator.class) {
            if (s_guidAddress == 0) {
                try {
                    s_guidAddress = InetAddress.getLocalHost().hashCode();
                }
                catch (UnknownHostException exception) {
                    s_guidAddress = Thread.currentThread().hashCode();
                }
            }
            // ** MonitorExit[var5_3] (shouldn't be in output)
            long time = System.currentTimeMillis();
            guid[0] = (byte)((++s_guidCount & 65280) >> 8);
            guid[1] = (byte)((s_guidAddress & -16777216) >> 24);
            guid[2] = (byte)((time & 0xFF0000) >> 16);
            guid[3] = (byte)(s_guidCount & 255);
            guid[4] = (byte)((time & -16777216) >> 24);
            guid[5] = (byte)((s_guidAddress & 65280) >> 8);
            guid[6] = (byte)((s_guidCount & -16777216) >> 24);
            guid[7] = (byte)(time & 255);
            guid[8] = (byte)(s_guidAddress & 255);
            guid[9] = (byte)((s_guidCount & 16711680) >> 16);
            guid[10] = (byte)((s_guidAddress & 16711680) >> 16);
            guid[11] = (byte)((time & 65280) >> 8);
            buffer.append(prefix);
            buffer.append('x');
            for (int index = 0; index < 12; ++index) {
                byte[] arrby = guid;
                int n = index;
                arrby[n] = (byte)(arrby[n] ^ GUID_OBFUSCATION_MASK[index]);
                buffer.append(GUID_DIGITS[guid[index] & 15]);
                buffer.append(GUID_DIGITS[(guid[index] & 240) >> 4]);
            }
            return buffer.toString();
        }
    }
}