// Path: src/main/java/net/utp4j/data/UtpPacketUtils.java
// public static final int DEF_HEADER_LENGTH = 20;
// 
// Path: src/main/java/net/utp4j/data/UtpPacketUtils.java
// public static byte[] joinByteArray(byte[] array1, byte[] array2) {
// 		
// 	int length1 = array1 == null ? 0 : array1.length;
// 	int length2 = array2 == null ? 0 : array2.length;
// 
// 		
// 	int totalLength = length1 + length2;
// 	byte[] returnArray = new byte[totalLength];
// 		
// 	int i = 0;
// 	for (; i < length1; i++) {
// 		returnArray[i] = array1[i];
// 	}
// 		
// 	for (int j = 0; j < length2; j++) {
// 		returnArray[i] = array2[j];
// 		i++;
// 	}
// 		
// 	return returnArray;
// 		
// }
// 
// Path: src/main/java/net/utp4j/data/bytes/UnsignedTypesUtil.java
// public final class UnsignedTypesUtil {
// 
// 	public static final long MAX_UBYTE = 255;
// 	public static final long MAX_USHORT = 65535;
// 	public static final long MAX_UINT = 4294967295L;
// 
// 		
// 	public static byte longToUbyte(long longvalue) {
// 		if (longvalue > MAX_UBYTE) {
// 			throw new ByteOverflowException(getExceptionText(MAX_UBYTE, longvalue));
// 		} else if (longvalue < 0) {
// 			throw new SignedNumberException(getExceptionText(MAX_UBYTE, longvalue));
// 		}
// 		return (byte) (longvalue & 0xFF);
// 	}
// 	
// 	public static short longToUshort(long longvalue) {
// 		if (longvalue > MAX_USHORT) {
// 			throw new ByteOverflowException(getExceptionText(MAX_USHORT, longvalue));
// 		} else if (longvalue < 0) {
// 			throw new SignedNumberException(getExceptionText(MAX_USHORT, longvalue));
// 		}
// 		return (short) (longvalue & 0xFFFF);
// 	}
// 	
// 	public static int longToUint(long longvalue) {
// 		if (longvalue > MAX_UINT) {
// 			throw new ByteOverflowException(getExceptionText(MAX_UINT, longvalue));
// 		} else if (longvalue < 0) {
// 			throw new SignedNumberException(getExceptionText(MAX_UINT, longvalue));
// 		}
// 		return (int) (longvalue & 0xFFFFFFFF);
// 	}
// 	
// 	private static String getExceptionText(long max, long actual) {
// 		return "Cannot convert to unsigned type. " +
// 				"Possible values [0, " + max +  "] but got " + actual + ".";
// 	}
// 	
// 	public static short bytesToUshort(byte first, byte second) {
// 		short value = (short)( ((first & 0xFF) << 8) | (second & 0xFF) );
// 		return value;
// 	}
// 	
// 	public static int bytesToUint(byte first, byte second, byte third, byte fourth) {
// 		int firstI = (first & 0xFF) << 24;
// 		int secondI = (second & 0xFF) << 16;
// 		int thirdI = (third & 0xFF) << 8;
// 		int fourthI = (fourth & 0xFF);
// 		
// 		return firstI | secondI | thirdI | fourthI;
// 
// 		
// 	}
// 	
// 
// 	
//  }


import static net.utp4j.data.UtpPacketUtils.DEF_HEADER_LENGTH;
import static net.utp4j.data.UtpPacketUtils.joinByteArray;
import java.util.ArrayList;
import net.utp4j.data.bytes.UnsignedTypesUtil;

		byte[] array = {typeVersion, firstExtension, (byte) (connectionId >> 8), (byte) (connectionId),
		(byte) (timestamp >> 24), (byte) (timestamp >> 16), (byte) (timestamp >> 8), (byte) (timestamp),
		(byte) (timestampDifference >> 24), (byte) (timestampDifference >> 16), (byte) (timestampDifference >> 8), (byte) (timestampDifference),
		(byte) (windowSize >> 24), (byte) (windowSize >> 16), (byte) (windowSize >> 8), (byte) (windowSize),
		(byte) (sequenceNumber >> 8), (byte) (sequenceNumber), (byte) (ackNumber >> 8), (byte) (ackNumber), };
		return array;
	}

	private boolean hasExtensions() {
		return !((extensions == null || extensions.length == 0) && firstExtension == 0);
	}

	private int getTotalLengthOfExtensions() {
		if (!hasExtensions()) {
			return 0;
		}
		int length = 0;
		for (int i = 0; i < extensions.length; i++) {
			length += 2 + extensions[i].getBitMask().length;
		}
		return length;
	}
	
	/**
	 * returns the total packet length.
	 * @return bytes.
	 */
	public int getPacketLength() {
		byte[] pl = getPayload();
		int plLength = pl != null ? pl.length : 0;

// Path: src/main/java/net/utp4j/data/UtpPacketUtils.java
// public static final int DEF_HEADER_LENGTH = 20;
// 
// Path: src/main/java/net/utp4j/data/UtpPacketUtils.java
// public static byte[] joinByteArray(byte[] array1, byte[] array2) {
// 		
// 	int length1 = array1 == null ? 0 : array1.length;
// 	int length2 = array2 == null ? 0 : array2.length;
// 
// 		
// 	int totalLength = length1 + length2;
// 	byte[] returnArray = new byte[totalLength];
// 		
// 	int i = 0;
// 	for (; i < length1; i++) {
// 		returnArray[i] = array1[i];
// 	}
// 		
// 	for (int j = 0; j < length2; j++) {
// 		returnArray[i] = array2[j];
// 		i++;
// 	}
// 		
// 	return returnArray;
// 		
// }
// 
// Path: src/main/java/net/utp4j/data/bytes/UnsignedTypesUtil.java
// public final class UnsignedTypesUtil {
// 
// 	public static final long MAX_UBYTE = 255;
// 	public static final long MAX_USHORT = 65535;
// 	public static final long MAX_UINT = 4294967295L;
// 
// 		
// 	public static byte longToUbyte(long longvalue) {
// 		if (longvalue > MAX_UBYTE) {
// 			throw new ByteOverflowException(getExceptionText(MAX_UBYTE, longvalue));
// 		} else if (longvalue < 0) {
// 			throw new SignedNumberException(getExceptionText(MAX_UBYTE, longvalue));
// 		}
// 		return (byte) (longvalue & 0xFF);
// 	}
// 	
// 	public static short longToUshort(long longvalue) {
// 		if (longvalue > MAX_USHORT) {
// 			throw new ByteOverflowException(getExceptionText(MAX_USHORT, longvalue));
// 		} else if (longvalue < 0) {
// 			throw new SignedNumberException(getExceptionText(MAX_USHORT, longvalue));
// 		}
// 		return (short) (longvalue & 0xFFFF);
// 	}
// 	
// 	public static int longToUint(long longvalue) {
// 		if (longvalue > MAX_UINT) {
// 			throw new ByteOverflowException(getExceptionText(MAX_UINT, longvalue));
// 		} else if (longvalue < 0) {
// 			throw new SignedNumberException(getExceptionText(MAX_UINT, longvalue));
// 		}
// 		return (int) (longvalue & 0xFFFFFFFF);
// 	}
// 	
// 	private static String getExceptionText(long max, long actual) {
// 		return "Cannot convert to unsigned type. " +
// 				"Possible values [0, " + max +  "] but got " + actual + ".";
// 	}
// 	
// 	public static short bytesToUshort(byte first, byte second) {
// 		short value = (short)( ((first & 0xFF) << 8) | (second & 0xFF) );
// 		return value;
// 	}
// 	
// 	public static int bytesToUint(byte first, byte second, byte third, byte fourth) {
// 		int firstI = (first & 0xFF) << 24;
// 		int secondI = (second & 0xFF) << 16;
// 		int thirdI = (third & 0xFF) << 8;
// 		int fourthI = (fourth & 0xFF);
// 		
// 		return firstI | secondI | thirdI | fourthI;
// 
// 		
// 	}
// 	
// 
// 	
//  }


// Path: src/main/java/net/utp4j/data/UtpPacket.java
import static net.utp4j.data.UtpPacketUtils.DEF_HEADER_LENGTH;
import static net.utp4j.data.UtpPacketUtils.joinByteArray;
import java.util.ArrayList;
import net.utp4j.data.bytes.UnsignedTypesUtil;

		byte[] array = {typeVersion, firstExtension, (byte) (connectionId >> 8), (byte) (connectionId),
		(byte) (timestamp >> 24), (byte) (timestamp >> 16), (byte) (timestamp >> 8), (byte) (timestamp),
		(byte) (timestampDifference >> 24), (byte) (timestampDifference >> 16), (byte) (timestampDifference >> 8), (byte) (timestampDifference),
		(byte) (windowSize >> 24), (byte) (windowSize >> 16), (byte) (windowSize >> 8), (byte) (windowSize),
		(byte) (sequenceNumber >> 8), (byte) (sequenceNumber), (byte) (ackNumber >> 8), (byte) (ackNumber), };
		return array;
	}

	private boolean hasExtensions() {
		return !((extensions == null || extensions.length == 0) && firstExtension == 0);
	}

	private int getTotalLengthOfExtensions() {
		if (!hasExtensions()) {
			return 0;
		}
		int length = 0;
		for (int i = 0; i < extensions.length; i++) {
			length += 2 + extensions[i].getBitMask().length;
		}
		return length;
	}
	
	/**
	 * returns the total packet length.
	 * @return bytes.
	 */
	public int getPacketLength() {
		byte[] pl = getPayload();
		int plLength = pl != null ? pl.length : 0;

		return DEF_HEADER_LENGTH + getTotalLengthOfExtensions() + plLength;
