// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/SOCKS5Exception.java
// public class SOCKS5Exception extends Exception {
// 
//     public SOCKS5Exception(final String msg) {
//         super(msg);
//     }
// 
// }
// 
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryWriter.java
// public class BinaryWriter {
// 
//     private final ByteBuffer byteBuffer;
// 
//     public BinaryWriter(final int capacity) {
//         byteBuffer = ByteBuffer.allocate(capacity);
//     }
// 
//     public BinaryWriter putSignedByte(final byte sb) {
//         byteBuffer.put(sb);
//         return this;
//     }
// 
//     public BinaryWriter putUnsignedByte(final short ub) {
//         byteBuffer.put((byte) (ub & 0xff));
//         return this;
//     }
// 
//     public BinaryWriter putSignedShort(final short ss) {
//         byteBuffer.putShort(ss);
//         return this;
//     }
// 
//     public BinaryWriter putUnsignedShort(final int us) {
//         byteBuffer.putShort((short) (us & 0xffff));
//         return this;
//     }
// 
//     public BinaryWriter putSignedInt(final int si) {
//         byteBuffer.putInt(si);
//         return this;
//     }
// 
//     public BinaryWriter putUnsignedInt(final long ui) {
//         byteBuffer.putInt((int) (ui & 0xffffffffL));
//         return this;
//     }
// 
//     public BinaryWriter putBytes(final byte[] bytes) {
//         byteBuffer.put(bytes);
//         return this;
//     }
// 
//     public BinaryWriter putBytesGroupWithByteLength(final byte[] bytes) {
//         putUnsignedByte((short) bytes.length);
//         putBytes(bytes);
//         return this;
//     }
// 
//     public BinaryWriter putBytesGroupWithShortLength(final byte[] bytes) {
//         putUnsignedShort(bytes.length);
//         putBytes(bytes);
//         return this;
//     }
// 
//     public BinaryWriter putBoolean(final boolean b) {
//         byteBuffer.put((byte) (b ? 1 : 0));
//         return this;
//     }
// 
//     public byte[] toBytes() {
//         return byteBuffer.array();
//     }
// 
// }


import com.vecsight.dragonite.proxy.exception.SOCKS5Exception;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
/*
 * The Dragonite Project
 * -------------------------
 * See the LICENSE file in the root directory for license information.
 */


package com.vecsight.dragonite.proxy.network.socks5;



public final class SOCKS5SocketHelper {

    private static final byte SOCKS5_VERSION = 0x05;

    private static final byte[] SOCKS5_SUCCEED = {SOCKS5_VERSION, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    private static final byte[] SOCKS5_NOT_ALLOWED = {SOCKS5_VERSION, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    private static final byte[] SOCKS5_FAILED_REFUSED = {SOCKS5_VERSION, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    private static final byte[] SOCKS5_NOT_SUPPORTED = {SOCKS5_VERSION, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/SOCKS5Exception.java
// public class SOCKS5Exception extends Exception {
// 
//     public SOCKS5Exception(final String msg) {
//         super(msg);
//     }
// 
// }
// 
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryWriter.java
// public class BinaryWriter {
// 
//     private final ByteBuffer byteBuffer;
// 
//     public BinaryWriter(final int capacity) {
//         byteBuffer = ByteBuffer.allocate(capacity);
//     }
// 
//     public BinaryWriter putSignedByte(final byte sb) {
//         byteBuffer.put(sb);
//         return this;
//     }
// 
//     public BinaryWriter putUnsignedByte(final short ub) {
//         byteBuffer.put((byte) (ub & 0xff));
//         return this;
//     }
// 
//     public BinaryWriter putSignedShort(final short ss) {
//         byteBuffer.putShort(ss);
//         return this;
//     }
// 
//     public BinaryWriter putUnsignedShort(final int us) {
//         byteBuffer.putShort((short) (us & 0xffff));
//         return this;
//     }
// 
//     public BinaryWriter putSignedInt(final int si) {
//         byteBuffer.putInt(si);
//         return this;
//     }
// 
//     public BinaryWriter putUnsignedInt(final long ui) {
//         byteBuffer.putInt((int) (ui & 0xffffffffL));
//         return this;
//     }
// 
//     public BinaryWriter putBytes(final byte[] bytes) {
//         byteBuffer.put(bytes);
//         return this;
//     }
// 
//     public BinaryWriter putBytesGroupWithByteLength(final byte[] bytes) {
//         putUnsignedByte((short) bytes.length);
//         putBytes(bytes);
//         return this;
//     }
// 
//     public BinaryWriter putBytesGroupWithShortLength(final byte[] bytes) {
//         putUnsignedShort(bytes.length);
//         putBytes(bytes);
//         return this;
//     }
// 
//     public BinaryWriter putBoolean(final boolean b) {
//         byteBuffer.put((byte) (b ? 1 : 0));
//         return this;
//     }
// 
//     public byte[] toBytes() {
//         return byteBuffer.array();
//     }
// 
// }


// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/socks5/SOCKS5SocketHelper.java
import com.vecsight.dragonite.proxy.exception.SOCKS5Exception;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/*
 * The Dragonite Project
 * -------------------------
 * See the LICENSE file in the root directory for license information.
 */


package com.vecsight.dragonite.proxy.network.socks5;



public final class SOCKS5SocketHelper {

    private static final byte SOCKS5_VERSION = 0x05;

    private static final byte[] SOCKS5_SUCCEED = {SOCKS5_VERSION, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    private static final byte[] SOCKS5_NOT_ALLOWED = {SOCKS5_VERSION, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    private static final byte[] SOCKS5_FAILED_REFUSED = {SOCKS5_VERSION, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    private static final byte[] SOCKS5_NOT_SUPPORTED = {SOCKS5_VERSION, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    public static SOCKS5Header getHeader(final Socket socket) throws IOException, SOCKS5Exception {