// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.channel.socket.nio;

import java.nio.file.Path;
import java.lang.reflect.InvocationTargetException;
import java.net.SocketAddress;
import java.lang.reflect.Method;

final class NioDomainSocketUtil
{
    private static final Method OF_METHOD;
    private static final Method GET_PATH_METHOD;
    
    static SocketAddress newUnixDomainSocketAddress(final String path) {
        if (NioDomainSocketUtil.OF_METHOD == null) {
            throw new IllegalStateException();
        }
        try {
            return (SocketAddress)NioDomainSocketUtil.OF_METHOD.invoke(null, path);
        }
        catch (final IllegalAccessException | InvocationTargetException e) {
            throw new IllegalStateException(e);
        }
    }
    
    static void deleteSocketFile(final SocketAddress address) {
        if (NioDomainSocketUtil.GET_PATH_METHOD == null) {
            throw new IllegalStateException();
        }
        try {
            final Path path = (Path)NioDomainSocketUtil.GET_PATH_METHOD.invoke(address, new Object[0]);
            if (path != null) {
                path.toFile().delete();
            }
        }
        catch (final IllegalAccessException | InvocationTargetException e) {
            throw new IllegalStateException(e);
        }
    }
    
    private NioDomainSocketUtil() {
    }
    
    static {
        Method ofMethod;
        Method getPathMethod;
        try {
            final Class<?> clazz = Class.forName("java.net.UnixDomainSocketAddress");
            ofMethod = clazz.getMethod("of", String.class);
            getPathMethod = clazz.getMethod("getPath", (Class<?>[])new Class[0]);
        }
        catch (final Throwable error) {
            ofMethod = null;
            getPathMethod = null;
        }
        OF_METHOD = ofMethod;
        GET_PATH_METHOD = getPathMethod;
    }
}
