repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/socks5/SOCKS5Header.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
| import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import java.util.Arrays; | }
public byte[] getAddr() {
return addr;
}
public void setAddr(final byte[] addr) {
this.addr = addr;
}
public int getPort() {
return port;
}
public void setPort(final int port) {
this.port = port;
}
public boolean isUdp() {
return udp;
}
public void setUdp(final boolean udp) {
this.udp = udp;
}
@Override
public String toString() {
return "SOCKS5Header{" +
"isDomain=" + isDomain + | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/socks5/SOCKS5Header.java
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import java.util.Arrays;
}
public byte[] getAddr() {
return addr;
}
public void setAddr(final byte[] addr) {
this.addr = addr;
}
public int getPort() {
return port;
}
public void setPort(final int port) {
this.port = port;
}
public boolean isUdp() {
return udp;
}
public void setUdp(final boolean udp) {
this.udp = udp;
}
@Override
public String toString() {
return "SOCKS5Header{" +
"isDomain=" + isDomain + | ", addr=" + (isDomain ? new String(addr, ProxyGlobalConstants.HEADER_ADDRESS_CHARSET) : Arrays.toString(addr)) + |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv4ACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv4ACLItem implements ACLItem {
private final byte[] bytes;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv4ACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv4ACLItem implements ACLItem {
private final byte[] bytes;
| private final ACLItemMethod method; |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv4ACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv4ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv4ACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv4ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
| public IPv4ACLItem(final String string, final ACLItemMethod method) throws InvalidAddressException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv4ACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv4ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
public IPv4ACLItem(final String string, final ACLItemMethod method) throws InvalidAddressException {
this.method = method;
try {
bytes = InetAddress.getByName(string).getAddress();
if (bytes.length != 4) throw new InvalidAddressException(string + " is not a valid IPv4 address");
} catch (final UnknownHostException e) {
throw new InvalidAddressException(string + " is not a valid IPv4 address");
}
}
public IPv4ACLItem(final byte[] bytes, final ACLItemMethod method) {
this.method = method;
this.bytes = bytes;
}
@Override | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv4ACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv4ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
public IPv4ACLItem(final String string, final ACLItemMethod method) throws InvalidAddressException {
this.method = method;
try {
bytes = InetAddress.getByName(string).getAddress();
if (bytes.length != 4) throw new InvalidAddressException(string + " is not a valid IPv4 address");
} catch (final UnknownHostException e) {
throw new InvalidAddressException(string + " is not a valid IPv4 address");
}
}
public IPv4ACLItem(final byte[] bytes, final ACLItemMethod method) {
this.method = method;
this.bytes = bytes;
}
@Override | public ACLItemType getType() { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/ServerResponseHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ProxyGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/ServerResponseHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ProxyGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
| public ServerResponseHeader(final byte[] header) throws IncorrectHeaderException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/ServerResponseHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ProxyGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
public ServerResponseHeader(final byte[] header) throws IncorrectHeaderException { | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/ServerResponseHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ProxyGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
public ServerResponseHeader(final byte[] header) throws IncorrectHeaderException { | final BinaryReader reader = new BinaryReader(header); |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/ServerResponseHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | }
}
public byte getStatus() {
return status;
}
public void setStatus(final byte status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(final String msg) {
this.msg = msg;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] msgBytes = msg.getBytes(ProxyGlobalConstants.STRING_CHARSET);
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/ServerResponseHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
}
}
public byte getStatus() {
return status;
}
public void setStatus(final byte status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(final String msg) {
this.msg = msg;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] msgBytes = msg.getBytes(ProxyGlobalConstants.STRING_CHARSET);
| final BinaryWriter writer = new BinaryWriter(getFixedLength() + msgBytes.length); |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainSuffixACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainSuffixACLItem implements ACLItem {
private final String domain;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainSuffixACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainSuffixACLItem implements ACLItem {
private final String domain;
| private final ACLItemMethod method; |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainSuffixACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainSuffixACLItem implements ACLItem {
private final String domain;
private final ACLItemMethod method;
public DomainSuffixACLItem(final String domain, final ACLItemMethod method) {
this.domain = domain;
this.method = method;
}
@Override | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainSuffixACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainSuffixACLItem implements ACLItem {
private final String domain;
private final ACLItemMethod method;
public DomainSuffixACLItem(final String domain, final ACLItemMethod method) {
this.domain = domain;
this.method = method;
}
@Override | public ACLItemType getType() { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/MuxPipe.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.network;
public class MuxPipe {
private final short bufferSize;
public MuxPipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/MuxPipe.java
import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.network;
public class MuxPipe {
private final short bufferSize;
public MuxPipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| public void pipe(final InputStream inputStream, final MultiplexedConnection connection) throws IOException, SenderClosedException, InterruptedException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/MuxPipe.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.network;
public class MuxPipe {
private final short bufferSize;
public MuxPipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/MuxPipe.java
import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.network;
public class MuxPipe {
private final short bufferSize;
public MuxPipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| public void pipe(final InputStream inputStream, final MultiplexedConnection connection) throws IOException, SenderClosedException, InterruptedException { |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/web/DevConsoleWebServer.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocketStatistics.java
// public class DragoniteSocketStatistics {
//
// private final SocketAddress remoteAddress;
//
// private final String description;
//
// private final long sendLength, sendRawLength, readLength, receiveRawLength, estimatedRTT, devRTT;
//
// private final long sendCount, resendCount, receiveCount, dupCount;
//
// public DragoniteSocketStatistics(final SocketAddress remoteAddress, final String description, final long sendLength, final long sendRawLength, final long readLength, final long receiveRawLength, final long estimatedRTT, final long devRTT, final long sendCount, final long resendCount, final long receiveCount, final long dupCount) {
// this.remoteAddress = remoteAddress;
// this.description = description;
// this.sendLength = sendLength;
// this.sendRawLength = sendRawLength;
// this.readLength = readLength;
// this.receiveRawLength = receiveRawLength;
// this.estimatedRTT = estimatedRTT;
// this.devRTT = devRTT;
// this.sendCount = sendCount;
// this.resendCount = resendCount;
// this.receiveCount = receiveCount;
// this.dupCount = dupCount;
// }
//
// public long getSendLength() {
// return sendLength;
// }
//
// public long getSendRawLength() {
// return sendRawLength;
// }
//
// public long getReadLength() {
// return readLength;
// }
//
// public long getReceiveRawLength() {
// return receiveRawLength;
// }
//
// public long getEstimatedRTT() {
// return estimatedRTT;
// }
//
// public long getDevRTT() {
// return devRTT;
// }
//
// public long getSendCount() {
// return sendCount;
// }
//
// public long getResendCount() {
// return resendCount;
// }
//
// public long getReceiveCount() {
// return receiveCount;
// }
//
// public long getDupCount() {
// return dupCount;
// }
//
// public SocketAddress getRemoteAddress() {
// return remoteAddress;
// }
//
// public String getDescription() {
// return description;
// }
// }
| import com.sun.net.httpserver.HttpServer;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.socket.DragoniteSocketStatistics;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.web;
/*
sample:
{
"title": "Dragonite Developer Web Interface",
"version": "0.2.0",
"connections": [
{
"remote": "123.123.123.123:54321",
"description": "someEvilConnection",
"rtt": 90,
"devrtt": 5,
"send": 10240,
"sendraw": 12680,
"sendpkt": 400,
"resend": 60,
"recv": 204800,
"recvraw": 219400,
"recvcount": 3800,
"dup": 280
}
]
}
*/
public class DevConsoleWebServer {
private static final String WEB_TITLE = "Dragonite Developer Web Interface";
private static final Charset CHARSET = StandardCharsets.UTF_8;
private static final int SHUTDOWN_SEC = 2;
private final HttpServer httpServer;
private final StatisticsProvider statisticsProvider;
public DevConsoleWebServer(final InetSocketAddress bindAddress, final StatisticsProvider provider) throws IOException {
this.statisticsProvider = provider;
httpServer = HttpServer.create(bindAddress, 0);
httpServer.createContext("/statistics", httpExchange -> {
final byte[] jsonBytes = getJSON(statisticsProvider.getLatest()).getBytes(CHARSET);
httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
httpExchange.sendResponseHeaders(200, jsonBytes.length);
httpExchange.getResponseBody().write(jsonBytes);
httpExchange.close();
});
httpServer.start();
}
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocketStatistics.java
// public class DragoniteSocketStatistics {
//
// private final SocketAddress remoteAddress;
//
// private final String description;
//
// private final long sendLength, sendRawLength, readLength, receiveRawLength, estimatedRTT, devRTT;
//
// private final long sendCount, resendCount, receiveCount, dupCount;
//
// public DragoniteSocketStatistics(final SocketAddress remoteAddress, final String description, final long sendLength, final long sendRawLength, final long readLength, final long receiveRawLength, final long estimatedRTT, final long devRTT, final long sendCount, final long resendCount, final long receiveCount, final long dupCount) {
// this.remoteAddress = remoteAddress;
// this.description = description;
// this.sendLength = sendLength;
// this.sendRawLength = sendRawLength;
// this.readLength = readLength;
// this.receiveRawLength = receiveRawLength;
// this.estimatedRTT = estimatedRTT;
// this.devRTT = devRTT;
// this.sendCount = sendCount;
// this.resendCount = resendCount;
// this.receiveCount = receiveCount;
// this.dupCount = dupCount;
// }
//
// public long getSendLength() {
// return sendLength;
// }
//
// public long getSendRawLength() {
// return sendRawLength;
// }
//
// public long getReadLength() {
// return readLength;
// }
//
// public long getReceiveRawLength() {
// return receiveRawLength;
// }
//
// public long getEstimatedRTT() {
// return estimatedRTT;
// }
//
// public long getDevRTT() {
// return devRTT;
// }
//
// public long getSendCount() {
// return sendCount;
// }
//
// public long getResendCount() {
// return resendCount;
// }
//
// public long getReceiveCount() {
// return receiveCount;
// }
//
// public long getDupCount() {
// return dupCount;
// }
//
// public SocketAddress getRemoteAddress() {
// return remoteAddress;
// }
//
// public String getDescription() {
// return description;
// }
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/web/DevConsoleWebServer.java
import com.sun.net.httpserver.HttpServer;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.socket.DragoniteSocketStatistics;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.web;
/*
sample:
{
"title": "Dragonite Developer Web Interface",
"version": "0.2.0",
"connections": [
{
"remote": "123.123.123.123:54321",
"description": "someEvilConnection",
"rtt": 90,
"devrtt": 5,
"send": 10240,
"sendraw": 12680,
"sendpkt": 400,
"resend": 60,
"recv": 204800,
"recvraw": 219400,
"recvcount": 3800,
"dup": 280
}
]
}
*/
public class DevConsoleWebServer {
private static final String WEB_TITLE = "Dragonite Developer Web Interface";
private static final Charset CHARSET = StandardCharsets.UTF_8;
private static final int SHUTDOWN_SEC = 2;
private final HttpServer httpServer;
private final StatisticsProvider statisticsProvider;
public DevConsoleWebServer(final InetSocketAddress bindAddress, final StatisticsProvider provider) throws IOException {
this.statisticsProvider = provider;
httpServer = HttpServer.create(bindAddress, 0);
httpServer.createContext("/statistics", httpExchange -> {
final byte[] jsonBytes = getJSON(statisticsProvider.getLatest()).getBytes(CHARSET);
httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
httpExchange.sendResponseHeaders(200, jsonBytes.length);
httpExchange.getResponseBody().write(jsonBytes);
httpExchange.close();
});
httpServer.start();
}
| private String getJSON(final List<DragoniteSocketStatistics> statisticsList) { |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/web/DevConsoleWebServer.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocketStatistics.java
// public class DragoniteSocketStatistics {
//
// private final SocketAddress remoteAddress;
//
// private final String description;
//
// private final long sendLength, sendRawLength, readLength, receiveRawLength, estimatedRTT, devRTT;
//
// private final long sendCount, resendCount, receiveCount, dupCount;
//
// public DragoniteSocketStatistics(final SocketAddress remoteAddress, final String description, final long sendLength, final long sendRawLength, final long readLength, final long receiveRawLength, final long estimatedRTT, final long devRTT, final long sendCount, final long resendCount, final long receiveCount, final long dupCount) {
// this.remoteAddress = remoteAddress;
// this.description = description;
// this.sendLength = sendLength;
// this.sendRawLength = sendRawLength;
// this.readLength = readLength;
// this.receiveRawLength = receiveRawLength;
// this.estimatedRTT = estimatedRTT;
// this.devRTT = devRTT;
// this.sendCount = sendCount;
// this.resendCount = resendCount;
// this.receiveCount = receiveCount;
// this.dupCount = dupCount;
// }
//
// public long getSendLength() {
// return sendLength;
// }
//
// public long getSendRawLength() {
// return sendRawLength;
// }
//
// public long getReadLength() {
// return readLength;
// }
//
// public long getReceiveRawLength() {
// return receiveRawLength;
// }
//
// public long getEstimatedRTT() {
// return estimatedRTT;
// }
//
// public long getDevRTT() {
// return devRTT;
// }
//
// public long getSendCount() {
// return sendCount;
// }
//
// public long getResendCount() {
// return resendCount;
// }
//
// public long getReceiveCount() {
// return receiveCount;
// }
//
// public long getDupCount() {
// return dupCount;
// }
//
// public SocketAddress getRemoteAddress() {
// return remoteAddress;
// }
//
// public String getDescription() {
// return description;
// }
// }
| import com.sun.net.httpserver.HttpServer;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.socket.DragoniteSocketStatistics;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.web;
/*
sample:
{
"title": "Dragonite Developer Web Interface",
"version": "0.2.0",
"connections": [
{
"remote": "123.123.123.123:54321",
"description": "someEvilConnection",
"rtt": 90,
"devrtt": 5,
"send": 10240,
"sendraw": 12680,
"sendpkt": 400,
"resend": 60,
"recv": 204800,
"recvraw": 219400,
"recvcount": 3800,
"dup": 280
}
]
}
*/
public class DevConsoleWebServer {
private static final String WEB_TITLE = "Dragonite Developer Web Interface";
private static final Charset CHARSET = StandardCharsets.UTF_8;
private static final int SHUTDOWN_SEC = 2;
private final HttpServer httpServer;
private final StatisticsProvider statisticsProvider;
public DevConsoleWebServer(final InetSocketAddress bindAddress, final StatisticsProvider provider) throws IOException {
this.statisticsProvider = provider;
httpServer = HttpServer.create(bindAddress, 0);
httpServer.createContext("/statistics", httpExchange -> {
final byte[] jsonBytes = getJSON(statisticsProvider.getLatest()).getBytes(CHARSET);
httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
httpExchange.sendResponseHeaders(200, jsonBytes.length);
httpExchange.getResponseBody().write(jsonBytes);
httpExchange.close();
});
httpServer.start();
}
private String getJSON(final List<DragoniteSocketStatistics> statisticsList) {
return "{\"title\":\"" + WEB_TITLE + | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocketStatistics.java
// public class DragoniteSocketStatistics {
//
// private final SocketAddress remoteAddress;
//
// private final String description;
//
// private final long sendLength, sendRawLength, readLength, receiveRawLength, estimatedRTT, devRTT;
//
// private final long sendCount, resendCount, receiveCount, dupCount;
//
// public DragoniteSocketStatistics(final SocketAddress remoteAddress, final String description, final long sendLength, final long sendRawLength, final long readLength, final long receiveRawLength, final long estimatedRTT, final long devRTT, final long sendCount, final long resendCount, final long receiveCount, final long dupCount) {
// this.remoteAddress = remoteAddress;
// this.description = description;
// this.sendLength = sendLength;
// this.sendRawLength = sendRawLength;
// this.readLength = readLength;
// this.receiveRawLength = receiveRawLength;
// this.estimatedRTT = estimatedRTT;
// this.devRTT = devRTT;
// this.sendCount = sendCount;
// this.resendCount = resendCount;
// this.receiveCount = receiveCount;
// this.dupCount = dupCount;
// }
//
// public long getSendLength() {
// return sendLength;
// }
//
// public long getSendRawLength() {
// return sendRawLength;
// }
//
// public long getReadLength() {
// return readLength;
// }
//
// public long getReceiveRawLength() {
// return receiveRawLength;
// }
//
// public long getEstimatedRTT() {
// return estimatedRTT;
// }
//
// public long getDevRTT() {
// return devRTT;
// }
//
// public long getSendCount() {
// return sendCount;
// }
//
// public long getResendCount() {
// return resendCount;
// }
//
// public long getReceiveCount() {
// return receiveCount;
// }
//
// public long getDupCount() {
// return dupCount;
// }
//
// public SocketAddress getRemoteAddress() {
// return remoteAddress;
// }
//
// public String getDescription() {
// return description;
// }
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/web/DevConsoleWebServer.java
import com.sun.net.httpserver.HttpServer;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.socket.DragoniteSocketStatistics;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.web;
/*
sample:
{
"title": "Dragonite Developer Web Interface",
"version": "0.2.0",
"connections": [
{
"remote": "123.123.123.123:54321",
"description": "someEvilConnection",
"rtt": 90,
"devrtt": 5,
"send": 10240,
"sendraw": 12680,
"sendpkt": 400,
"resend": 60,
"recv": 204800,
"recvraw": 219400,
"recvcount": 3800,
"dup": 280
}
]
}
*/
public class DevConsoleWebServer {
private static final String WEB_TITLE = "Dragonite Developer Web Interface";
private static final Charset CHARSET = StandardCharsets.UTF_8;
private static final int SHUTDOWN_SEC = 2;
private final HttpServer httpServer;
private final StatisticsProvider statisticsProvider;
public DevConsoleWebServer(final InetSocketAddress bindAddress, final StatisticsProvider provider) throws IOException {
this.statisticsProvider = provider;
httpServer = HttpServer.create(bindAddress, 0);
httpServer.createContext("/statistics", httpExchange -> {
final byte[] jsonBytes = getJSON(statisticsProvider.getLatest()).getBytes(CHARSET);
httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
httpExchange.sendResponseHeaders(200, jsonBytes.length);
httpExchange.getResponseBody().write(jsonBytes);
httpExchange.close();
});
httpServer.start();
}
private String getJSON(final List<DragoniteSocketStatistics> statisticsList) {
return "{\"title\":\"" + WEB_TITLE + | "\",\"version\":\"" + DragoniteGlobalConstants.LIBRARY_VERSION + |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ServerResponseHeader.java | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
| // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ServerResponseHeader.java
import com.vecsight.dragonite.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
| public ServerResponseHeader(final byte[] header) throws IncorrectHeaderException { |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ServerResponseHeader.java | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
public ServerResponseHeader(final byte[] header) throws IncorrectHeaderException { | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ServerResponseHeader.java
import com.vecsight.dragonite.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* status 1 SB
* msgLen 2 US
* msg [length]
*/
public class ServerResponseHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 4;
private byte status;
private String msg;
public ServerResponseHeader(final byte status, final String msg) {
this.status = status;
this.msg = msg;
}
public ServerResponseHeader(final byte[] header) throws IncorrectHeaderException { | final BinaryReader reader = new BinaryReader(header); |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ServerResponseHeader.java | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | }
}
public byte getStatus() {
return status;
}
public void setStatus(final byte status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(final String msg) {
this.msg = msg;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] msgBytes = msg.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
| // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ServerResponseHeader.java
import com.vecsight.dragonite.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
}
}
public byte getStatus() {
return status;
}
public void setStatus(final byte status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(final String msg) {
this.msg = msg;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] msgBytes = msg.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
| final BinaryWriter writer = new BinaryWriter(getFixedLength() + msgBytes.length); |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/CreateConnectionFrame.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class CreateConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/CreateConnectionFrame.java
import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class CreateConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| private static final FrameType TYPE = FrameType.CREATE; |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/ResendHandler.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
//
// public static long min(final long l1, final long l2) {
// return l1 < l2 ? l1 : l2;
// }
//
// public static long max(final long l1, final long l2) {
// return l1 > l2 ? l1 : l2;
// }
//
// public static int min(final int i1, final int i2) {
// return i1 < i2 ? i1 : i2;
// }
//
// public static int max(final int i1, final int i2) {
// return i1 > i2 ? i1 : i2;
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
//
// int getSequence();
//
// void setSequence(int sequence);
//
// }
| import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class ResendHandler {
private final DragoniteSocket socket;
private final PacketSender packetSender;
private final ConnectionState state;
private final int minResendMS;
private final int ackDelayCompensation;
private final Thread resendThread;
private volatile boolean running = true;
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
//
// public static long min(final long l1, final long l2) {
// return l1 < l2 ? l1 : l2;
// }
//
// public static long max(final long l1, final long l2) {
// return l1 > l2 ? l1 : l2;
// }
//
// public static int min(final int i1, final int i2) {
// return i1 < i2 ? i1 : i2;
// }
//
// public static int max(final int i1, final int i2) {
// return i1 > i2 ? i1 : i2;
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
//
// int getSequence();
//
// void setSequence(int sequence);
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/ResendHandler.java
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class ResendHandler {
private final DragoniteSocket socket;
private final PacketSender packetSender;
private final ConnectionState state;
private final int minResendMS;
private final int ackDelayCompensation;
private final Thread resendThread;
private volatile boolean running = true;
| private final ConcurrentMap<Integer, ReliableMessage> messageConcurrentMap = new ConcurrentHashMap<>(); |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/ResendHandler.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
//
// public static long min(final long l1, final long l2) {
// return l1 < l2 ? l1 : l2;
// }
//
// public static long max(final long l1, final long l2) {
// return l1 > l2 ? l1 : l2;
// }
//
// public static int min(final int i1, final int i2) {
// return i1 < i2 ? i1 : i2;
// }
//
// public static int max(final int i1, final int i2) {
// return i1 > i2 ? i1 : i2;
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
//
// int getSequence();
//
// void setSequence(int sequence);
//
// }
| import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong; | resendThread = new Thread(() -> {
try {
while (canRun()) {
final long sleepTime;
final int sequence;
ResendItem resendItem;
/*synchronized (queueLock) {
resendItem = resendQueue.take();
sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
sequence = resendItem.getSequence();
resendItem.addSendCount();
resendItem.setNextSendTime(getNextSendTime(resendItem.getSendCount(), NumUtils.max(sleepTime, 0)));
resendQueue.put(resendItem);
}*/
synchronized (queueLock) {
while ((resendItem = riQueue.poll()) == null && canRun()) {
queueLock.wait();
}
if (resendItem == null) {
break;
}
sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
sequence = resendItem.getSequence();
resendItem.addSendCount(); | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
//
// public static long min(final long l1, final long l2) {
// return l1 < l2 ? l1 : l2;
// }
//
// public static long max(final long l1, final long l2) {
// return l1 > l2 ? l1 : l2;
// }
//
// public static int min(final int i1, final int i2) {
// return i1 < i2 ? i1 : i2;
// }
//
// public static int max(final int i1, final int i2) {
// return i1 > i2 ? i1 : i2;
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
//
// int getSequence();
//
// void setSequence(int sequence);
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/ResendHandler.java
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
resendThread = new Thread(() -> {
try {
while (canRun()) {
final long sleepTime;
final int sequence;
ResendItem resendItem;
/*synchronized (queueLock) {
resendItem = resendQueue.take();
sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
sequence = resendItem.getSequence();
resendItem.addSendCount();
resendItem.setNextSendTime(getNextSendTime(resendItem.getSendCount(), NumUtils.max(sleepTime, 0)));
resendQueue.put(resendItem);
}*/
synchronized (queueLock) {
while ((resendItem = riQueue.poll()) == null && canRun()) {
queueLock.wait();
}
if (resendItem == null) {
break;
}
sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
sequence = resendItem.getSequence();
resendItem.addSendCount(); | resendItem.setNextSendTime(getNextSendTime(resendItem.getSendCount(), NumUtils.max(sleepTime, 0))); |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/ResendHandler.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
//
// public static long min(final long l1, final long l2) {
// return l1 < l2 ? l1 : l2;
// }
//
// public static long max(final long l1, final long l2) {
// return l1 > l2 ? l1 : l2;
// }
//
// public static int min(final int i1, final int i2) {
// return i1 < i2 ? i1 : i2;
// }
//
// public static int max(final int i1, final int i2) {
// return i1 > i2 ? i1 : i2;
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
//
// int getSequence();
//
// void setSequence(int sequence);
//
// }
| import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong; |
if (sleepTime > 0) {
Thread.sleep(sleepTime);
}
//sleep done
final ReliableMessage message = messageConcurrentMap.get(sequence);
if (message != null) {
try {
resendItem.setResended();
packetSender.sendPacket(message.toBytes());
resendCount++;
//System.out.println(message.getSequence());
} catch (final IOException ignored) {
}
}
}
} catch (final InterruptedException ignored) {
//okay
}
}, "DS-Resend");
resendThread.start();
}
private boolean canRun() {
return running && socket.isAlive();
}
private long getNextSendTime(final int count, final long timeOffset) { | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
//
// public static long min(final long l1, final long l2) {
// return l1 < l2 ? l1 : l2;
// }
//
// public static long max(final long l1, final long l2) {
// return l1 > l2 ? l1 : l2;
// }
//
// public static int min(final int i1, final int i2) {
// return i1 < i2 ? i1 : i2;
// }
//
// public static int max(final int i1, final int i2) {
// return i1 > i2 ? i1 : i2;
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
//
// int getSequence();
//
// void setSequence(int sequence);
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/ResendHandler.java
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
if (sleepTime > 0) {
Thread.sleep(sleepTime);
}
//sleep done
final ReliableMessage message = messageConcurrentMap.get(sequence);
if (message != null) {
try {
resendItem.setResended();
packetSender.sendPacket(message.toBytes());
resendCount++;
//System.out.println(message.getSequence());
} catch (final IOException ignored) {
}
}
}
} catch (final InterruptedException ignored) {
//okay
}
}, "DS-Resend");
resendThread.start();
}
private boolean canRun() {
return running && socket.isAlive();
}
private long getNextSendTime(final int count, final long timeOffset) { | final int resendMult = count <= DragoniteGlobalConstants.MAX_FAST_RESEND_COUNT ? 1 : |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/socks5/SOCKS5SocketHelper.java | // 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 { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/network/socks5/SOCKS5SocketHelper.java | // 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; | inputStream.readFully(addr);
} else if (atyp == 0x04) {
//IPv6
addr = new byte[16];
inputStream.readFully(addr);
} else {
throw new SOCKS5Exception("Unknown address type");
}
port = inputStream.readUnsignedShort();
if (cmd == 0x01 || cmd == 0x03) {
//CONNECT & UDP ASSOCIATE
if (atyp == 0x03)
return new SOCKS5Header(true, addr, port, cmd == 0x03);
else
return new SOCKS5Header(false, addr, port, cmd == 0x03);
//No response frame yet
} else {
//Not supported, yet
outputStream.write(SOCKS5_NOT_SUPPORTED);
throw new SOCKS5Exception("Command " + cmd + " is not supported.");
}
}
public static void sendSucceed(final Socket socket) throws IOException {
socket.getOutputStream().write(SOCKS5_SUCCEED);
}
public static void sendSucceedUDP(final Socket socket, final int port) throws IOException {
final byte[] localAddress = socket.getLocalAddress().getAddress();
| // 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;
inputStream.readFully(addr);
} else if (atyp == 0x04) {
//IPv6
addr = new byte[16];
inputStream.readFully(addr);
} else {
throw new SOCKS5Exception("Unknown address type");
}
port = inputStream.readUnsignedShort();
if (cmd == 0x01 || cmd == 0x03) {
//CONNECT & UDP ASSOCIATE
if (atyp == 0x03)
return new SOCKS5Header(true, addr, port, cmd == 0x03);
else
return new SOCKS5Header(false, addr, port, cmd == 0x03);
//No response frame yet
} else {
//Not supported, yet
outputStream.write(SOCKS5_NOT_SUPPORTED);
throw new SOCKS5Exception("Command " + cmd + " is not supported.");
}
}
public static void sendSucceed(final Socket socket) throws IOException {
socket.getOutputStream().write(SOCKS5_SUCCEED);
}
public static void sendSucceedUDP(final Socket socket, final int port) throws IOException {
final byte[] localAddress = socket.getLocalAddress().getAddress();
| final BinaryWriter writer = new BinaryWriter(6 + localAddress.length); |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6ACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6ACLItem implements ACLItem {
private final byte[] bytes;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6ACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6ACLItem implements ACLItem {
private final byte[] bytes;
| private final ACLItemMethod method; |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6ACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6ACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
| public IPv6ACLItem(final String string, final ACLItemMethod method) throws InvalidAddressException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6ACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
public IPv6ACLItem(final String string, final ACLItemMethod method) throws InvalidAddressException {
this.method = method;
try {
bytes = InetAddress.getByName(string).getAddress();
if (bytes.length != 16) throw new InvalidAddressException(string + " is not a valid IPv6 address");
} catch (final UnknownHostException e) {
throw new InvalidAddressException(string + " is not a valid IPv6 address");
}
}
public IPv6ACLItem(final byte[] bytes, final ACLItemMethod method) {
this.method = method;
this.bytes = bytes;
}
@Override | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6ACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6ACLItem implements ACLItem {
private final byte[] bytes;
private final ACLItemMethod method;
public IPv6ACLItem(final String string, final ACLItemMethod method) throws InvalidAddressException {
this.method = method;
try {
bytes = InetAddress.getByName(string).getAddress();
if (bytes.length != 16) throw new InvalidAddressException(string + " is not a valid IPv6 address");
} catch (final UnknownHostException e) {
throw new InvalidAddressException(string + " is not a valid IPv6 address");
}
}
public IPv6ACLItem(final byte[] bytes, final ACLItemMethod method) {
this.method = method;
this.bytes = bytes;
}
@Override | public ACLItemType getType() { |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/network/Pipe.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.network;
public class Pipe {
private final short bufferSize;
public Pipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/network/Pipe.java
import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.network;
public class Pipe {
private final short bufferSize;
public Pipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| public void pipe(final InputStream inputStream, final MultiplexedConnection connection) throws IOException, SenderClosedException, InterruptedException { |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/network/Pipe.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.network;
public class Pipe {
private final short bufferSize;
public Pipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/MultiplexedConnection.java
// public class MultiplexedConnection {
//
// private final Multiplexer multiplexer;
//
// private final short connectionID;
//
// private final PacketSender packetSender;
//
// private final Queue<Frame> frameQueue = new LinkedList<>();
//
// private volatile boolean alive = true;
//
// private volatile boolean stopSend = false;
//
// private final Object closeLock = new Object();
//
// private final Object frameLock = new Object();
//
// private volatile int bufSize = 0;
//
// private volatile boolean remotePauseSend = false; //Told remote to stop send
//
// private volatile boolean localPauseSend = false; //Remote told to stop send
//
// private final Object sendLock = new Object();
//
// public MultiplexedConnection(final Multiplexer multiplexer, final short connectionID, final PacketSender packetSender) {
// this.multiplexer = multiplexer;
// this.connectionID = connectionID;
// this.packetSender = packetSender;
// }
//
// protected void addFrame(final Frame frame) {
// if (alive) {
// synchronized (frameLock) {
// frameQueue.add(frame);
//
// if (frame instanceof DataFrame) {
// bufSize += ((DataFrame) frame).getData().length;
// if (bufSize > MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && !remotePauseSend) {
// remotePauseSend = true;
// packetSender.sendPacket(new PauseConnectionFrame(connectionID).toBytes());
// }
// }
//
// frameLock.notifyAll();
// }
// }
// }
//
// private byte[] readRaw() throws InterruptedException, ConnectionNotAliveException {
// if (alive) {
// Frame frame;
// synchronized (frameLock) {
// while ((frame = frameQueue.poll()) == null && alive) {
// frameLock.wait();
// }
// }
//
// if (frame == null) {
// throw new ConnectionNotAliveException();
// }
//
// if (frame instanceof DataFrame) {
// final byte[] data = ((DataFrame) frame).getData();
//
// synchronized (frameLock) {
// bufSize -= data.length;
// if (bufSize < MuxGlobalConstants.CONNECTION_MAX_DATA_BUFFER_SIZE && remotePauseSend) {
// remotePauseSend = false;
// packetSender.sendPacket(new ContinueConnectionFrame(connectionID).toBytes());
// }
// }
//
// return data;
// } else if (frame instanceof CloseConnectionFrame) {
// close();
// return null;
// } else {
// return null;
// }
// } else {
// throw new ConnectionNotAliveException();
// }
// }
//
// public byte[] read() throws ConnectionNotAliveException, InterruptedException {
// byte[] tmp = null;
// while (tmp == null) {
// tmp = readRaw();
// }
// return tmp;
// }
//
// private boolean canSend() {
// return alive && !stopSend;
// }
//
// public void send(final byte[] bytes) throws SenderClosedException, InterruptedException {
// if (canSend()) {
// synchronized (sendLock) {
// while (localPauseSend && canSend()) {
// sendLock.wait();
// }
// }
// packetSender.sendPacket(new DataFrame(connectionID, bytes).toBytes());
// } else {
// throw new SenderClosedException();
// }
// }
//
// protected void pauseSend() {
// localPauseSend = true;
// }
//
// protected void continueSend() {
// localPauseSend = false;
// synchronized (sendLock) {
// sendLock.notifyAll();
// }
// }
//
// public boolean isAlive() {
// return alive;
// }
//
// public short getID() {
// return connectionID;
// }
//
// protected void closeSender() {
// stopSend = true;
// }
//
// public void close() {
// close_impl(true);
// }
//
// protected void closeNoRemove() {
// close_impl(false);
// }
//
// private void close_impl(final boolean removeFromMap) {
// synchronized (closeLock) {
// if (alive) {
//
// packetSender.sendPacket(new CloseConnectionFrame(connectionID).toBytes());
//
// alive = false;
//
// continueSend();
//
// if (removeFromMap) multiplexer.removeConnectionFromMap(connectionID);
//
// synchronized (frameLock) {
// frameQueue.clear();
// frameLock.notifyAll();
// }
//
// }
// }
// }
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends MuxException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/SenderClosedException.java
// public class SenderClosedException extends MuxException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/network/Pipe.java
import com.vecsight.dragonite.mux.conn.MultiplexedConnection;
import com.vecsight.dragonite.mux.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.mux.exception.SenderClosedException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.network;
public class Pipe {
private final short bufferSize;
public Pipe(final short bufferSize) {
this.bufferSize = bufferSize;
}
| public void pipe(final InputStream inputStream, final MultiplexedConnection connection) throws IOException, SenderClosedException, InterruptedException { |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
| import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.conn;
public class Multiplexer {
private final PacketSender packetSender;
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java
import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.conn;
public class Multiplexer {
private final PacketSender packetSender;
| private final FrameParser frameParser; |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
| import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.conn;
public class Multiplexer {
private final PacketSender packetSender;
private final FrameParser frameParser;
private final Map<Short, MultiplexedConnection> connectionMap = new HashMap<>();
private final Object connLock = new Object();
private final Queue<MultiplexedConnection> acceptQueue = new LinkedList<>();
private final Object acceptLock = new Object();
private volatile boolean alive = true;
public Multiplexer(final PacketSender packetSender, final int maxFrameSize) {
this.packetSender = packetSender;
frameParser = new FrameParser(maxFrameSize);
}
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java
import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.conn;
public class Multiplexer {
private final PacketSender packetSender;
private final FrameParser frameParser;
private final Map<Short, MultiplexedConnection> connectionMap = new HashMap<>();
private final Object connLock = new Object();
private final Queue<MultiplexedConnection> acceptQueue = new LinkedList<>();
private final Object acceptLock = new Object();
private volatile boolean alive = true;
public Multiplexer(final PacketSender packetSender, final int maxFrameSize) {
this.packetSender = packetSender;
frameParser = new FrameParser(maxFrameSize);
}
| public MultiplexedConnection createConnection(final short connID) throws ConnectionAlreadyExistsException, MultiplexerClosedException { |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
| import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.conn;
public class Multiplexer {
private final PacketSender packetSender;
private final FrameParser frameParser;
private final Map<Short, MultiplexedConnection> connectionMap = new HashMap<>();
private final Object connLock = new Object();
private final Queue<MultiplexedConnection> acceptQueue = new LinkedList<>();
private final Object acceptLock = new Object();
private volatile boolean alive = true;
public Multiplexer(final PacketSender packetSender, final int maxFrameSize) {
this.packetSender = packetSender;
frameParser = new FrameParser(maxFrameSize);
}
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java
import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.conn;
public class Multiplexer {
private final PacketSender packetSender;
private final FrameParser frameParser;
private final Map<Short, MultiplexedConnection> connectionMap = new HashMap<>();
private final Object connLock = new Object();
private final Queue<MultiplexedConnection> acceptQueue = new LinkedList<>();
private final Object acceptLock = new Object();
private volatile boolean alive = true;
public Multiplexer(final PacketSender packetSender, final int maxFrameSize) {
this.packetSender = packetSender;
frameParser = new FrameParser(maxFrameSize);
}
| public MultiplexedConnection createConnection(final short connID) throws ConnectionAlreadyExistsException, MultiplexerClosedException { |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
| import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*; | }
protected void removeConnectionFromMap(final short connID) {
synchronized (connLock) {
connectionMap.remove(connID);
}
}
public boolean isAlive() {
return alive;
}
public void close() {
if (alive) {
alive = false;
synchronized (connLock) {
for (final Iterator<Map.Entry<Short, MultiplexedConnection>> it = connectionMap.entrySet().iterator(); it.hasNext(); ) {
final Map.Entry<Short, MultiplexedConnection> entry = it.next();
entry.getValue().closeNoRemove();
it.remove();
}
}
synchronized (acceptLock) {
acceptQueue.clear();
acceptLock.notifyAll();
}
}
}
public void onReceiveBytes(final byte[] rawBytes) { | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/ConnectionAlreadyExistsException.java
// public class ConnectionAlreadyExistsException extends MuxException {
//
// public ConnectionAlreadyExistsException() {
// super("Connection already exists");
// }
//
// public ConnectionAlreadyExistsException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/MultiplexerClosedException.java
// public class MultiplexerClosedException extends MuxException {
//
// public MultiplexerClosedException() {
// super("Multiplexer closed");
// }
//
// public MultiplexerClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
// public class FrameParser {
//
// private final FrameBuffer frameBuffer;
//
// private boolean needMore = false;
//
// private int expectedLength = 0;
//
// public FrameParser(final int maxFrameSize) {
// frameBuffer = new FrameBuffer(maxFrameSize);
// }
//
// public Frame feed(final byte[] rawBytes) {
//
// frameBuffer.add(rawBytes);
//
// if (!needMore || frameBuffer.getSize() >= expectedLength) {
//
// try {
// final Frame frame = parseFrameRaw(frameBuffer.get());
//
// if (frame.getExpectedLength() == 0) {
// frameBuffer.reset();
// needMore = false;
// return frame;
//
// } else {
// expectedLength = frame.getExpectedLength();
// needMore = true;
// }
// } catch (final IncorrectFrameException e) {
// frameBuffer.reset();
// needMore = false;
// }
// return null;
//
// } else {
// return null;
// }
//
// }
//
// private static Frame parseFrameRaw(final byte[] rawBytes) throws IncorrectFrameException {
// if (rawBytes.length >= 2) {
// try {
// switch (FrameType.fromByte(rawBytes[1])) {
// case CREATE:
// return new CreateConnectionFrame(rawBytes);
// case CLOSE:
// return new CloseConnectionFrame(rawBytes);
// case DATA:
// return new DataFrame(rawBytes);
// case PAUSE:
// return new PauseConnectionFrame(rawBytes);
// case CONTINUE:
// return new ContinueConnectionFrame(rawBytes);
// default:
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } catch (final IllegalArgumentException e) {
// throw new IncorrectFrameException("Unknown Frame Type");
// }
// } else {
// throw new IncorrectFrameException("Packet is too short");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/conn/Multiplexer.java
import com.vecsight.dragonite.mux.exception.ConnectionAlreadyExistsException;
import com.vecsight.dragonite.mux.exception.MultiplexerClosedException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameParser;
import com.vecsight.dragonite.mux.frame.types.*;
import java.util.*;
}
protected void removeConnectionFromMap(final short connID) {
synchronized (connLock) {
connectionMap.remove(connID);
}
}
public boolean isAlive() {
return alive;
}
public void close() {
if (alive) {
alive = false;
synchronized (connLock) {
for (final Iterator<Map.Entry<Short, MultiplexedConnection>> it = connectionMap.entrySet().iterator(); it.hasNext(); ) {
final Map.Entry<Short, MultiplexedConnection> entry = it.next();
entry.getValue().closeNoRemove();
it.remove();
}
}
synchronized (acceptLock) {
acceptQueue.clear();
acceptLock.notifyAll();
}
}
}
public void onReceiveBytes(final byte[] rawBytes) { | final Frame frame = frameParser.feed(rawBytes); |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ClientInfoHeader.java | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* downMbps 2 US
* upMbps 2 US
* nameLen 1 UB
* nameStr [length]
* verLen 1 UB
* verStr [length]
* osLen 1 UB
* osStr [length]
*/
public class ClientInfoHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 8;
private int downMbps, upMbps;
private String name, appVer, osName;
public ClientInfoHeader(final int downMbps, final int upMbps, final String name, final String appVer, final String osName) {
this.downMbps = downMbps;
this.upMbps = upMbps;
this.name = name;
this.appVer = appVer;
this.osName = osName;
}
| // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ClientInfoHeader.java
import com.vecsight.dragonite.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* downMbps 2 US
* upMbps 2 US
* nameLen 1 UB
* nameStr [length]
* verLen 1 UB
* verStr [length]
* osLen 1 UB
* osStr [length]
*/
public class ClientInfoHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 8;
private int downMbps, upMbps;
private String name, appVer, osName;
public ClientInfoHeader(final int downMbps, final int upMbps, final String name, final String appVer, final String osName) {
this.downMbps = downMbps;
this.upMbps = upMbps;
this.name = name;
this.appVer = appVer;
this.osName = osName;
}
| public ClientInfoHeader(final byte[] header) throws IncorrectHeaderException { |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ClientInfoHeader.java | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* downMbps 2 US
* upMbps 2 US
* nameLen 1 UB
* nameStr [length]
* verLen 1 UB
* verStr [length]
* osLen 1 UB
* osStr [length]
*/
public class ClientInfoHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 8;
private int downMbps, upMbps;
private String name, appVer, osName;
public ClientInfoHeader(final int downMbps, final int upMbps, final String name, final String appVer, final String osName) {
this.downMbps = downMbps;
this.upMbps = upMbps;
this.name = name;
this.appVer = appVer;
this.osName = osName;
}
public ClientInfoHeader(final byte[] header) throws IncorrectHeaderException { | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ClientInfoHeader.java
import com.vecsight.dragonite.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.forwarder.header;
/*
* VERSION 1 SB
* downMbps 2 US
* upMbps 2 US
* nameLen 1 UB
* nameStr [length]
* verLen 1 UB
* verStr [length]
* osLen 1 UB
* osStr [length]
*/
public class ClientInfoHeader {
private static final byte VERSION = ForwarderGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 8;
private int downMbps, upMbps;
private String name, appVer, osName;
public ClientInfoHeader(final int downMbps, final int upMbps, final String name, final String appVer, final String osName) {
this.downMbps = downMbps;
this.upMbps = upMbps;
this.name = name;
this.appVer = appVer;
this.osName = osName;
}
public ClientInfoHeader(final byte[] header) throws IncorrectHeaderException { | final BinaryReader reader = new BinaryReader(header); |
dragonite-network/dragonite-java | dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ClientInfoHeader.java | // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; |
public String getAppVer() {
return appVer;
}
public void setAppVer(final String appVer) {
this.appVer = appVer;
}
public String getOsName() {
return osName;
}
public void setOsName(final String osName) {
this.osName = osName;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] nameBytes = name.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
final byte[] appVerBytes = appVer.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
final byte[] osNameBytes = osName.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
| // Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java
// public final class ForwarderGlobalConstants {
//
// public static final String APP_VERSION = ForwarderBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 3;
//
// public static final int DEFAULT_SERVER_PORT = 5233;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "forwarder";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-forwarder/src/main/java/com/vecsight/dragonite/forwarder/header/ClientInfoHeader.java
import com.vecsight.dragonite.forwarder.exception.IncorrectHeaderException;
import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
public String getAppVer() {
return appVer;
}
public void setAppVer(final String appVer) {
this.appVer = appVer;
}
public String getOsName() {
return osName;
}
public void setOsName(final String osName) {
this.osName = osName;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] nameBytes = name.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
final byte[] appVerBytes = appVer.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
final byte[] osNameBytes = osName.getBytes(ForwarderGlobalConstants.STRING_CHARSET);
| final BinaryWriter writer = new BinaryWriter(getFixedLength() + nameBytes.length + appVerBytes.length + osNameBytes.length); |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/cryptor/AESCryptor.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/EncryptionException.java
// public class EncryptionException extends Exception {
//
// public EncryptionException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.sdk.exception.EncryptionException;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.cryptor;
public class AESCryptor implements PacketCryptor {
private static final int IV_LENGTH = 16;
private static final int PADDING_LENGTH = 16;
private static final String ENCRYPTION_ALGORITHM = "AES";
private static final String ENCRYPTION_ALGORITHM_WITH_MODE = "AES/CBC/PKCS5Padding";
private static final String PASSWORD_HASH_ALGORITHM = "PBKDF2WithHmacSHA1";
private static final byte[] PASSWORD_HASH_SALT = "*1w@UTcZLS@6fS713x80".getBytes(StandardCharsets.UTF_8);
private static final int PASSWORD_HASH_ITERATION_COUNT = 12450;
private static final int PASSWORD_HASH_LENGTH_BITS = 128;
private final SecretKeySpec keySpec;
private final Cipher decryptionCipher;
private final Cipher encryptionCipher;
private final SecureRandom random = new SecureRandom();
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/EncryptionException.java
// public class EncryptionException extends Exception {
//
// public EncryptionException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/cryptor/AESCryptor.java
import com.vecsight.dragonite.sdk.exception.EncryptionException;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.cryptor;
public class AESCryptor implements PacketCryptor {
private static final int IV_LENGTH = 16;
private static final int PADDING_LENGTH = 16;
private static final String ENCRYPTION_ALGORITHM = "AES";
private static final String ENCRYPTION_ALGORITHM_WITH_MODE = "AES/CBC/PKCS5Padding";
private static final String PASSWORD_HASH_ALGORITHM = "PBKDF2WithHmacSHA1";
private static final byte[] PASSWORD_HASH_SALT = "*1w@UTcZLS@6fS713x80".getBytes(StandardCharsets.UTF_8);
private static final int PASSWORD_HASH_ITERATION_COUNT = 12450;
private static final int PASSWORD_HASH_LENGTH_BITS = 128;
private final SecretKeySpec keySpec;
private final Cipher decryptionCipher;
private final Cipher encryptionCipher;
private final SecureRandom random = new SecureRandom();
| public AESCryptor(final String password) throws EncryptionException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainACLItem implements ACLItem {
private final String domain;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainACLItem implements ACLItem {
private final String domain;
| private final ACLItemMethod method; |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainACLItem implements ACLItem {
private final String domain;
private final ACLItemMethod method;
public DomainACLItem(final String domain, final ACLItemMethod method) {
this.domain = domain;
this.method = method;
}
@Override | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/DomainACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class DomainACLItem implements ACLItem {
private final String domain;
private final ACLItemMethod method;
public DomainACLItem(final String domain, final ACLItemMethod method) {
this.domain = domain;
this.method = method;
}
@Override | public ACLItemType getType() { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/udp/ProxyUDPRelayHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.udp;
/*
* addrType 1 SB
* addr [4B/16B/1+length]
* port 2 US
* payload [REMAINING]
*/
public class ProxyUDPRelayHeader {
private AddressType type;
private byte[] addr;
private int port;
private byte[] payload;
public ProxyUDPRelayHeader(final AddressType type, final byte[] addr, final int port, final byte[] payload) {
this.type = type;
this.addr = addr;
this.port = port;
this.payload = payload;
}
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/udp/ProxyUDPRelayHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.udp;
/*
* addrType 1 SB
* addr [4B/16B/1+length]
* port 2 US
* payload [REMAINING]
*/
public class ProxyUDPRelayHeader {
private AddressType type;
private byte[] addr;
private int port;
private byte[] payload;
public ProxyUDPRelayHeader(final AddressType type, final byte[] addr, final int port, final byte[] payload) {
this.type = type;
this.addr = addr;
this.port = port;
this.payload = payload;
}
| public ProxyUDPRelayHeader(final byte[] header) throws IncorrectHeaderException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/udp/ProxyUDPRelayHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.udp;
/*
* addrType 1 SB
* addr [4B/16B/1+length]
* port 2 US
* payload [REMAINING]
*/
public class ProxyUDPRelayHeader {
private AddressType type;
private byte[] addr;
private int port;
private byte[] payload;
public ProxyUDPRelayHeader(final AddressType type, final byte[] addr, final int port, final byte[] payload) {
this.type = type;
this.addr = addr;
this.port = port;
this.payload = payload;
}
public ProxyUDPRelayHeader(final byte[] header) throws IncorrectHeaderException { | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/udp/ProxyUDPRelayHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.udp;
/*
* addrType 1 SB
* addr [4B/16B/1+length]
* port 2 US
* payload [REMAINING]
*/
public class ProxyUDPRelayHeader {
private AddressType type;
private byte[] addr;
private int port;
private byte[] payload;
public ProxyUDPRelayHeader(final AddressType type, final byte[] addr, final int port, final byte[] payload) {
this.type = type;
this.addr = addr;
this.port = port;
this.payload = payload;
}
public ProxyUDPRelayHeader(final byte[] header) throws IncorrectHeaderException { | final BinaryReader reader = new BinaryReader(header); |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/udp/ProxyUDPRelayHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | this.type = type;
}
public byte[] getAddr() {
return addr;
}
public void setAddr(final byte[] addr) {
this.addr = addr;
}
public int getPort() {
return port;
}
public void setPort(final int port) {
this.port = port;
}
public byte[] getPayload() {
return payload;
}
public void setPayload(final byte[] payload) {
this.payload = payload;
}
public byte[] toBytes() {
final int addrTotalLength = (type == AddressType.IPv4 ? 4 : (type == AddressType.IPv6 ? 16 : 1 + addr.length));
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/udp/ProxyUDPRelayHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
this.type = type;
}
public byte[] getAddr() {
return addr;
}
public void setAddr(final byte[] addr) {
this.addr = addr;
}
public int getPort() {
return port;
}
public void setPort(final int port) {
this.port = port;
}
public byte[] getPayload() {
return payload;
}
public void setPayload(final byte[] payload) {
this.payload = payload;
}
public byte[] toBytes() {
final int addrTotalLength = (type == AddressType.IPv4 ? 4 : (type == AddressType.IPv6 ? 16 : 1 + addr.length));
| final BinaryWriter writer = new BinaryWriter(3 + addrTotalLength + payload.length); |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/PauseConnectionFrame.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class PauseConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/PauseConnectionFrame.java
import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class PauseConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| private static final FrameType TYPE = FrameType.PAUSE; |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/BucketPacketSender.java | // Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/flow/Preconditions.java
// public static void checkArgument(final boolean ok, final String message) {
// if (!ok) throw new IllegalArgumentException(message);
// }
| import com.github.bucket4j.Bandwidth;
import com.github.bucket4j.Bucket;
import com.github.bucket4j.Bucket4j;
import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import static com.vecsight.dragonite.utils.flow.Preconditions.checkArgument; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class BucketPacketSender implements PacketSender {
private final PacketSender packetSender;
private volatile Bucket bucket;
private volatile long speed;
private final AtomicLong sendRawLength = new AtomicLong(0);
public BucketPacketSender(final PacketSender packetSender, final long speed) {
this.packetSender = packetSender;
setSpeed(speed);
}
public void setSpeed(final long speed) { | // Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/flow/Preconditions.java
// public static void checkArgument(final boolean ok, final String message) {
// if (!ok) throw new IllegalArgumentException(message);
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/BucketPacketSender.java
import com.github.bucket4j.Bandwidth;
import com.github.bucket4j.Bucket;
import com.github.bucket4j.Bucket4j;
import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import static com.vecsight.dragonite.utils.flow.Preconditions.checkArgument;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class BucketPacketSender implements PacketSender {
private final PacketSender packetSender;
private volatile Bucket bucket;
private volatile long speed;
private final AtomicLong sendRawLength = new AtomicLong(0);
public BucketPacketSender(final PacketSender packetSender, final long speed) {
this.packetSender = packetSender;
setSpeed(speed);
}
public void setSpeed(final long speed) { | checkArgument(speed > 0, "Speed must be greater than zero"); |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6CIDRACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6CIDRACLItem implements ACLItem {
private final BigInteger lowest;
private final BigInteger highest;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6CIDRACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6CIDRACLItem implements ACLItem {
private final BigInteger lowest;
private final BigInteger highest;
| private final ACLItemMethod method; |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6CIDRACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6CIDRACLItem implements ACLItem {
private final BigInteger lowest;
private final BigInteger highest;
private final ACLItemMethod method;
private static final byte[] MASK_BASE = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6CIDRACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public class IPv6CIDRACLItem implements ACLItem {
private final BigInteger lowest;
private final BigInteger highest;
private final ACLItemMethod method;
private static final byte[] MASK_BASE = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
| public IPv6CIDRACLItem(final String string, final ACLItemMethod method) throws InvalidAddressException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6CIDRACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException; | throw new InvalidAddressException(string + " is not a valid IPv6 CIDR address");
}
final byte[] ipBytes;
try {
ipBytes = InetAddress.getByName(stringSplit[0]).getAddress();
if (ipBytes.length != 16) throw new InvalidAddressException(string + " is not a valid IPv6 address");
} catch (final UnknownHostException e) {
throw new InvalidAddressException(stringSplit[0] + " is not a valid IPv6 address");
}
final int cidrShift;
try {
cidrShift = Integer.parseInt(stringSplit[1]);
if (cidrShift < 1 || cidrShift > 128)
throw new InvalidAddressException(string + " is not a valid IPv6 CIDR address");
} catch (final NumberFormatException e) {
throw new InvalidAddressException(string + " is not a valid IPv4 CIDR address");
}
final BigInteger mask = (new BigInteger(1, MASK_BASE)).not().shiftRight(cidrShift);
final BigInteger ipVal = new BigInteger(1, ipBytes);
lowest = ipVal.and(mask);
highest = lowest.add(mask.not());
}
@Override | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/InvalidAddressException.java
// public class InvalidAddressException extends Exception {
//
// public InvalidAddressException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/IPv6CIDRACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
import com.vecsight.dragonite.proxy.exception.InvalidAddressException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
throw new InvalidAddressException(string + " is not a valid IPv6 CIDR address");
}
final byte[] ipBytes;
try {
ipBytes = InetAddress.getByName(stringSplit[0]).getAddress();
if (ipBytes.length != 16) throw new InvalidAddressException(string + " is not a valid IPv6 address");
} catch (final UnknownHostException e) {
throw new InvalidAddressException(stringSplit[0] + " is not a valid IPv6 address");
}
final int cidrShift;
try {
cidrShift = Integer.parseInt(stringSplit[1]);
if (cidrShift < 1 || cidrShift > 128)
throw new InvalidAddressException(string + " is not a valid IPv6 CIDR address");
} catch (final NumberFormatException e) {
throw new InvalidAddressException(string + " is not a valid IPv4 CIDR address");
}
final BigInteger mask = (new BigInteger(1, MASK_BASE)).not().shiftRight(cidrShift);
final BigInteger ipVal = new BigInteger(1, ipBytes);
lowest = ipVal.and(mask);
highest = lowest.add(mask.not());
}
@Override | public ACLItemType getType() { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/ACLItem.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
| import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public interface ACLItem {
ACLItemType getType();
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemMethod.java
// public enum ACLItemMethod {
// DIRECT,
// PROXY,
// REJECT
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ACLItemType.java
// public enum ACLItemType {
// DOMAIN,
// DOMAIN_SUFFIX,
// IPv4,
// IPv4_CIDR,
// IPv6,
// IPv6_CIDR
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/ACLItem.java
import com.vecsight.dragonite.proxy.acl.ACLItemMethod;
import com.vecsight.dragonite.proxy.acl.ACLItemType;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl.item;
public interface ACLItem {
ACLItemType getType();
| ACLItemMethod getMethod(); |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocket.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import java.io.IOException;
import java.net.SocketAddress; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public abstract class DragoniteSocket {
public abstract byte[] read() throws InterruptedException, ConnectionNotAliveException;
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocket.java
import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import java.io.IOException;
import java.net.SocketAddress;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public abstract class DragoniteSocket {
public abstract byte[] read() throws InterruptedException, ConnectionNotAliveException;
| public abstract void send(byte[] bytes) throws InterruptedException, IncorrectSizeException, IOException, SenderClosedException; |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocket.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
| import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import java.io.IOException;
import java.net.SocketAddress; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public abstract class DragoniteSocket {
public abstract byte[] read() throws InterruptedException, ConnectionNotAliveException;
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteSocket.java
import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import java.io.IOException;
import java.net.SocketAddress;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public abstract class DragoniteSocket {
public abstract byte[] read() throws InterruptedException, ConnectionNotAliveException;
| public abstract void send(byte[] bytes) throws InterruptedException, IncorrectSizeException, IOException, SenderClosedException; |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/udp/SOCKS5UDPRelayHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.udp;
/*
https://www.ietf.org/rfc/rfc1928.txt
+----+------+------+----------+----------+----------+
|RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
+----+------+------+----------+----------+----------+
| 2 | 1 | 1 | Variable | 2 | Variable |
+----+------+------+----------+----------+----------+
The fields in the UDP request header are:
o RSV Reserved X'0000'
o FRAG Current fragment number
o ATYP address type of following addresses:
o IP V4 address: X'01'
o DOMAINNAME: X'03'
o IP V6 address: X'04'
o DST.ADDR desired destination address
o DST.PORT desired destination port
o DATA user data
*/
public class SOCKS5UDPRelayHeader {
private AddressType type;
private byte[] addr;
private int port;
private byte[] payload;
public SOCKS5UDPRelayHeader(final AddressType type, final byte[] addr, final int port, final byte[] payload) {
this.type = type;
this.addr = addr;
this.port = port;
this.payload = payload;
}
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/udp/SOCKS5UDPRelayHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.udp;
/*
https://www.ietf.org/rfc/rfc1928.txt
+----+------+------+----------+----------+----------+
|RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
+----+------+------+----------+----------+----------+
| 2 | 1 | 1 | Variable | 2 | Variable |
+----+------+------+----------+----------+----------+
The fields in the UDP request header are:
o RSV Reserved X'0000'
o FRAG Current fragment number
o ATYP address type of following addresses:
o IP V4 address: X'01'
o DOMAINNAME: X'03'
o IP V6 address: X'04'
o DST.ADDR desired destination address
o DST.PORT desired destination port
o DATA user data
*/
public class SOCKS5UDPRelayHeader {
private AddressType type;
private byte[] addr;
private int port;
private byte[] payload;
public SOCKS5UDPRelayHeader(final AddressType type, final byte[] addr, final int port, final byte[] payload) {
this.type = type;
this.addr = addr;
this.port = port;
this.payload = payload;
}
| public SOCKS5UDPRelayHeader(final byte[] header) throws IncorrectHeaderException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/udp/SOCKS5UDPRelayHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | this.type = type;
}
public byte[] getAddr() {
return addr;
}
public void setAddr(final byte[] addr) {
this.addr = addr;
}
public int getPort() {
return port;
}
public void setPort(final int port) {
this.port = port;
}
public byte[] getPayload() {
return payload;
}
public void setPayload(final byte[] payload) {
this.payload = payload;
}
public byte[] toBytes() {
final int addrTotalLength = (type == AddressType.IPv4 ? 4 : (type == AddressType.IPv6 ? 16 : 1 + addr.length));
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/AddressType.java
// public enum AddressType {
// IPv4((byte) 0),
// IPv6((byte) 1),
// DOMAIN((byte) 2);
//
// private final byte value;
//
// AddressType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final AddressType[] types = AddressType.values();
//
// public static AddressType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/udp/SOCKS5UDPRelayHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.header.AddressType;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
this.type = type;
}
public byte[] getAddr() {
return addr;
}
public void setAddr(final byte[] addr) {
this.addr = addr;
}
public int getPort() {
return port;
}
public void setPort(final int port) {
this.port = port;
}
public byte[] getPayload() {
return payload;
}
public void setPayload(final byte[] payload) {
this.payload = payload;
}
public byte[] toBytes() {
final int addrTotalLength = (type == AddressType.IPv4 ? 4 : (type == AddressType.IPv6 ? 16 : 1 + addr.length));
| final BinaryWriter writer = new BinaryWriter(6 + addrTotalLength + payload.length); |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/ContinueConnectionFrame.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class ContinueConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/ContinueConnectionFrame.java
import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class ContinueConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| private static final FrameType TYPE = FrameType.CONTINUE; |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
| import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class DragoniteServerSocket extends DragoniteSocket {
private final ReceiveHandler receiver;
private final ResendHandler resender; //THREAD
private final SendHandler sender;
private final BucketPacketSender bucketPacketSender;
private final ACKSender ackSender; //THREAD
private final SocketAddress remoteAddress;
private final DragoniteServer dragoniteServer;
private volatile boolean alive = true;
private volatile long lastReceiveTime, lastSendTime;
private final ConnectionState state = new ConnectionState();
private final Object closeLock = new Object();
private volatile String description;
public DragoniteServerSocket(final SocketAddress remoteAddress, final long sendSpeed, final DragoniteServer dragoniteServer) {
this.remoteAddress = remoteAddress;
this.dragoniteServer = dragoniteServer;
updateLastReceiveTime();
bucketPacketSender = new BucketPacketSender(bytes -> {
dragoniteServer.sendPacket(bytes, remoteAddress);
updateLastSendTime();
}, sendSpeed);
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java
import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class DragoniteServerSocket extends DragoniteSocket {
private final ReceiveHandler receiver;
private final ResendHandler resender; //THREAD
private final SendHandler sender;
private final BucketPacketSender bucketPacketSender;
private final ACKSender ackSender; //THREAD
private final SocketAddress remoteAddress;
private final DragoniteServer dragoniteServer;
private volatile boolean alive = true;
private volatile long lastReceiveTime, lastSendTime;
private final ConnectionState state = new ConnectionState();
private final Object closeLock = new Object();
private volatile String description;
public DragoniteServerSocket(final SocketAddress remoteAddress, final long sendSpeed, final DragoniteServer dragoniteServer) {
this.remoteAddress = remoteAddress;
this.dragoniteServer = dragoniteServer;
updateLastReceiveTime();
bucketPacketSender = new BucketPacketSender(bytes -> {
dragoniteServer.sendPacket(bytes, remoteAddress);
updateLastSendTime();
}, sendSpeed);
| ackSender = new ACKSender(this, bucketPacketSender, DragoniteGlobalConstants.ACK_INTERVAL_MS, dragoniteServer.getPacketSize()); |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
| import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class DragoniteServerSocket extends DragoniteSocket {
private final ReceiveHandler receiver;
private final ResendHandler resender; //THREAD
private final SendHandler sender;
private final BucketPacketSender bucketPacketSender;
private final ACKSender ackSender; //THREAD
private final SocketAddress remoteAddress;
private final DragoniteServer dragoniteServer;
private volatile boolean alive = true;
private volatile long lastReceiveTime, lastSendTime;
private final ConnectionState state = new ConnectionState();
private final Object closeLock = new Object();
private volatile String description;
public DragoniteServerSocket(final SocketAddress remoteAddress, final long sendSpeed, final DragoniteServer dragoniteServer) {
this.remoteAddress = remoteAddress;
this.dragoniteServer = dragoniteServer;
updateLastReceiveTime();
bucketPacketSender = new BucketPacketSender(bytes -> {
dragoniteServer.sendPacket(bytes, remoteAddress);
updateLastSendTime();
}, sendSpeed);
ackSender = new ACKSender(this, bucketPacketSender, DragoniteGlobalConstants.ACK_INTERVAL_MS, dragoniteServer.getPacketSize());
resender = new ResendHandler(this, bucketPacketSender, state, dragoniteServer.getResendMinDelayMS(), DragoniteGlobalConstants.ACK_INTERVAL_MS);
receiver = new ReceiveHandler(this, ackSender, state, dragoniteServer.getWindowMultiplier(),
resender, dragoniteServer.getPacketSize());
sender = new SendHandler(this, bucketPacketSender, receiver, state, resender, dragoniteServer.getPacketSize());
description = "DSSocket";
}
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java
import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.sdk.socket;
public class DragoniteServerSocket extends DragoniteSocket {
private final ReceiveHandler receiver;
private final ResendHandler resender; //THREAD
private final SendHandler sender;
private final BucketPacketSender bucketPacketSender;
private final ACKSender ackSender; //THREAD
private final SocketAddress remoteAddress;
private final DragoniteServer dragoniteServer;
private volatile boolean alive = true;
private volatile long lastReceiveTime, lastSendTime;
private final ConnectionState state = new ConnectionState();
private final Object closeLock = new Object();
private volatile String description;
public DragoniteServerSocket(final SocketAddress remoteAddress, final long sendSpeed, final DragoniteServer dragoniteServer) {
this.remoteAddress = remoteAddress;
this.dragoniteServer = dragoniteServer;
updateLastReceiveTime();
bucketPacketSender = new BucketPacketSender(bytes -> {
dragoniteServer.sendPacket(bytes, remoteAddress);
updateLastSendTime();
}, sendSpeed);
ackSender = new ACKSender(this, bucketPacketSender, DragoniteGlobalConstants.ACK_INTERVAL_MS, dragoniteServer.getPacketSize());
resender = new ResendHandler(this, bucketPacketSender, state, dragoniteServer.getResendMinDelayMS(), DragoniteGlobalConstants.ACK_INTERVAL_MS);
receiver = new ReceiveHandler(this, ackSender, state, dragoniteServer.getWindowMultiplier(),
resender, dragoniteServer.getPacketSize());
sender = new SendHandler(this, bucketPacketSender, receiver, state, resender, dragoniteServer.getPacketSize());
description = "DSSocket";
}
| protected void onHandleMessage(final Message message, final int pktLength) { |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
| import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress; | sender = new SendHandler(this, bucketPacketSender, receiver, state, resender, dragoniteServer.getPacketSize());
description = "DSSocket";
}
protected void onHandleMessage(final Message message, final int pktLength) {
receiver.onHandleMessage(message, pktLength);
}
@Override
protected void updateLastReceiveTime() {
lastReceiveTime = System.currentTimeMillis();
}
@Override
public long getLastReceiveTime() {
return lastReceiveTime;
}
@Override
protected void updateLastSendTime() {
lastSendTime = System.currentTimeMillis();
}
@Override
public long getLastSendTime() {
return lastSendTime;
}
| // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java
import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress;
sender = new SendHandler(this, bucketPacketSender, receiver, state, resender, dragoniteServer.getPacketSize());
description = "DSSocket";
}
protected void onHandleMessage(final Message message, final int pktLength) {
receiver.onHandleMessage(message, pktLength);
}
@Override
protected void updateLastReceiveTime() {
lastReceiveTime = System.currentTimeMillis();
}
@Override
public long getLastReceiveTime() {
return lastReceiveTime;
}
@Override
protected void updateLastSendTime() {
lastSendTime = System.currentTimeMillis();
}
@Override
public long getLastSendTime() {
return lastSendTime;
}
| protected void sendHeartbeat() throws InterruptedException, IOException, SenderClosedException { |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
| import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress; |
protected void onHandleMessage(final Message message, final int pktLength) {
receiver.onHandleMessage(message, pktLength);
}
@Override
protected void updateLastReceiveTime() {
lastReceiveTime = System.currentTimeMillis();
}
@Override
public long getLastReceiveTime() {
return lastReceiveTime;
}
@Override
protected void updateLastSendTime() {
lastSendTime = System.currentTimeMillis();
}
@Override
public long getLastSendTime() {
return lastSendTime;
}
protected void sendHeartbeat() throws InterruptedException, IOException, SenderClosedException {
sender.sendHeartbeatMessage();
}
@Override | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java
import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress;
protected void onHandleMessage(final Message message, final int pktLength) {
receiver.onHandleMessage(message, pktLength);
}
@Override
protected void updateLastReceiveTime() {
lastReceiveTime = System.currentTimeMillis();
}
@Override
public long getLastReceiveTime() {
return lastReceiveTime;
}
@Override
protected void updateLastSendTime() {
lastSendTime = System.currentTimeMillis();
}
@Override
public long getLastSendTime() {
return lastSendTime;
}
protected void sendHeartbeat() throws InterruptedException, IOException, SenderClosedException {
sender.sendHeartbeatMessage();
}
@Override | public byte[] read() throws InterruptedException, ConnectionNotAliveException { |
dragonite-network/dragonite-java | dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
| import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress; | @Override
protected void updateLastReceiveTime() {
lastReceiveTime = System.currentTimeMillis();
}
@Override
public long getLastReceiveTime() {
return lastReceiveTime;
}
@Override
protected void updateLastSendTime() {
lastSendTime = System.currentTimeMillis();
}
@Override
public long getLastSendTime() {
return lastSendTime;
}
protected void sendHeartbeat() throws InterruptedException, IOException, SenderClosedException {
sender.sendHeartbeatMessage();
}
@Override
public byte[] read() throws InterruptedException, ConnectionNotAliveException {
return receiver.read();
}
@Override | // Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/ConnectionNotAliveException.java
// public class ConnectionNotAliveException extends DragoniteException {
//
// public ConnectionNotAliveException() {
// super("Connection is not alive");
// }
//
// public ConnectionNotAliveException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/IncorrectSizeException.java
// public class IncorrectSizeException extends DragoniteException {
//
// public IncorrectSizeException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/exception/SenderClosedException.java
// public class SenderClosedException extends DragoniteException {
//
// public SenderClosedException() {
// super("Sender closed");
// }
//
// public SenderClosedException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
//
// public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int MIN_SEND_WINDOW_SIZE = 20;
//
// public static final int ACK_INTERVAL_MS = 10;
//
// public static final int MAX_FAST_RESEND_COUNT = 3;
//
// public static final int MAX_SLOW_RESEND_MULT = 4;
//
// public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
//
// public static final int DEV_RTT_MULT = 4;
//
// public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
//
// public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
//
// public static final int WEB_PANEL_PORT = 8000;
//
// }
//
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/Message.java
// public interface Message {
//
// byte getVersion();
//
// MessageType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// }
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/DragoniteServerSocket.java
import com.vecsight.dragonite.sdk.exception.ConnectionNotAliveException;
import com.vecsight.dragonite.sdk.exception.IncorrectSizeException;
import com.vecsight.dragonite.sdk.exception.SenderClosedException;
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.msg.Message;
import java.io.IOException;
import java.net.SocketAddress;
@Override
protected void updateLastReceiveTime() {
lastReceiveTime = System.currentTimeMillis();
}
@Override
public long getLastReceiveTime() {
return lastReceiveTime;
}
@Override
protected void updateLastSendTime() {
lastSendTime = System.currentTimeMillis();
}
@Override
public long getLastSendTime() {
return lastSendTime;
}
protected void sendHeartbeat() throws InterruptedException, IOException, SenderClosedException {
sender.sendHeartbeatMessage();
}
@Override
public byte[] read() throws InterruptedException, ConnectionNotAliveException {
return receiver.read();
}
@Override | public void send(final byte[] bytes) throws InterruptedException, IncorrectSizeException, IOException, SenderClosedException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/mux/MuxConnectionResponseHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.mux;
/*
* status 1 SB
* udp port 2 US
* msgLen 1 UB
* msg [length]
*/
public class MuxConnectionResponseHeader {
private ConnectionStatus status;
private int udpPort;
private String msg;
public MuxConnectionResponseHeader(final ConnectionStatus status, final int udpPort, final String msg) {
this.status = status;
this.udpPort = udpPort;
this.msg = msg;
}
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/mux/MuxConnectionResponseHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.mux;
/*
* status 1 SB
* udp port 2 US
* msgLen 1 UB
* msg [length]
*/
public class MuxConnectionResponseHeader {
private ConnectionStatus status;
private int udpPort;
private String msg;
public MuxConnectionResponseHeader(final ConnectionStatus status, final int udpPort, final String msg) {
this.status = status;
this.udpPort = udpPort;
this.msg = msg;
}
| public MuxConnectionResponseHeader(final byte[] header) throws IncorrectHeaderException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/mux/MuxConnectionResponseHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.mux;
/*
* status 1 SB
* udp port 2 US
* msgLen 1 UB
* msg [length]
*/
public class MuxConnectionResponseHeader {
private ConnectionStatus status;
private int udpPort;
private String msg;
public MuxConnectionResponseHeader(final ConnectionStatus status, final int udpPort, final String msg) {
this.status = status;
this.udpPort = udpPort;
this.msg = msg;
}
public MuxConnectionResponseHeader(final byte[] header) throws IncorrectHeaderException { | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/mux/MuxConnectionResponseHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header.mux;
/*
* status 1 SB
* udp port 2 US
* msgLen 1 UB
* msg [length]
*/
public class MuxConnectionResponseHeader {
private ConnectionStatus status;
private int udpPort;
private String msg;
public MuxConnectionResponseHeader(final ConnectionStatus status, final int udpPort, final String msg) {
this.status = status;
this.udpPort = udpPort;
this.msg = msg;
}
public MuxConnectionResponseHeader(final byte[] header) throws IncorrectHeaderException { | final BinaryReader reader = new BinaryReader(header); |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/mux/MuxConnectionResponseHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; |
}
public ConnectionStatus getStatus() {
return status;
}
public void setStatus(final ConnectionStatus status) {
this.status = status;
}
public int getUdpPort() {
return udpPort;
}
public void setUdpPort(final int udpPort) {
this.udpPort = udpPort;
}
public String getMsg() {
return msg;
}
public void setMsg(final String msg) {
this.msg = msg;
}
public byte[] toBytes() {
final byte[] msgBytes = msg.getBytes(ProxyGlobalConstants.STRING_CHARSET);
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/mux/MuxConnectionResponseHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
}
public ConnectionStatus getStatus() {
return status;
}
public void setStatus(final ConnectionStatus status) {
this.status = status;
}
public int getUdpPort() {
return udpPort;
}
public void setUdpPort(final int udpPort) {
this.udpPort = udpPort;
}
public String getMsg() {
return msg;
}
public void setMsg(final String msg) {
this.msg = msg;
}
public byte[] toBytes() {
final byte[] msgBytes = msg.getBytes(ProxyGlobalConstants.STRING_CHARSET);
| final BinaryWriter writer = new BinaryWriter(4 + msgBytes.length); |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ParsedACL.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/ACLItem.java
// public interface ACLItem {
//
// ACLItemType getType();
//
// ACLItemMethod getMethod();
//
// boolean match(final byte[] address);
//
// //DO NOT resolve and match with hostname's IPs!!! Just return false if it's an IP address item
// boolean match(final String domain);
//
// }
| import com.vecsight.dragonite.proxy.acl.item.ACLItem;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl;
public class ParsedACL {
private final String title;
private final String author;
private final ACLItemMethod defaultMethod;
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/item/ACLItem.java
// public interface ACLItem {
//
// ACLItemType getType();
//
// ACLItemMethod getMethod();
//
// boolean match(final byte[] address);
//
// //DO NOT resolve and match with hostname's IPs!!! Just return false if it's an IP address item
// boolean match(final String domain);
//
// }
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/acl/ParsedACL.java
import com.vecsight.dragonite.proxy.acl.item.ACLItem;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.acl;
public class ParsedACL {
private final String title;
private final String author;
private final ACLItemMethod defaultMethod;
| private final List<ACLItem> items; |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
| import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.types.*; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame;
public class FrameParser {
private final FrameBuffer frameBuffer;
private boolean needMore = false;
private int expectedLength = 0;
public FrameParser(final int maxFrameSize) {
frameBuffer = new FrameBuffer(maxFrameSize);
}
public Frame feed(final byte[] rawBytes) {
frameBuffer.add(rawBytes);
if (!needMore || frameBuffer.getSize() >= expectedLength) {
try {
final Frame frame = parseFrameRaw(frameBuffer.get());
if (frame.getExpectedLength() == 0) {
frameBuffer.reset();
needMore = false;
return frame;
} else {
expectedLength = frame.getExpectedLength();
needMore = true;
} | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// private static final FrameType[] types = FrameType.values();
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameParser.java
import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.types.*;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame;
public class FrameParser {
private final FrameBuffer frameBuffer;
private boolean needMore = false;
private int expectedLength = 0;
public FrameParser(final int maxFrameSize) {
frameBuffer = new FrameBuffer(maxFrameSize);
}
public Frame feed(final byte[] rawBytes) {
frameBuffer.add(rawBytes);
if (!needMore || frameBuffer.getSize() >= expectedLength) {
try {
final Frame frame = parseFrameRaw(frameBuffer.get());
if (frame.getExpectedLength() == 0) {
frameBuffer.reset();
needMore = false;
return frame;
} else {
expectedLength = frame.getExpectedLength();
needMore = true;
} | } catch (final IncorrectFrameException e) { |
dragonite-network/dragonite-java | dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/CloseConnectionFrame.java | // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class CloseConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| // Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/exception/IncorrectFrameException.java
// public class IncorrectFrameException extends MuxException {
//
// public IncorrectFrameException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/Frame.java
// public interface Frame {
//
// byte getVersion();
//
// FrameType getType();
//
// byte[] toBytes();
//
// int getFixedLength();
//
// int getExpectedLength();
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/frame/FrameType.java
// public enum FrameType {
// CREATE((byte) 0),
// DATA((byte) 1),
// CLOSE((byte) 2),
// PAUSE((byte) 3),
// CONTINUE((byte) 4);
//
// private final byte value;
//
// FrameType(final byte value) {
// this.value = value;
// }
//
// public byte getValue() {
// return value;
// }
//
// private static final FrameType[] types = FrameType.values();
//
// public static FrameType fromByte(final byte type) {
// try {
// return types[type];
// } catch (final ArrayIndexOutOfBoundsException e) {
// throw new IllegalArgumentException("Type byte " + type + " not found");
// }
// }
//
// }
//
// Path: dragonite-mux/src/main/java/com/vecsight/dragonite/mux/misc/MuxGlobalConstants.java
// public final class MuxGlobalConstants {
//
// public static final String LIBRARY_VERSION = MuxBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int CONNECTION_MAX_DATA_BUFFER_SIZE = 1048576; //1M
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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-mux/src/main/java/com/vecsight/dragonite/mux/frame/types/CloseConnectionFrame.java
import com.vecsight.dragonite.mux.exception.IncorrectFrameException;
import com.vecsight.dragonite.mux.frame.Frame;
import com.vecsight.dragonite.mux.frame.FrameType;
import com.vecsight.dragonite.mux.misc.MuxGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.mux.frame.types;
/*
* VERSION 1 SB
* TYPE 1 SB
* connID 2 SS
*/
public class CloseConnectionFrame implements Frame {
private static final byte VERSION = MuxGlobalConstants.PROTOCOL_VERSION;
| private static final FrameType TYPE = FrameType.CLOSE; |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/ClientInfoHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; | /*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header;
/*
* VERSION 1 SB
* downMbps 2 US
* upMbps 2 US
* nameLen 1 UB
* nameStr [length]
* verLen 1 UB
* verStr [length]
* osLen 1 UB
* osStr [length]
*/
public class ClientInfoHeader {
private static final byte VERSION = ProxyGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 8;
private int downMbps, upMbps;
private String name, appVer, osName;
public ClientInfoHeader(final int downMbps, final int upMbps, final String name, final String appVer, final String osName) {
this.downMbps = downMbps;
this.upMbps = upMbps;
this.name = name;
this.appVer = appVer;
this.osName = osName;
}
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/ClientInfoHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
/*
* The Dragonite Project
* -------------------------
* See the LICENSE file in the root directory for license information.
*/
package com.vecsight.dragonite.proxy.header;
/*
* VERSION 1 SB
* downMbps 2 US
* upMbps 2 US
* nameLen 1 UB
* nameStr [length]
* verLen 1 UB
* verStr [length]
* osLen 1 UB
* osStr [length]
*/
public class ClientInfoHeader {
private static final byte VERSION = ProxyGlobalConstants.PROTOCOL_VERSION;
public static final int FIXED_LENGTH = 8;
private int downMbps, upMbps;
private String name, appVer, osName;
public ClientInfoHeader(final int downMbps, final int upMbps, final String name, final String appVer, final String osName) {
this.downMbps = downMbps;
this.upMbps = upMbps;
this.name = name;
this.appVer = appVer;
this.osName = osName;
}
| public ClientInfoHeader(final byte[] header) throws IncorrectHeaderException { |
dragonite-network/dragonite-java | dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/header/ClientInfoHeader.java | // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException; |
public String getAppVer() {
return appVer;
}
public void setAppVer(final String appVer) {
this.appVer = appVer;
}
public String getOsName() {
return osName;
}
public void setOsName(final String osName) {
this.osName = osName;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] nameBytes = name.getBytes(ProxyGlobalConstants.STRING_CHARSET);
final byte[] appVerBytes = appVer.getBytes(ProxyGlobalConstants.STRING_CHARSET);
final byte[] osNameBytes = osName.getBytes(ProxyGlobalConstants.STRING_CHARSET);
| // Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/exception/IncorrectHeaderException.java
// public class IncorrectHeaderException extends Exception {
//
// public IncorrectHeaderException(final String msg) {
// super(msg);
// }
//
// }
//
// Path: dragonite-proxy/src/main/java/com/vecsight/dragonite/proxy/misc/ProxyGlobalConstants.java
// public final class ProxyGlobalConstants {
//
// public static final String APP_VERSION = ProxyBuildConfig.VERSION;
//
// public static final byte PROTOCOL_VERSION = 2;
//
// public static final int DEFAULT_SERVER_PORT = 5234;
//
// public static final long INIT_SEND_SPEED = 100 * 1024; //100kb/s
//
// public static final Charset STRING_CHARSET = StandardCharsets.UTF_8;
//
// public static final Charset HEADER_ADDRESS_CHARSET = StandardCharsets.US_ASCII;
//
// public static final short PIPE_BUFFER_SIZE = 10240;
//
// public static final short MAX_FRAME_SIZE = 20480;
//
// public static final int PASSWORD_MIN_LENGTH = 4;
//
// public static final int SOCKS5_PORT = 1080;
//
// public static final int TCP_CONNECT_TIMEOUT_MS = 4000;
//
// public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";
//
// public static final String UPDATE_API_PRODUCT_NAME = "proxy";
//
// }
//
// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/binary/BinaryReader.java
// public class BinaryReader {
//
// private final ByteBuffer byteBuffer;
//
// public BinaryReader(final byte[] bytes) {
// byteBuffer = ByteBuffer.wrap(bytes);
// }
//
// public byte getSignedByte() {
// return byteBuffer.get();
// }
//
// public short getUnsignedByte() {
// return (short) (byteBuffer.get() & (short) 0xff);
// }
//
// public short getSignedShort() {
// return byteBuffer.getShort();
// }
//
// public int getUnsignedShort() {
// return byteBuffer.getShort() & 0xffff;
// }
//
// public int getSignedInt() {
// return byteBuffer.getInt();
// }
//
// public long getUnsignedInt() {
// return (long) byteBuffer.getInt() & 0xffffffffL;
// }
//
// public void getBytes(final byte[] bytes) {
// byteBuffer.get(bytes);
// }
//
// public byte[] getBytesGroupWithByteLength() {
// final short len = getUnsignedByte();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public byte[] getBytesGroupWithShortLength() {
// final int len = getUnsignedShort();
// final byte[] bytes = new byte[len];
// byteBuffer.get(bytes);
// return bytes;
// }
//
// public boolean getBoolean() {
// return byteBuffer.get() != 0;
// }
//
// public int remaining() {
// return byteBuffer.remaining();
// }
//
// }
//
// 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/header/ClientInfoHeader.java
import com.vecsight.dragonite.proxy.exception.IncorrectHeaderException;
import com.vecsight.dragonite.proxy.misc.ProxyGlobalConstants;
import com.vecsight.dragonite.utils.binary.BinaryReader;
import com.vecsight.dragonite.utils.binary.BinaryWriter;
import java.nio.BufferUnderflowException;
public String getAppVer() {
return appVer;
}
public void setAppVer(final String appVer) {
this.appVer = appVer;
}
public String getOsName() {
return osName;
}
public void setOsName(final String osName) {
this.osName = osName;
}
public static byte getVersion() {
return VERSION;
}
public static int getFixedLength() {
return FIXED_LENGTH;
}
public byte[] toBytes() {
final byte[] nameBytes = name.getBytes(ProxyGlobalConstants.STRING_CHARSET);
final byte[] appVerBytes = appVer.getBytes(ProxyGlobalConstants.STRING_CHARSET);
final byte[] osNameBytes = osName.getBytes(ProxyGlobalConstants.STRING_CHARSET);
| final BinaryWriter writer = new BinaryWriter(getFixedLength() + nameBytes.length + appVerBytes.length + osNameBytes.length); |
denis-zhdanov/traute | core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettingsBuilder.java | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType;
import java.io.File;
import java.util.*;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton; | "javax.annotation.CheckForNull",
// JavaEE - https://docs.oracle.com/javaee/7/api/javax/validation/constraints/Null.html
"javax.validation.constraints.Null",
// FindBugs - http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/Nullable.html
"edu.umd.cs.findbugs.annotations.Nullable",
// FindBugs - http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/CheckForNull.html
"edu.umd.cs.findbugs.annotations.CheckForNull",
// Android - https://developer.android.com/reference/android/support/annotation/Nullable.html
"android.support.annotation.Nullable",
// Eclipse - http://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_null_annotations.htm
"org.eclipse.jdt.annotation.Nullable",
// Spring - https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/lang/Nullable.html
"org.springframework.lang.Nullable",
// Checker - https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/Nullable.html
"org.checkerframework.checker.nullness.qual.Nullable",
// Checker - https://checkerframework.org/api/org/checkerframework/checker/nullness/compatqual/NullableDecl.html
"org.checkerframework.checker.nullness.compatqual.NullableDecl",
// Checker - https://checkerframework.org/api/org/checkerframework/checker/nullness/compatqual/NullableType.html
"org.checkerframework.checker.nullness.compatqual.NullableType"
));
| // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettingsBuilder.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType;
import java.io.File;
import java.util.*;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
"javax.annotation.CheckForNull",
// JavaEE - https://docs.oracle.com/javaee/7/api/javax/validation/constraints/Null.html
"javax.validation.constraints.Null",
// FindBugs - http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/Nullable.html
"edu.umd.cs.findbugs.annotations.Nullable",
// FindBugs - http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/CheckForNull.html
"edu.umd.cs.findbugs.annotations.CheckForNull",
// Android - https://developer.android.com/reference/android/support/annotation/Nullable.html
"android.support.annotation.Nullable",
// Eclipse - http://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_null_annotations.htm
"org.eclipse.jdt.annotation.Nullable",
// Spring - https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/lang/Nullable.html
"org.springframework.lang.Nullable",
// Checker - https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/Nullable.html
"org.checkerframework.checker.nullness.qual.Nullable",
// Checker - https://checkerframework.org/api/org/checkerframework/checker/nullness/compatqual/NullableDecl.html
"org.checkerframework.checker.nullness.compatqual.NullableDecl",
// Checker - https://checkerframework.org/api/org/checkerframework/checker/nullness/compatqual/NullableType.html
"org.checkerframework.checker.nullness.compatqual.NullableType"
));
| public static final Set<InstrumentationType> DEFAULT_INSTRUMENTATIONS_TO_APPLY = |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java
// public class TrautePluginSettings {
//
// public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
//
// private final Set<String> notNullAnnotations = new HashSet<>();
// private final Set<String> nullableAnnotations = new HashSet<>();
// private final Set<InstrumentationType> instrumentationsToApply = new HashSet<>();
// private final Map<InstrumentationType, String> exceptionsToThrow = new HashMap<>();
// private final Map<InstrumentationType, String> exceptionTextPatterns = new HashMap<>();
// private final Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations = new HashMap<>();
//
// @Nullable private final File logFile;
//
// private final boolean verboseMode;
//
// public TrautePluginSettings(@NotNull Set<String> notNullAnnotations,
// @NotNull Set<String> nullableAnnotations,
// @NotNull Set<InstrumentationType> instrumentationsToApply,
// @NotNull Map<InstrumentationType, String> exceptionsToThrow,
// @NotNull Map<InstrumentationType, String> exceptionTextPatterns,
// @NotNull Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations,
// @Nullable File logFile,
// boolean verboseMode)
// {
// this.logFile = logFile;
// this.notNullAnnotations.addAll(notNullAnnotations);
// this.nullableAnnotations.addAll(nullableAnnotations);
// this.instrumentationsToApply.addAll(instrumentationsToApply);
// this.exceptionsToThrow.putAll(exceptionsToThrow);
// this.exceptionTextPatterns.putAll(exceptionTextPatterns);
// this.notNullByDefaultAnnotations.putAll(notNullByDefaultAnnotations);
// this.verboseMode = verboseMode;
// }
//
// @NotNull
// public Set<String> getNotNullAnnotations() {
// return notNullAnnotations;
// }
//
// @NotNull
// public Set<String> getNullableAnnotations() {
// return nullableAnnotations;
// }
//
// public boolean isEnabled(@NotNull InstrumentationType type) {
// return instrumentationsToApply.contains(type);
// }
//
// @NotNull
// public Set<InstrumentationType> getInstrumentationsToApply() {
// return instrumentationsToApply;
// }
//
// @NotNull
// public String getExceptionToThrow(@NotNull InstrumentationType type) {
// return exceptionsToThrow.getOrDefault(type, DEFAULT_EXCEPTION_TO_THROW);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionsToThrow() {
// return exceptionsToThrow;
// }
//
// @Nullable
// public String getExceptionTextPattern(@NotNull InstrumentationType type) {
// return exceptionTextPatterns.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionTextPatterns() {
// return exceptionTextPatterns;
// }
//
// @NotNull
// public Set<String> getNotNullByDefaultAnnotations(@NotNull InstrumentationType type) {
// return notNullByDefaultAnnotations.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, Set<String>> getNotNullByDefaultAnnotations() {
// return notNullByDefaultAnnotations;
// }
//
// @NotNull
// public Optional<File> getLogFile() {
// return Optional.ofNullable(logFile);
// }
//
// public boolean isVerboseMode() {
// return verboseMode;
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.common.settings.TrautePluginSettings;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import java.util.Collection; | package tech.harmonysoft.oss.traute.test.api.engine;
/**
* Defines an interface for a service which knows how to produce a {@link CompilationResult} from a {@link TestSource}.
*/
public interface TestCompiler {
/**
* Produces a {@link CompilationResult} from the given {@link TestSource}
*
* @param testSources test sources to compile
* @param settings plugin settings to use
* @return compilation result
*/
@NotNull | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java
// public class TrautePluginSettings {
//
// public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
//
// private final Set<String> notNullAnnotations = new HashSet<>();
// private final Set<String> nullableAnnotations = new HashSet<>();
// private final Set<InstrumentationType> instrumentationsToApply = new HashSet<>();
// private final Map<InstrumentationType, String> exceptionsToThrow = new HashMap<>();
// private final Map<InstrumentationType, String> exceptionTextPatterns = new HashMap<>();
// private final Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations = new HashMap<>();
//
// @Nullable private final File logFile;
//
// private final boolean verboseMode;
//
// public TrautePluginSettings(@NotNull Set<String> notNullAnnotations,
// @NotNull Set<String> nullableAnnotations,
// @NotNull Set<InstrumentationType> instrumentationsToApply,
// @NotNull Map<InstrumentationType, String> exceptionsToThrow,
// @NotNull Map<InstrumentationType, String> exceptionTextPatterns,
// @NotNull Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations,
// @Nullable File logFile,
// boolean verboseMode)
// {
// this.logFile = logFile;
// this.notNullAnnotations.addAll(notNullAnnotations);
// this.nullableAnnotations.addAll(nullableAnnotations);
// this.instrumentationsToApply.addAll(instrumentationsToApply);
// this.exceptionsToThrow.putAll(exceptionsToThrow);
// this.exceptionTextPatterns.putAll(exceptionTextPatterns);
// this.notNullByDefaultAnnotations.putAll(notNullByDefaultAnnotations);
// this.verboseMode = verboseMode;
// }
//
// @NotNull
// public Set<String> getNotNullAnnotations() {
// return notNullAnnotations;
// }
//
// @NotNull
// public Set<String> getNullableAnnotations() {
// return nullableAnnotations;
// }
//
// public boolean isEnabled(@NotNull InstrumentationType type) {
// return instrumentationsToApply.contains(type);
// }
//
// @NotNull
// public Set<InstrumentationType> getInstrumentationsToApply() {
// return instrumentationsToApply;
// }
//
// @NotNull
// public String getExceptionToThrow(@NotNull InstrumentationType type) {
// return exceptionsToThrow.getOrDefault(type, DEFAULT_EXCEPTION_TO_THROW);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionsToThrow() {
// return exceptionsToThrow;
// }
//
// @Nullable
// public String getExceptionTextPattern(@NotNull InstrumentationType type) {
// return exceptionTextPatterns.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionTextPatterns() {
// return exceptionTextPatterns;
// }
//
// @NotNull
// public Set<String> getNotNullByDefaultAnnotations(@NotNull InstrumentationType type) {
// return notNullByDefaultAnnotations.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, Set<String>> getNotNullByDefaultAnnotations() {
// return notNullByDefaultAnnotations;
// }
//
// @NotNull
// public Optional<File> getLogFile() {
// return Optional.ofNullable(logFile);
// }
//
// public boolean isVerboseMode() {
// return verboseMode;
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.common.settings.TrautePluginSettings;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import java.util.Collection;
package tech.harmonysoft.oss.traute.test.api.engine;
/**
* Defines an interface for a service which knows how to produce a {@link CompilationResult} from a {@link TestSource}.
*/
public interface TestCompiler {
/**
* Produces a {@link CompilationResult} from the given {@link TestSource}
*
* @param testSources test sources to compile
* @param settings plugin settings to use
* @return compilation result
*/
@NotNull | CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java
// public class TrautePluginSettings {
//
// public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
//
// private final Set<String> notNullAnnotations = new HashSet<>();
// private final Set<String> nullableAnnotations = new HashSet<>();
// private final Set<InstrumentationType> instrumentationsToApply = new HashSet<>();
// private final Map<InstrumentationType, String> exceptionsToThrow = new HashMap<>();
// private final Map<InstrumentationType, String> exceptionTextPatterns = new HashMap<>();
// private final Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations = new HashMap<>();
//
// @Nullable private final File logFile;
//
// private final boolean verboseMode;
//
// public TrautePluginSettings(@NotNull Set<String> notNullAnnotations,
// @NotNull Set<String> nullableAnnotations,
// @NotNull Set<InstrumentationType> instrumentationsToApply,
// @NotNull Map<InstrumentationType, String> exceptionsToThrow,
// @NotNull Map<InstrumentationType, String> exceptionTextPatterns,
// @NotNull Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations,
// @Nullable File logFile,
// boolean verboseMode)
// {
// this.logFile = logFile;
// this.notNullAnnotations.addAll(notNullAnnotations);
// this.nullableAnnotations.addAll(nullableAnnotations);
// this.instrumentationsToApply.addAll(instrumentationsToApply);
// this.exceptionsToThrow.putAll(exceptionsToThrow);
// this.exceptionTextPatterns.putAll(exceptionTextPatterns);
// this.notNullByDefaultAnnotations.putAll(notNullByDefaultAnnotations);
// this.verboseMode = verboseMode;
// }
//
// @NotNull
// public Set<String> getNotNullAnnotations() {
// return notNullAnnotations;
// }
//
// @NotNull
// public Set<String> getNullableAnnotations() {
// return nullableAnnotations;
// }
//
// public boolean isEnabled(@NotNull InstrumentationType type) {
// return instrumentationsToApply.contains(type);
// }
//
// @NotNull
// public Set<InstrumentationType> getInstrumentationsToApply() {
// return instrumentationsToApply;
// }
//
// @NotNull
// public String getExceptionToThrow(@NotNull InstrumentationType type) {
// return exceptionsToThrow.getOrDefault(type, DEFAULT_EXCEPTION_TO_THROW);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionsToThrow() {
// return exceptionsToThrow;
// }
//
// @Nullable
// public String getExceptionTextPattern(@NotNull InstrumentationType type) {
// return exceptionTextPatterns.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionTextPatterns() {
// return exceptionTextPatterns;
// }
//
// @NotNull
// public Set<String> getNotNullByDefaultAnnotations(@NotNull InstrumentationType type) {
// return notNullByDefaultAnnotations.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, Set<String>> getNotNullByDefaultAnnotations() {
// return notNullByDefaultAnnotations;
// }
//
// @NotNull
// public Optional<File> getLogFile() {
// return Optional.ofNullable(logFile);
// }
//
// public boolean isVerboseMode() {
// return verboseMode;
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.common.settings.TrautePluginSettings;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import java.util.Collection; | package tech.harmonysoft.oss.traute.test.api.engine;
/**
* Defines an interface for a service which knows how to produce a {@link CompilationResult} from a {@link TestSource}.
*/
public interface TestCompiler {
/**
* Produces a {@link CompilationResult} from the given {@link TestSource}
*
* @param testSources test sources to compile
* @param settings plugin settings to use
* @return compilation result
*/
@NotNull | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java
// public class TrautePluginSettings {
//
// public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
//
// private final Set<String> notNullAnnotations = new HashSet<>();
// private final Set<String> nullableAnnotations = new HashSet<>();
// private final Set<InstrumentationType> instrumentationsToApply = new HashSet<>();
// private final Map<InstrumentationType, String> exceptionsToThrow = new HashMap<>();
// private final Map<InstrumentationType, String> exceptionTextPatterns = new HashMap<>();
// private final Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations = new HashMap<>();
//
// @Nullable private final File logFile;
//
// private final boolean verboseMode;
//
// public TrautePluginSettings(@NotNull Set<String> notNullAnnotations,
// @NotNull Set<String> nullableAnnotations,
// @NotNull Set<InstrumentationType> instrumentationsToApply,
// @NotNull Map<InstrumentationType, String> exceptionsToThrow,
// @NotNull Map<InstrumentationType, String> exceptionTextPatterns,
// @NotNull Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations,
// @Nullable File logFile,
// boolean verboseMode)
// {
// this.logFile = logFile;
// this.notNullAnnotations.addAll(notNullAnnotations);
// this.nullableAnnotations.addAll(nullableAnnotations);
// this.instrumentationsToApply.addAll(instrumentationsToApply);
// this.exceptionsToThrow.putAll(exceptionsToThrow);
// this.exceptionTextPatterns.putAll(exceptionTextPatterns);
// this.notNullByDefaultAnnotations.putAll(notNullByDefaultAnnotations);
// this.verboseMode = verboseMode;
// }
//
// @NotNull
// public Set<String> getNotNullAnnotations() {
// return notNullAnnotations;
// }
//
// @NotNull
// public Set<String> getNullableAnnotations() {
// return nullableAnnotations;
// }
//
// public boolean isEnabled(@NotNull InstrumentationType type) {
// return instrumentationsToApply.contains(type);
// }
//
// @NotNull
// public Set<InstrumentationType> getInstrumentationsToApply() {
// return instrumentationsToApply;
// }
//
// @NotNull
// public String getExceptionToThrow(@NotNull InstrumentationType type) {
// return exceptionsToThrow.getOrDefault(type, DEFAULT_EXCEPTION_TO_THROW);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionsToThrow() {
// return exceptionsToThrow;
// }
//
// @Nullable
// public String getExceptionTextPattern(@NotNull InstrumentationType type) {
// return exceptionTextPatterns.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionTextPatterns() {
// return exceptionTextPatterns;
// }
//
// @NotNull
// public Set<String> getNotNullByDefaultAnnotations(@NotNull InstrumentationType type) {
// return notNullByDefaultAnnotations.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, Set<String>> getNotNullByDefaultAnnotations() {
// return notNullByDefaultAnnotations;
// }
//
// @NotNull
// public Optional<File> getLogFile() {
// return Optional.ofNullable(logFile);
// }
//
// public boolean isVerboseMode() {
// return verboseMode;
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.common.settings.TrautePluginSettings;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import java.util.Collection;
package tech.harmonysoft.oss.traute.test.api.engine;
/**
* Defines an interface for a service which knows how to produce a {@link CompilationResult} from a {@link TestSource}.
*/
public interface TestCompiler {
/**
* Produces a {@link CompilationResult} from the given {@link TestSource}
*
* @param testSources test sources to compile
* @param settings plugin settings to use
* @return compilation result
*/
@NotNull | CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java
// public class TrautePluginSettings {
//
// public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
//
// private final Set<String> notNullAnnotations = new HashSet<>();
// private final Set<String> nullableAnnotations = new HashSet<>();
// private final Set<InstrumentationType> instrumentationsToApply = new HashSet<>();
// private final Map<InstrumentationType, String> exceptionsToThrow = new HashMap<>();
// private final Map<InstrumentationType, String> exceptionTextPatterns = new HashMap<>();
// private final Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations = new HashMap<>();
//
// @Nullable private final File logFile;
//
// private final boolean verboseMode;
//
// public TrautePluginSettings(@NotNull Set<String> notNullAnnotations,
// @NotNull Set<String> nullableAnnotations,
// @NotNull Set<InstrumentationType> instrumentationsToApply,
// @NotNull Map<InstrumentationType, String> exceptionsToThrow,
// @NotNull Map<InstrumentationType, String> exceptionTextPatterns,
// @NotNull Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations,
// @Nullable File logFile,
// boolean verboseMode)
// {
// this.logFile = logFile;
// this.notNullAnnotations.addAll(notNullAnnotations);
// this.nullableAnnotations.addAll(nullableAnnotations);
// this.instrumentationsToApply.addAll(instrumentationsToApply);
// this.exceptionsToThrow.putAll(exceptionsToThrow);
// this.exceptionTextPatterns.putAll(exceptionTextPatterns);
// this.notNullByDefaultAnnotations.putAll(notNullByDefaultAnnotations);
// this.verboseMode = verboseMode;
// }
//
// @NotNull
// public Set<String> getNotNullAnnotations() {
// return notNullAnnotations;
// }
//
// @NotNull
// public Set<String> getNullableAnnotations() {
// return nullableAnnotations;
// }
//
// public boolean isEnabled(@NotNull InstrumentationType type) {
// return instrumentationsToApply.contains(type);
// }
//
// @NotNull
// public Set<InstrumentationType> getInstrumentationsToApply() {
// return instrumentationsToApply;
// }
//
// @NotNull
// public String getExceptionToThrow(@NotNull InstrumentationType type) {
// return exceptionsToThrow.getOrDefault(type, DEFAULT_EXCEPTION_TO_THROW);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionsToThrow() {
// return exceptionsToThrow;
// }
//
// @Nullable
// public String getExceptionTextPattern(@NotNull InstrumentationType type) {
// return exceptionTextPatterns.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionTextPatterns() {
// return exceptionTextPatterns;
// }
//
// @NotNull
// public Set<String> getNotNullByDefaultAnnotations(@NotNull InstrumentationType type) {
// return notNullByDefaultAnnotations.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, Set<String>> getNotNullByDefaultAnnotations() {
// return notNullByDefaultAnnotations;
// }
//
// @NotNull
// public Optional<File> getLogFile() {
// return Optional.ofNullable(logFile);
// }
//
// public boolean isVerboseMode() {
// return verboseMode;
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.common.settings.TrautePluginSettings;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import java.util.Collection; | package tech.harmonysoft.oss.traute.test.api.engine;
/**
* Defines an interface for a service which knows how to produce a {@link CompilationResult} from a {@link TestSource}.
*/
public interface TestCompiler {
/**
* Produces a {@link CompilationResult} from the given {@link TestSource}
*
* @param testSources test sources to compile
* @param settings plugin settings to use
* @return compilation result
*/
@NotNull | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java
// public class TrautePluginSettings {
//
// public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
//
// private final Set<String> notNullAnnotations = new HashSet<>();
// private final Set<String> nullableAnnotations = new HashSet<>();
// private final Set<InstrumentationType> instrumentationsToApply = new HashSet<>();
// private final Map<InstrumentationType, String> exceptionsToThrow = new HashMap<>();
// private final Map<InstrumentationType, String> exceptionTextPatterns = new HashMap<>();
// private final Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations = new HashMap<>();
//
// @Nullable private final File logFile;
//
// private final boolean verboseMode;
//
// public TrautePluginSettings(@NotNull Set<String> notNullAnnotations,
// @NotNull Set<String> nullableAnnotations,
// @NotNull Set<InstrumentationType> instrumentationsToApply,
// @NotNull Map<InstrumentationType, String> exceptionsToThrow,
// @NotNull Map<InstrumentationType, String> exceptionTextPatterns,
// @NotNull Map<InstrumentationType, Set<String>> notNullByDefaultAnnotations,
// @Nullable File logFile,
// boolean verboseMode)
// {
// this.logFile = logFile;
// this.notNullAnnotations.addAll(notNullAnnotations);
// this.nullableAnnotations.addAll(nullableAnnotations);
// this.instrumentationsToApply.addAll(instrumentationsToApply);
// this.exceptionsToThrow.putAll(exceptionsToThrow);
// this.exceptionTextPatterns.putAll(exceptionTextPatterns);
// this.notNullByDefaultAnnotations.putAll(notNullByDefaultAnnotations);
// this.verboseMode = verboseMode;
// }
//
// @NotNull
// public Set<String> getNotNullAnnotations() {
// return notNullAnnotations;
// }
//
// @NotNull
// public Set<String> getNullableAnnotations() {
// return nullableAnnotations;
// }
//
// public boolean isEnabled(@NotNull InstrumentationType type) {
// return instrumentationsToApply.contains(type);
// }
//
// @NotNull
// public Set<InstrumentationType> getInstrumentationsToApply() {
// return instrumentationsToApply;
// }
//
// @NotNull
// public String getExceptionToThrow(@NotNull InstrumentationType type) {
// return exceptionsToThrow.getOrDefault(type, DEFAULT_EXCEPTION_TO_THROW);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionsToThrow() {
// return exceptionsToThrow;
// }
//
// @Nullable
// public String getExceptionTextPattern(@NotNull InstrumentationType type) {
// return exceptionTextPatterns.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, String> getExceptionTextPatterns() {
// return exceptionTextPatterns;
// }
//
// @NotNull
// public Set<String> getNotNullByDefaultAnnotations(@NotNull InstrumentationType type) {
// return notNullByDefaultAnnotations.get(type);
// }
//
// @NotNull
// public Map<InstrumentationType, Set<String>> getNotNullByDefaultAnnotations() {
// return notNullByDefaultAnnotations;
// }
//
// @NotNull
// public Optional<File> getLogFile() {
// return Optional.ofNullable(logFile);
// }
//
// public boolean isVerboseMode() {
// return verboseMode;
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.common.settings.TrautePluginSettings;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import java.util.Collection;
package tech.harmonysoft.oss.traute.test.api.engine;
/**
* Defines an interface for a service which knows how to produce a {@link CompilationResult} from a {@link TestSource}.
*/
public interface TestCompiler {
/**
* Produces a {@link CompilationResult} from the given {@link TestSource}
*
* @param testSources test sources to compile
* @param settings plugin settings to use
* @return compilation result
*/
@NotNull | CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings); |
denis-zhdanov/traute | core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/InstrumentationInfo.java | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType; | package tech.harmonysoft.oss.traute.javac.instrumentation;
/**
* Holds information necessary to perform instrumentation.
*/
public interface InstrumentationInfo {
/**
* @return instrumentation type of the data stored in the current object
*/
@NotNull | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/InstrumentationInfo.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType;
package tech.harmonysoft.oss.traute.javac.instrumentation;
/**
* Holds information necessary to perform instrumentation.
*/
public interface InstrumentationInfo {
/**
* @return instrumentation type of the data stored in the current object
*/
@NotNull | InstrumentationType getType(); |
denis-zhdanov/traute | core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/InstrumentationInfo.java | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType; | package tech.harmonysoft.oss.traute.javac.instrumentation;
/**
* Holds information necessary to perform instrumentation.
*/
public interface InstrumentationInfo {
/**
* @return instrumentation type of the data stored in the current object
*/
@NotNull
InstrumentationType getType();
/**
* @return current compilation unit processing context
*/
@NotNull | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/InstrumentationInfo.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType;
package tech.harmonysoft.oss.traute.javac.instrumentation;
/**
* Holds information necessary to perform instrumentation.
*/
public interface InstrumentationInfo {
/**
* @return instrumentation type of the data stored in the current object
*/
@NotNull
InstrumentationType getType();
/**
* @return current compilation unit processing context
*/
@NotNull | CompilationUnitProcessingContext getContext(); |
denis-zhdanov/traute | core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType;
import java.io.File;
import java.util.*; | package tech.harmonysoft.oss.traute.common.settings;
public class TrautePluginSettings {
public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
private final Set<String> notNullAnnotations = new HashSet<>();
private final Set<String> nullableAnnotations = new HashSet<>(); | // Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/instrumentation/InstrumentationType.java
// public enum InstrumentationType {
//
// /**
// * Before:
// * <pre>
// * public void test(@NotNull String s) {
// * // body
// * }
// * </pre>
// * After:
// * <pre>
// * public void test(@NotNull String s) {
// * if (s == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * // body
// * }
// * </pre>
// */
// METHOD_PARAMETER("parameter"),
//
// /**
// * Before:
// * <pre>
// * @NotNull
// * public String compute() {
// * return doCompute();
// * }
// * </pre>
// * After:
// * <pre>
// * @NotNull
// * public String compute() {
// * String tmpVar = doCompute();
// * if (tmpVar == null) {
// * throw new NullPointerException("[problem details]");
// * }
// * return tmpVar;
// * }
// * </pre>
// */
// METHOD_RETURN("return");
//
// private static Map<String, InstrumentationType> BY_SHORT_NAME = new HashMap<>();
// static {
// for (InstrumentationType type : values()) {
// BY_SHORT_NAME.put(type.getShortName(), type);
// }
// }
//
// @NotNull private final String shortName;
//
// InstrumentationType(@NotNull String shortName) {
// this.shortName = shortName;
// }
//
// @Nullable
// public static InstrumentationType byShortName(@NotNull String shortName) {
// return BY_SHORT_NAME.get(shortName);
// }
//
// @NotNull
// public String getShortName() {
// return shortName;
// }
// }
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/settings/TrautePluginSettings.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType;
import java.io.File;
import java.util.*;
package tech.harmonysoft.oss.traute.common.settings;
public class TrautePluginSettings {
public static final String DEFAULT_EXCEPTION_TO_THROW = NullPointerException.class.getSimpleName();
private final Set<String> notNullAnnotations = new HashSet<>();
private final Set<String> nullableAnnotations = new HashSet<>(); | private final Set<InstrumentationType> instrumentationsToApply = new HashSet<>(); |
denis-zhdanov/traute | facade/maven/src/test/java/tech/harmonysoft/oss/traute/maven/test/impl/TrauteMavenExtension.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
// public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
//
// public AbstractTrauteExtension() {
// System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
// }
//
// @Override
// public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
// for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// if (field.getType() == TestCompiler.class) {
// field.setAccessible(true);
// field.set(testInstance, getCompiler());
// } else if (field.getType() == TestRunner.class) {
// field.setAccessible(true);
// field.set(testInstance, TrauteInMemoryTestRunner.INSTANCE);
// }
// }
// }
// }
//
// @NotNull
// protected abstract TestCompiler getCompiler();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.impl.engine.AbstractTrauteExtension; | package tech.harmonysoft.oss.traute.maven.test.impl;
public class TrauteMavenExtension extends AbstractTrauteExtension {
@Override
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
// public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
//
// public AbstractTrauteExtension() {
// System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
// }
//
// @Override
// public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
// for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// if (field.getType() == TestCompiler.class) {
// field.setAccessible(true);
// field.set(testInstance, getCompiler());
// } else if (field.getType() == TestRunner.class) {
// field.setAccessible(true);
// field.set(testInstance, TrauteInMemoryTestRunner.INSTANCE);
// }
// }
// }
// }
//
// @NotNull
// protected abstract TestCompiler getCompiler();
// }
// Path: facade/maven/src/test/java/tech/harmonysoft/oss/traute/maven/test/impl/TrauteMavenExtension.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.impl.engine.AbstractTrauteExtension;
package tech.harmonysoft.oss.traute.maven.test.impl;
public class TrauteMavenExtension extends AbstractTrauteExtension {
@Override
@NotNull | protected TestCompiler getCompiler() { |
denis-zhdanov/traute | core/javac/src/test/java/tech/harmonysoft/oss/traute/javac/test/impl/SimpleSourceFile.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import javax.tools.JavaCompiler;
import javax.tools.SimpleJavaFileObject;
import java.net.URI; | package tech.harmonysoft.oss.traute.javac.test.impl;
/**
* <p>Stands for a source file with the predefined content.</p>
* <p>Taken from {@link JavaCompiler} javadoc.</p>
*/
public class SimpleSourceFile extends SimpleJavaFileObject {
@NotNull private final String content;
| // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
// Path: core/javac/src/test/java/tech/harmonysoft/oss/traute/javac/test/impl/SimpleSourceFile.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import javax.tools.JavaCompiler;
import javax.tools.SimpleJavaFileObject;
import java.net.URI;
package tech.harmonysoft.oss.traute.javac.test.impl;
/**
* <p>Stands for a source file with the predefined content.</p>
* <p>Taken from {@link JavaCompiler} javadoc.</p>
*/
public class SimpleSourceFile extends SimpleJavaFileObject {
@NotNull private final String content;
| public SimpleSourceFile(@NotNull TestSource testSource) { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
| import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource; | package tech.harmonysoft.oss.traute.test.suite;
public abstract class LoggingTest extends AbstractTrauteTest {
@ParameterizedTest
@CsvSource(value = { "true", "false" })
public void verboseMode_instrumentation(boolean verbose) {
settingsBuilder.withVerboseMode(verbose);
String testSource = String.format(
"package %s;\n" +
"\n" +
"import %s;\n" +
"\n" +
"public class %s {\n" +
"\n" +
" @NotNull\n" +
" public Integer test(@NotNull Integer i1, @NotNull Integer i2) {\n" +
" return i1 + i2;\n" +
" }\n" +
"\n" +
" @NotNull\n" +
" private Integer negative(@NotNull Integer i) {\n" +
" return -1 * i;\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test(1, 2);\n" +
" }\n" + | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource;
package tech.harmonysoft.oss.traute.test.suite;
public abstract class LoggingTest extends AbstractTrauteTest {
@ParameterizedTest
@CsvSource(value = { "true", "false" })
public void verboseMode_instrumentation(boolean verbose) {
settingsBuilder.withVerboseMode(verbose);
String testSource = String.format(
"package %s;\n" +
"\n" +
"import %s;\n" +
"\n" +
"public class %s {\n" +
"\n" +
" @NotNull\n" +
" public Integer test(@NotNull Integer i1, @NotNull Integer i2) {\n" +
" return i1 + i2;\n" +
" }\n" +
"\n" +
" @NotNull\n" +
" private Integer negative(@NotNull Integer i) {\n" +
" return -1 * i;\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test(1, 2);\n" +
" }\n" + | "}", PACKAGE, NotNull.class.getName(), CLASS_NAME); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
| import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource; | package tech.harmonysoft.oss.traute.test.suite;
public abstract class LoggingTest extends AbstractTrauteTest {
@ParameterizedTest
@CsvSource(value = { "true", "false" })
public void verboseMode_instrumentation(boolean verbose) {
settingsBuilder.withVerboseMode(verbose);
String testSource = String.format(
"package %s;\n" +
"\n" +
"import %s;\n" +
"\n" +
"public class %s {\n" +
"\n" +
" @NotNull\n" +
" public Integer test(@NotNull Integer i1, @NotNull Integer i2) {\n" +
" return i1 + i2;\n" +
" }\n" +
"\n" +
" @NotNull\n" +
" private Integer negative(@NotNull Integer i) {\n" +
" return -1 * i;\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test(1, 2);\n" +
" }\n" + | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource;
package tech.harmonysoft.oss.traute.test.suite;
public abstract class LoggingTest extends AbstractTrauteTest {
@ParameterizedTest
@CsvSource(value = { "true", "false" })
public void verboseMode_instrumentation(boolean verbose) {
settingsBuilder.withVerboseMode(verbose);
String testSource = String.format(
"package %s;\n" +
"\n" +
"import %s;\n" +
"\n" +
"public class %s {\n" +
"\n" +
" @NotNull\n" +
" public Integer test(@NotNull Integer i1, @NotNull Integer i2) {\n" +
" return i1 + i2;\n" +
" }\n" +
"\n" +
" @NotNull\n" +
" private Integer negative(@NotNull Integer i) {\n" +
" return -1 * i;\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test(1, 2);\n" +
" }\n" + | "}", PACKAGE, NotNull.class.getName(), CLASS_NAME); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
| import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource; | " return i1 + i2;\n" +
" }\n" +
"\n" +
" class Inner {\n" +
" @NotNull\n" +
" String inner(@NotNull String s) { return s + 1;}\n" +
" }\n" +
"\n" +
" static class StaticInner {\n" +
" @NotNull\n" +
" String staticInner(@NotNull String s) { return s + 2;}\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test(1, 2);\n" +
" }\n" +
"}", PACKAGE, NotNull.class.getName(), CLASS_NAME);
expectCompilationResult.withText(String.format(
"added 7 instrumentations to the .*?/%s/%s%s - METHOD_PARAMETER: 4, METHOD_RETURN: 3",
PACKAGE.replaceAll("\\.", "/"), CLASS_NAME, JavaFileObject.Kind.SOURCE.extension
));
doCompile(testSource);
}
@Test
public void customSetting_annotations() {
settingsBuilder.withNotNullAnnotations(NN.class.getName());
expectCompilationResult.withText(String.format("using the following NotNull annotations: \\[%s\\]",
NN.class.getName())); | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource;
" return i1 + i2;\n" +
" }\n" +
"\n" +
" class Inner {\n" +
" @NotNull\n" +
" String inner(@NotNull String s) { return s + 1;}\n" +
" }\n" +
"\n" +
" static class StaticInner {\n" +
" @NotNull\n" +
" String staticInner(@NotNull String s) { return s + 2;}\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test(1, 2);\n" +
" }\n" +
"}", PACKAGE, NotNull.class.getName(), CLASS_NAME);
expectCompilationResult.withText(String.format(
"added 7 instrumentations to the .*?/%s/%s%s - METHOD_PARAMETER: 4, METHOD_RETURN: 3",
PACKAGE.replaceAll("\\.", "/"), CLASS_NAME, JavaFileObject.Kind.SOURCE.extension
));
doCompile(testSource);
}
@Test
public void customSetting_annotations() {
settingsBuilder.withNotNullAnnotations(NN.class.getName());
expectCompilationResult.withText(String.format("using the following NotNull annotations: \\[%s\\]",
NN.class.getName())); | doCompile(prepareReturnTestSource("return 1;")); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
| import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource; | " new Test().test(1, 2);\n" +
" }\n" +
"}", PACKAGE, NotNull.class.getName(), CLASS_NAME);
expectCompilationResult.withText(String.format(
"added 7 instrumentations to the .*?/%s/%s%s - METHOD_PARAMETER: 4, METHOD_RETURN: 3",
PACKAGE.replaceAll("\\.", "/"), CLASS_NAME, JavaFileObject.Kind.SOURCE.extension
));
doCompile(testSource);
}
@Test
public void customSetting_annotations() {
settingsBuilder.withNotNullAnnotations(NN.class.getName());
expectCompilationResult.withText(String.format("using the following NotNull annotations: \\[%s\\]",
NN.class.getName()));
doCompile(prepareReturnTestSource("return 1;"));
}
@Test
public void customSetting_verbose() {
settingsBuilder.withVerboseMode(true);
expectCompilationResult.withText("'verbose mode' is on");
doCompile(prepareReturnTestSource("return 1;"));
}
@Test
public void noReportForNonEnhancedSource() {
settingsBuilder.withVerboseMode(true);
expectCompilationResult.withText("added 0 instrumentation", false); | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareParameterTestSource(@Nullable String importString,
// @NotNull String testMethod,
// @NotNull String callArguments)
// {
// return prepareParameterTestSource(PACKAGE, importString, testMethod, callArguments);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
// @NotNull
// public static String prepareReturnTestSource(@NotNull String methodBody) {
// return prepareReturnTestSource(NotNull.class, methodBody);
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/LoggingTest.java
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import tech.harmonysoft.oss.traute.test.fixture.NN;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareParameterTestSource;
import static tech.harmonysoft.oss.traute.test.util.TestUtil.prepareReturnTestSource;
" new Test().test(1, 2);\n" +
" }\n" +
"}", PACKAGE, NotNull.class.getName(), CLASS_NAME);
expectCompilationResult.withText(String.format(
"added 7 instrumentations to the .*?/%s/%s%s - METHOD_PARAMETER: 4, METHOD_RETURN: 3",
PACKAGE.replaceAll("\\.", "/"), CLASS_NAME, JavaFileObject.Kind.SOURCE.extension
));
doCompile(testSource);
}
@Test
public void customSetting_annotations() {
settingsBuilder.withNotNullAnnotations(NN.class.getName());
expectCompilationResult.withText(String.format("using the following NotNull annotations: \\[%s\\]",
NN.class.getName()));
doCompile(prepareReturnTestSource("return 1;"));
}
@Test
public void customSetting_verbose() {
settingsBuilder.withVerboseMode(true);
expectCompilationResult.withText("'verbose mode' is on");
doCompile(prepareReturnTestSource("return 1;"));
}
@Test
public void noReportForNonEnhancedSource() {
settingsBuilder.withVerboseMode(true);
expectCompilationResult.withText("added 0 instrumentation", false); | doCompile(prepareParameterTestSource(null, "public void test() {}", "")); |
denis-zhdanov/traute | core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/parameter/ParameterInstrumentator.java | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/text/ExceptionTextGenerator.java
// public interface ExceptionTextGenerator<T> {
//
// @NotNull
// String generate(@NotNull T context);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/AbstractInstrumentator.java
// public abstract class AbstractInstrumentator<T extends InstrumentationInfo> implements Instrumentator<T> {
//
// @Override
// public void instrument(@NotNull T instrumentationInfo) {
// boolean instrumented = mayBeInstrument(instrumentationInfo);
// if (instrumented) {
// instrumentationInfo.getContext().getStatsCollector().increment(instrumentationInfo.getType());
// }
// }
//
// protected abstract boolean mayBeInstrument(@NotNull T instrumentationInfo);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/util/InstrumentationUtil.java
// @NotNull
// public static JCTree.JCIf buildVarCheck(@NotNull TreeMaker factory,
// @NotNull Names symbolsTable,
// @NotNull String variableName,
// @NotNull String errorMessage,
// @NotNull String exceptionToThrow)
// {
// return factory.If(
// factory.Parens(
// factory.Binary(
// JCTree.Tag.EQ,
// factory.Ident(
// symbolsTable.fromString(variableName)
// ),
// factory.Literal(TypeTag.BOT, null))
// ),
// factory.Block(0, List.of(
// factory.Throw(
// factory.NewClass(
// null,
// nil(),
// buildExceptionClassExpression(exceptionToThrow, factory, symbolsTable),
// List.of(factory.Literal(TypeTag.CLASS, errorMessage)),
// null
// )
// )
// )),
// null
// );
// }
| import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names;
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.text.ExceptionTextGenerator;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.javac.instrumentation.AbstractInstrumentator;
import static tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType.METHOD_PARAMETER;
import static tech.harmonysoft.oss.traute.javac.util.InstrumentationUtil.buildVarCheck; | package tech.harmonysoft.oss.traute.javac.instrumentation.parameter;
/**
* <p>Enhances target method in a way to include a {@code null}-check for the target method parameter.</p>
* <p>Thread-safe.</p>
*/
public class ParameterInstrumentator extends AbstractInstrumentator<ParameterToInstrumentInfo> {
@Override
protected boolean mayBeInstrument(@NotNull ParameterToInstrumentInfo info) {
String parameterName = info.getMethodParameter().getName().toString(); | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/text/ExceptionTextGenerator.java
// public interface ExceptionTextGenerator<T> {
//
// @NotNull
// String generate(@NotNull T context);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/AbstractInstrumentator.java
// public abstract class AbstractInstrumentator<T extends InstrumentationInfo> implements Instrumentator<T> {
//
// @Override
// public void instrument(@NotNull T instrumentationInfo) {
// boolean instrumented = mayBeInstrument(instrumentationInfo);
// if (instrumented) {
// instrumentationInfo.getContext().getStatsCollector().increment(instrumentationInfo.getType());
// }
// }
//
// protected abstract boolean mayBeInstrument(@NotNull T instrumentationInfo);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/util/InstrumentationUtil.java
// @NotNull
// public static JCTree.JCIf buildVarCheck(@NotNull TreeMaker factory,
// @NotNull Names symbolsTable,
// @NotNull String variableName,
// @NotNull String errorMessage,
// @NotNull String exceptionToThrow)
// {
// return factory.If(
// factory.Parens(
// factory.Binary(
// JCTree.Tag.EQ,
// factory.Ident(
// symbolsTable.fromString(variableName)
// ),
// factory.Literal(TypeTag.BOT, null))
// ),
// factory.Block(0, List.of(
// factory.Throw(
// factory.NewClass(
// null,
// nil(),
// buildExceptionClassExpression(exceptionToThrow, factory, symbolsTable),
// List.of(factory.Literal(TypeTag.CLASS, errorMessage)),
// null
// )
// )
// )),
// null
// );
// }
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/parameter/ParameterInstrumentator.java
import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names;
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.text.ExceptionTextGenerator;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.javac.instrumentation.AbstractInstrumentator;
import static tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType.METHOD_PARAMETER;
import static tech.harmonysoft.oss.traute.javac.util.InstrumentationUtil.buildVarCheck;
package tech.harmonysoft.oss.traute.javac.instrumentation.parameter;
/**
* <p>Enhances target method in a way to include a {@code null}-check for the target method parameter.</p>
* <p>Thread-safe.</p>
*/
public class ParameterInstrumentator extends AbstractInstrumentator<ParameterToInstrumentInfo> {
@Override
protected boolean mayBeInstrument(@NotNull ParameterToInstrumentInfo info) {
String parameterName = info.getMethodParameter().getName().toString(); | CompilationUnitProcessingContext context = info.getContext(); |
denis-zhdanov/traute | core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/parameter/ParameterInstrumentator.java | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/text/ExceptionTextGenerator.java
// public interface ExceptionTextGenerator<T> {
//
// @NotNull
// String generate(@NotNull T context);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/AbstractInstrumentator.java
// public abstract class AbstractInstrumentator<T extends InstrumentationInfo> implements Instrumentator<T> {
//
// @Override
// public void instrument(@NotNull T instrumentationInfo) {
// boolean instrumented = mayBeInstrument(instrumentationInfo);
// if (instrumented) {
// instrumentationInfo.getContext().getStatsCollector().increment(instrumentationInfo.getType());
// }
// }
//
// protected abstract boolean mayBeInstrument(@NotNull T instrumentationInfo);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/util/InstrumentationUtil.java
// @NotNull
// public static JCTree.JCIf buildVarCheck(@NotNull TreeMaker factory,
// @NotNull Names symbolsTable,
// @NotNull String variableName,
// @NotNull String errorMessage,
// @NotNull String exceptionToThrow)
// {
// return factory.If(
// factory.Parens(
// factory.Binary(
// JCTree.Tag.EQ,
// factory.Ident(
// symbolsTable.fromString(variableName)
// ),
// factory.Literal(TypeTag.BOT, null))
// ),
// factory.Block(0, List.of(
// factory.Throw(
// factory.NewClass(
// null,
// nil(),
// buildExceptionClassExpression(exceptionToThrow, factory, symbolsTable),
// List.of(factory.Literal(TypeTag.CLASS, errorMessage)),
// null
// )
// )
// )),
// null
// );
// }
| import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names;
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.text.ExceptionTextGenerator;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.javac.instrumentation.AbstractInstrumentator;
import static tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType.METHOD_PARAMETER;
import static tech.harmonysoft.oss.traute.javac.util.InstrumentationUtil.buildVarCheck; | package tech.harmonysoft.oss.traute.javac.instrumentation.parameter;
/**
* <p>Enhances target method in a way to include a {@code null}-check for the target method parameter.</p>
* <p>Thread-safe.</p>
*/
public class ParameterInstrumentator extends AbstractInstrumentator<ParameterToInstrumentInfo> {
@Override
protected boolean mayBeInstrument(@NotNull ParameterToInstrumentInfo info) {
String parameterName = info.getMethodParameter().getName().toString();
CompilationUnitProcessingContext context = info.getContext(); | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/text/ExceptionTextGenerator.java
// public interface ExceptionTextGenerator<T> {
//
// @NotNull
// String generate(@NotNull T context);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/AbstractInstrumentator.java
// public abstract class AbstractInstrumentator<T extends InstrumentationInfo> implements Instrumentator<T> {
//
// @Override
// public void instrument(@NotNull T instrumentationInfo) {
// boolean instrumented = mayBeInstrument(instrumentationInfo);
// if (instrumented) {
// instrumentationInfo.getContext().getStatsCollector().increment(instrumentationInfo.getType());
// }
// }
//
// protected abstract boolean mayBeInstrument(@NotNull T instrumentationInfo);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/util/InstrumentationUtil.java
// @NotNull
// public static JCTree.JCIf buildVarCheck(@NotNull TreeMaker factory,
// @NotNull Names symbolsTable,
// @NotNull String variableName,
// @NotNull String errorMessage,
// @NotNull String exceptionToThrow)
// {
// return factory.If(
// factory.Parens(
// factory.Binary(
// JCTree.Tag.EQ,
// factory.Ident(
// symbolsTable.fromString(variableName)
// ),
// factory.Literal(TypeTag.BOT, null))
// ),
// factory.Block(0, List.of(
// factory.Throw(
// factory.NewClass(
// null,
// nil(),
// buildExceptionClassExpression(exceptionToThrow, factory, symbolsTable),
// List.of(factory.Literal(TypeTag.CLASS, errorMessage)),
// null
// )
// )
// )),
// null
// );
// }
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/parameter/ParameterInstrumentator.java
import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names;
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.text.ExceptionTextGenerator;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.javac.instrumentation.AbstractInstrumentator;
import static tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType.METHOD_PARAMETER;
import static tech.harmonysoft.oss.traute.javac.util.InstrumentationUtil.buildVarCheck;
package tech.harmonysoft.oss.traute.javac.instrumentation.parameter;
/**
* <p>Enhances target method in a way to include a {@code null}-check for the target method parameter.</p>
* <p>Thread-safe.</p>
*/
public class ParameterInstrumentator extends AbstractInstrumentator<ParameterToInstrumentInfo> {
@Override
protected boolean mayBeInstrument(@NotNull ParameterToInstrumentInfo info) {
String parameterName = info.getMethodParameter().getName().toString();
CompilationUnitProcessingContext context = info.getContext(); | ExceptionTextGenerator<ParameterToInstrumentInfo> generator = |
denis-zhdanov/traute | core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/parameter/ParameterInstrumentator.java | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/text/ExceptionTextGenerator.java
// public interface ExceptionTextGenerator<T> {
//
// @NotNull
// String generate(@NotNull T context);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/AbstractInstrumentator.java
// public abstract class AbstractInstrumentator<T extends InstrumentationInfo> implements Instrumentator<T> {
//
// @Override
// public void instrument(@NotNull T instrumentationInfo) {
// boolean instrumented = mayBeInstrument(instrumentationInfo);
// if (instrumented) {
// instrumentationInfo.getContext().getStatsCollector().increment(instrumentationInfo.getType());
// }
// }
//
// protected abstract boolean mayBeInstrument(@NotNull T instrumentationInfo);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/util/InstrumentationUtil.java
// @NotNull
// public static JCTree.JCIf buildVarCheck(@NotNull TreeMaker factory,
// @NotNull Names symbolsTable,
// @NotNull String variableName,
// @NotNull String errorMessage,
// @NotNull String exceptionToThrow)
// {
// return factory.If(
// factory.Parens(
// factory.Binary(
// JCTree.Tag.EQ,
// factory.Ident(
// symbolsTable.fromString(variableName)
// ),
// factory.Literal(TypeTag.BOT, null))
// ),
// factory.Block(0, List.of(
// factory.Throw(
// factory.NewClass(
// null,
// nil(),
// buildExceptionClassExpression(exceptionToThrow, factory, symbolsTable),
// List.of(factory.Literal(TypeTag.CLASS, errorMessage)),
// null
// )
// )
// )),
// null
// );
// }
| import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names;
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.text.ExceptionTextGenerator;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.javac.instrumentation.AbstractInstrumentator;
import static tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType.METHOD_PARAMETER;
import static tech.harmonysoft.oss.traute.javac.util.InstrumentationUtil.buildVarCheck; | package tech.harmonysoft.oss.traute.javac.instrumentation.parameter;
/**
* <p>Enhances target method in a way to include a {@code null}-check for the target method parameter.</p>
* <p>Thread-safe.</p>
*/
public class ParameterInstrumentator extends AbstractInstrumentator<ParameterToInstrumentInfo> {
@Override
protected boolean mayBeInstrument(@NotNull ParameterToInstrumentInfo info) {
String parameterName = info.getMethodParameter().getName().toString();
CompilationUnitProcessingContext context = info.getContext();
ExceptionTextGenerator<ParameterToInstrumentInfo> generator =
context.getExceptionTextGeneratorManager().getGenerator(METHOD_PARAMETER, context.getPluginSettings());
String errorMessage = generator.generate(info);
TreeMaker factory = context.getAstFactory();
Names symbolsTable = context.getSymbolsTable();
JCTree.JCBlock body = info.getBody();
String exceptionToThrow = info.getContext().getPluginSettings().getExceptionToThrow(METHOD_PARAMETER); | // Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/text/ExceptionTextGenerator.java
// public interface ExceptionTextGenerator<T> {
//
// @NotNull
// String generate(@NotNull T context);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/common/CompilationUnitProcessingContext.java
// public class CompilationUnitProcessingContext {
//
// private final Set<String> imports = new HashSet<>();
//
// @NotNull private final TrautePluginSettings pluginSettings;
// @NotNull private final TreeMaker astFactory;
// @NotNull private final Names symbolsTable;
// @NotNull private final TrautePluginLogger logger;
// @NotNull private final StatsCollector statsCollector;
// @NotNull private final ExceptionTextGeneratorManager exceptionTextGeneratorManager;
// @NotNull private final PackageInfoManager packageInfoManager;
//
// public CompilationUnitProcessingContext(
// @NotNull TrautePluginSettings pluginSettings,
// @NotNull TreeMaker astFactory,
// @NotNull Names symbolsTable,
// @NotNull TrautePluginLogger logger,
// @NotNull StatsCollector statsCollector,
// @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
// @NotNull PackageInfoManager packageInfoManager)
// {
// this.pluginSettings = pluginSettings;
// this.statsCollector = statsCollector;
// this.astFactory = astFactory;
// this.symbolsTable = symbolsTable;
// this.logger = logger;
// this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
// this.packageInfoManager = packageInfoManager;
// }
//
// public void addImport(@NotNull String importText) {
// imports.add(importText);
// }
//
// @NotNull
// public TrautePluginSettings getPluginSettings() {
// return pluginSettings;
// }
//
// @NotNull
// public Set<String> getImports() {
// return imports;
// }
//
// @NotNull
// public TreeMaker getAstFactory() {
// return astFactory;
// }
//
// @NotNull
// public Names getSymbolsTable() {
// return symbolsTable;
// }
//
// @NotNull
// public TrautePluginLogger getLogger() {
// return logger;
// }
//
// @NotNull
// public StatsCollector getStatsCollector() {
// return statsCollector;
// }
//
// @NotNull
// public ExceptionTextGeneratorManager getExceptionTextGeneratorManager() {
// return exceptionTextGeneratorManager;
// }
//
// @NotNull
// public PackageInfoManager getPackageInfoManager() {
// return packageInfoManager;
// }
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/AbstractInstrumentator.java
// public abstract class AbstractInstrumentator<T extends InstrumentationInfo> implements Instrumentator<T> {
//
// @Override
// public void instrument(@NotNull T instrumentationInfo) {
// boolean instrumented = mayBeInstrument(instrumentationInfo);
// if (instrumented) {
// instrumentationInfo.getContext().getStatsCollector().increment(instrumentationInfo.getType());
// }
// }
//
// protected abstract boolean mayBeInstrument(@NotNull T instrumentationInfo);
// }
//
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/util/InstrumentationUtil.java
// @NotNull
// public static JCTree.JCIf buildVarCheck(@NotNull TreeMaker factory,
// @NotNull Names symbolsTable,
// @NotNull String variableName,
// @NotNull String errorMessage,
// @NotNull String exceptionToThrow)
// {
// return factory.If(
// factory.Parens(
// factory.Binary(
// JCTree.Tag.EQ,
// factory.Ident(
// symbolsTable.fromString(variableName)
// ),
// factory.Literal(TypeTag.BOT, null))
// ),
// factory.Block(0, List.of(
// factory.Throw(
// factory.NewClass(
// null,
// nil(),
// buildExceptionClassExpression(exceptionToThrow, factory, symbolsTable),
// List.of(factory.Literal(TypeTag.CLASS, errorMessage)),
// null
// )
// )
// )),
// null
// );
// }
// Path: core/javac/src/main/java/tech/harmonysoft/oss/traute/javac/instrumentation/parameter/ParameterInstrumentator.java
import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names;
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.text.ExceptionTextGenerator;
import tech.harmonysoft.oss.traute.javac.common.CompilationUnitProcessingContext;
import tech.harmonysoft.oss.traute.javac.instrumentation.AbstractInstrumentator;
import static tech.harmonysoft.oss.traute.common.instrumentation.InstrumentationType.METHOD_PARAMETER;
import static tech.harmonysoft.oss.traute.javac.util.InstrumentationUtil.buildVarCheck;
package tech.harmonysoft.oss.traute.javac.instrumentation.parameter;
/**
* <p>Enhances target method in a way to include a {@code null}-check for the target method parameter.</p>
* <p>Thread-safe.</p>
*/
public class ParameterInstrumentator extends AbstractInstrumentator<ParameterToInstrumentInfo> {
@Override
protected boolean mayBeInstrument(@NotNull ParameterToInstrumentInfo info) {
String parameterName = info.getMethodParameter().getName().toString();
CompilationUnitProcessingContext context = info.getContext();
ExceptionTextGenerator<ParameterToInstrumentInfo> generator =
context.getExceptionTextGeneratorManager().getGenerator(METHOD_PARAMETER, context.getPluginSettings());
String errorMessage = generator.generate(info);
TreeMaker factory = context.getAstFactory();
Names symbolsTable = context.getSymbolsTable();
JCTree.JCBlock body = info.getBody();
String exceptionToThrow = info.getContext().getPluginSettings().getExceptionToThrow(METHOD_PARAMETER); | JCTree.JCIf varCheck = buildVarCheck(factory, symbolsTable, parameterName, errorMessage, exceptionToThrow); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE; | package tech.harmonysoft.oss.traute.test.util;
public class TestUtil {
public static final String PARAMETER_TEST_CLASS_TEMPLATE =
"package %s;\n" +
"%s\n" + | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
package tech.harmonysoft.oss.traute.test.util;
public class TestUtil {
public static final String PARAMETER_TEST_CLASS_TEMPLATE =
"package %s;\n" +
"%s\n" + | "public class " + CLASS_NAME + " {\n" + |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE; | package tech.harmonysoft.oss.traute.test.util;
public class TestUtil {
public static final String PARAMETER_TEST_CLASS_TEMPLATE =
"package %s;\n" +
"%s\n" +
"public class " + CLASS_NAME + " {\n" +
"\n" +
"%s\n" +
"\n" +
" public static void main(String[] args) {\n" + | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
package tech.harmonysoft.oss.traute.test.util;
public class TestUtil {
public static final String PARAMETER_TEST_CLASS_TEMPLATE =
"package %s;\n" +
"%s\n" +
"public class " + CLASS_NAME + " {\n" +
"\n" +
"%s\n" +
"\n" +
" public static void main(String[] args) {\n" + | " new " + CLASS_NAME + "()." + METHOD_NAME + "(%s);\n" + |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE; | package tech.harmonysoft.oss.traute.test.util;
public class TestUtil {
public static final String PARAMETER_TEST_CLASS_TEMPLATE =
"package %s;\n" +
"%s\n" +
"public class " + CLASS_NAME + " {\n" +
"\n" +
"%s\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new " + CLASS_NAME + "()." + METHOD_NAME + "(%s);\n" +
" }\n" +
"}";
public static final String METHOD_TEST_CLASS_TEMPLATE = String.format(
"package %s;\n" +
"\n" +
"public class %s {\n" +
"\n" +
" @%%s\n" +
" public Integer test() {\n" +
" %%s\n" +
" }\n" +
"\n" +
" private Integer count() {\n" +
" return null;\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test();\n" +
" }\n" + | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
package tech.harmonysoft.oss.traute.test.util;
public class TestUtil {
public static final String PARAMETER_TEST_CLASS_TEMPLATE =
"package %s;\n" +
"%s\n" +
"public class " + CLASS_NAME + " {\n" +
"\n" +
"%s\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new " + CLASS_NAME + "()." + METHOD_NAME + "(%s);\n" +
" }\n" +
"}";
public static final String METHOD_TEST_CLASS_TEMPLATE = String.format(
"package %s;\n" +
"\n" +
"public class %s {\n" +
"\n" +
" @%%s\n" +
" public Integer test() {\n" +
" %%s\n" +
" }\n" +
"\n" +
" private Integer count() {\n" +
" return null;\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" new Test().test();\n" +
" }\n" + | "}", PACKAGE, CLASS_NAME); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE; | return String.format(METHOD_TEST_CLASS_TEMPLATE,
notNullAnnotationClass.getName(),
methodBody.replaceAll("\n", "\n "));
}
public static int findLineNumber(@NotNull String text, @NotNull String marker) {
int i = text.indexOf(marker);
if (i <= 0) {
fail(String.format("Can't find line number for the text '%s'. It's not contained in the source:%n%s",
marker, text));
}
int line = 1;
for (int j = 0; j < i; j++) {
if (text.charAt(j) == '\n') {
line++;
}
}
return line;
}
/**
* Configures expectations for running test code assuming that a plugin-introduced {@code null}-check
* should be triggered for the target method parameter.
*
* @param testSource test source
* @param parameterName name of the {@code NotNull} parameter which should be reported
* @param expectRunResult test run expectations
*/
public static void expectNpeFromParameterCheck(@NotNull String testSource,
@NotNull String parameterName, | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
return String.format(METHOD_TEST_CLASS_TEMPLATE,
notNullAnnotationClass.getName(),
methodBody.replaceAll("\n", "\n "));
}
public static int findLineNumber(@NotNull String text, @NotNull String marker) {
int i = text.indexOf(marker);
if (i <= 0) {
fail(String.format("Can't find line number for the text '%s'. It's not contained in the source:%n%s",
marker, text));
}
int line = 1;
for (int j = 0; j < i; j++) {
if (text.charAt(j) == '\n') {
line++;
}
}
return line;
}
/**
* Configures expectations for running test code assuming that a plugin-introduced {@code null}-check
* should be triggered for the target method parameter.
*
* @param testSource test source
* @param parameterName name of the {@code NotNull} parameter which should be reported
* @param expectRunResult test run expectations
*/
public static void expectNpeFromParameterCheck(@NotNull String testSource,
@NotNull String parameterName, | @NotNull RunResultExpectationBuilder expectRunResult) |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE; | return line;
}
/**
* Configures expectations for running test code assuming that a plugin-introduced {@code null}-check
* should be triggered for the target method parameter.
*
* @param testSource test source
* @param parameterName name of the {@code NotNull} parameter which should be reported
* @param expectRunResult test run expectations
*/
public static void expectNpeFromParameterCheck(@NotNull String testSource,
@NotNull String parameterName,
@NotNull RunResultExpectationBuilder expectRunResult)
{
expectRunResult.withExceptionClass(NullPointerException.class)
.withExceptionMessageSnippet(parameterName)
.atLine(findLineNumber(testSource, parameterName));
}
public static void expectNpeFromReturnCheck(@NotNull String testSource,
@NotNull String returnExpression,
@NotNull RunResultExpectationBuilder expectRunResult)
{
expectRunResult.withExceptionClass(NullPointerException.class)
.withExceptionMessageSnippet("Detected an attempt to return null from a method")
.atLine(findLineNumber(testSource, returnExpression));
}
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
return line;
}
/**
* Configures expectations for running test code assuming that a plugin-introduced {@code null}-check
* should be triggered for the target method parameter.
*
* @param testSource test source
* @param parameterName name of the {@code NotNull} parameter which should be reported
* @param expectRunResult test run expectations
*/
public static void expectNpeFromParameterCheck(@NotNull String testSource,
@NotNull String parameterName,
@NotNull RunResultExpectationBuilder expectRunResult)
{
expectRunResult.withExceptionClass(NullPointerException.class)
.withExceptionMessageSnippet(parameterName)
.atLine(findLineNumber(testSource, parameterName));
}
public static void expectNpeFromReturnCheck(@NotNull String testSource,
@NotNull String returnExpression,
@NotNull RunResultExpectationBuilder expectRunResult)
{
expectRunResult.withExceptionClass(NullPointerException.class)
.withExceptionMessageSnippet("Detected an attempt to return null from a method")
.atLine(findLineNumber(testSource, returnExpression));
}
@NotNull | public static String getSources(@NotNull Collection<TestSource> sources) { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
| import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE; | @NotNull RunResultExpectationBuilder expectRunResult)
{
expectRunResult.withExceptionClass(NullPointerException.class)
.withExceptionMessageSnippet("Detected an attempt to return null from a method")
.atLine(findLineNumber(testSource, returnExpression));
}
@NotNull
public static String getSources(@NotNull Collection<TestSource> sources) {
return sources.stream()
.map(s -> s.getQualifiedClassName() + ".java:\n\n" + s.getSourceText())
.collect(joining("\n\n"));
}
@NotNull
public static TestSource findInClassPath(@NotNull String root, @NotNull String qualifiedClassName) {
InputStream in = ClassLoader
.getSystemClassLoader()
.getResourceAsStream(root + "/" + qualifiedClassName.replace('.', '/') + ".java");
byte[] buffer = new byte[1024];
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int read;
try {
while ((read = in.read(buffer)) >= 0) {
bOut.write(buffer, 0, read);
}
} catch (IOException e) {
throw new IllegalStateException(String.format("Can't read source text for the class %s from source "
+ "root '%s'", qualifiedClassName, root), e);
} | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/expectation/RunResultExpectationBuilder.java
// @SuppressWarnings("UnusedReturnValue")
// public class RunResultExpectationBuilder {
//
// @Nullable private String expectedExceptionClass;
// @Nullable private String expectedExceptionMessageSnippet;
// @Nullable private String expectedExceptionMessageText;
// @Nullable private Integer thrownAtLine;
//
// @NotNull
// public static RunResultExpectationBuilder expectRunResult() {
// return new RunResultExpectationBuilder();
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull Class<?> clazz) {
// return withExceptionClass(clazz.getName());
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionClass(@NotNull String clazz) {
// expectedExceptionClass = clazz;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessageSnippet(@NotNull String snippet) {
// expectedExceptionMessageSnippet = snippet;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder withExceptionMessage(@NotNull String message) {
// expectedExceptionMessageText = message;
// return this;
// }
//
// @NotNull
// public RunResultExpectationBuilder atLine(int line) {
// thrownAtLine = line;
// return this;
// }
//
// @NotNull
// public RunResultExpectation build() {
// return new RunResultExpectation(expectedExceptionClass,
// expectedExceptionMessageSnippet,
// expectedExceptionMessageText,
// thrownAtLine);
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/TestSourceImpl.java
// public class TestSourceImpl implements TestSource {
//
// @NotNull private final String sourceText;
// @NotNull private final String className;
//
// public TestSourceImpl(@NotNull String sourceText, @NotNull String className) {
// this.sourceText = sourceText;
// this.className = className;
// }
//
// @Override
// @NotNull
// public String getSourceText() {
// return sourceText;
// }
//
// @Override
// @NotNull
// public String getQualifiedClassName() {
// return className;
// }
//
// @Override
// public String toString() {
// return className + " source";
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String CLASS_NAME = "Test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String METHOD_NAME = "test";
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestConstants.java
// public static final String PACKAGE = "tech.harmonysoft.oss.traute.test";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/util/TestUtil.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.expectation.RunResultExpectationBuilder;
import tech.harmonysoft.oss.traute.test.impl.model.TestSourceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.fail;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.CLASS_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.METHOD_NAME;
import static tech.harmonysoft.oss.traute.test.util.TestConstants.PACKAGE;
@NotNull RunResultExpectationBuilder expectRunResult)
{
expectRunResult.withExceptionClass(NullPointerException.class)
.withExceptionMessageSnippet("Detected an attempt to return null from a method")
.atLine(findLineNumber(testSource, returnExpression));
}
@NotNull
public static String getSources(@NotNull Collection<TestSource> sources) {
return sources.stream()
.map(s -> s.getQualifiedClassName() + ".java:\n\n" + s.getSourceText())
.collect(joining("\n\n"));
}
@NotNull
public static TestSource findInClassPath(@NotNull String root, @NotNull String qualifiedClassName) {
InputStream in = ClassLoader
.getSystemClassLoader()
.getResourceAsStream(root + "/" + qualifiedClassName.replace('.', '/') + ".java");
byte[] buffer = new byte[1024];
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int read;
try {
while ((read = in.read(buffer)) >= 0) {
bOut.write(buffer, 0, read);
}
} catch (IOException e) {
throw new IllegalStateException(String.format("Can't read source text for the class %s from source "
+ "root '%s'", qualifiedClassName, root), e);
} | return new TestSourceImpl(new String(bOut.toByteArray(), StandardCharsets.UTF_8), qualifiedClassName); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/AbstractTrauteTest.java
// @SuppressWarnings("NullableProblems")
// @ExtendWith(TestDurationPrinter.class)
// public abstract class AbstractTrauteTest {
//
// public static final String ACTIVATION_PROPERTY = AbstractTrauteTest.class.getName();
//
// @NotNull protected TestCompiler compiler;
// @NotNull protected TestRunner runner;
// @NotNull protected TrautePluginSettingsBuilder settingsBuilder;
// @NotNull protected CompilationResultExpectationBuilder expectCompilationResult;
// @NotNull protected RunResultExpectationBuilder expectRunResult;
//
// @BeforeEach
// public void commonSetUp() {
// settingsBuilder = TrautePluginSettingsBuilder.settingsBuilder();
// expectCompilationResult = CompilationResultExpectationBuilder.expectCompilationResult();
// expectRunResult = RunResultExpectationBuilder.expectRunResult();
//
// Assumptions.assumeTrue(Boolean.getBoolean(ACTIVATION_PROPERTY));
// }
//
// protected void doTest(@NotNull String testSource) {
// doTest(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// protected void doTest(@NotNull TestSource ... testSources) {
// CompilationResult compilationResult = compiler.compile(asList(testSources),
// settingsBuilder.build(),
// expectCompilationResult.build());
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// protected void doTest(@NotNull String qualifiedClassName, @NotNull String testSource) {
// CompilationResult compilationResult = doCompile(qualifiedClassName, testSource);
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// @NotNull
// protected void doCompile(@NotNull String testSource) {
// doCompile(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// @NotNull
// protected CompilationResult doCompile(@NotNull String qualifiedClassName, @NotNull String testSource) {
// return compiler.compile(singleton(new TestSourceImpl(testSource, qualifiedClassName)),
// settingsBuilder.build(),
// expectCompilationResult.build());
// }
// }
| import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.suite.AbstractTrauteTest;
import java.lang.reflect.Field; | package tech.harmonysoft.oss.traute.test.impl.engine;
public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
public AbstractTrauteExtension() { | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/AbstractTrauteTest.java
// @SuppressWarnings("NullableProblems")
// @ExtendWith(TestDurationPrinter.class)
// public abstract class AbstractTrauteTest {
//
// public static final String ACTIVATION_PROPERTY = AbstractTrauteTest.class.getName();
//
// @NotNull protected TestCompiler compiler;
// @NotNull protected TestRunner runner;
// @NotNull protected TrautePluginSettingsBuilder settingsBuilder;
// @NotNull protected CompilationResultExpectationBuilder expectCompilationResult;
// @NotNull protected RunResultExpectationBuilder expectRunResult;
//
// @BeforeEach
// public void commonSetUp() {
// settingsBuilder = TrautePluginSettingsBuilder.settingsBuilder();
// expectCompilationResult = CompilationResultExpectationBuilder.expectCompilationResult();
// expectRunResult = RunResultExpectationBuilder.expectRunResult();
//
// Assumptions.assumeTrue(Boolean.getBoolean(ACTIVATION_PROPERTY));
// }
//
// protected void doTest(@NotNull String testSource) {
// doTest(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// protected void doTest(@NotNull TestSource ... testSources) {
// CompilationResult compilationResult = compiler.compile(asList(testSources),
// settingsBuilder.build(),
// expectCompilationResult.build());
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// protected void doTest(@NotNull String qualifiedClassName, @NotNull String testSource) {
// CompilationResult compilationResult = doCompile(qualifiedClassName, testSource);
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// @NotNull
// protected void doCompile(@NotNull String testSource) {
// doCompile(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// @NotNull
// protected CompilationResult doCompile(@NotNull String qualifiedClassName, @NotNull String testSource) {
// return compiler.compile(singleton(new TestSourceImpl(testSource, qualifiedClassName)),
// settingsBuilder.build(),
// expectCompilationResult.build());
// }
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.suite.AbstractTrauteTest;
import java.lang.reflect.Field;
package tech.harmonysoft.oss.traute.test.impl.engine;
public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
public AbstractTrauteExtension() { | System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString()); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/AbstractTrauteTest.java
// @SuppressWarnings("NullableProblems")
// @ExtendWith(TestDurationPrinter.class)
// public abstract class AbstractTrauteTest {
//
// public static final String ACTIVATION_PROPERTY = AbstractTrauteTest.class.getName();
//
// @NotNull protected TestCompiler compiler;
// @NotNull protected TestRunner runner;
// @NotNull protected TrautePluginSettingsBuilder settingsBuilder;
// @NotNull protected CompilationResultExpectationBuilder expectCompilationResult;
// @NotNull protected RunResultExpectationBuilder expectRunResult;
//
// @BeforeEach
// public void commonSetUp() {
// settingsBuilder = TrautePluginSettingsBuilder.settingsBuilder();
// expectCompilationResult = CompilationResultExpectationBuilder.expectCompilationResult();
// expectRunResult = RunResultExpectationBuilder.expectRunResult();
//
// Assumptions.assumeTrue(Boolean.getBoolean(ACTIVATION_PROPERTY));
// }
//
// protected void doTest(@NotNull String testSource) {
// doTest(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// protected void doTest(@NotNull TestSource ... testSources) {
// CompilationResult compilationResult = compiler.compile(asList(testSources),
// settingsBuilder.build(),
// expectCompilationResult.build());
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// protected void doTest(@NotNull String qualifiedClassName, @NotNull String testSource) {
// CompilationResult compilationResult = doCompile(qualifiedClassName, testSource);
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// @NotNull
// protected void doCompile(@NotNull String testSource) {
// doCompile(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// @NotNull
// protected CompilationResult doCompile(@NotNull String qualifiedClassName, @NotNull String testSource) {
// return compiler.compile(singleton(new TestSourceImpl(testSource, qualifiedClassName)),
// settingsBuilder.build(),
// expectCompilationResult.build());
// }
// }
| import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.suite.AbstractTrauteTest;
import java.lang.reflect.Field; | package tech.harmonysoft.oss.traute.test.impl.engine;
public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
public AbstractTrauteExtension() {
System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
}
@Override
public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) { | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/AbstractTrauteTest.java
// @SuppressWarnings("NullableProblems")
// @ExtendWith(TestDurationPrinter.class)
// public abstract class AbstractTrauteTest {
//
// public static final String ACTIVATION_PROPERTY = AbstractTrauteTest.class.getName();
//
// @NotNull protected TestCompiler compiler;
// @NotNull protected TestRunner runner;
// @NotNull protected TrautePluginSettingsBuilder settingsBuilder;
// @NotNull protected CompilationResultExpectationBuilder expectCompilationResult;
// @NotNull protected RunResultExpectationBuilder expectRunResult;
//
// @BeforeEach
// public void commonSetUp() {
// settingsBuilder = TrautePluginSettingsBuilder.settingsBuilder();
// expectCompilationResult = CompilationResultExpectationBuilder.expectCompilationResult();
// expectRunResult = RunResultExpectationBuilder.expectRunResult();
//
// Assumptions.assumeTrue(Boolean.getBoolean(ACTIVATION_PROPERTY));
// }
//
// protected void doTest(@NotNull String testSource) {
// doTest(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// protected void doTest(@NotNull TestSource ... testSources) {
// CompilationResult compilationResult = compiler.compile(asList(testSources),
// settingsBuilder.build(),
// expectCompilationResult.build());
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// protected void doTest(@NotNull String qualifiedClassName, @NotNull String testSource) {
// CompilationResult compilationResult = doCompile(qualifiedClassName, testSource);
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// @NotNull
// protected void doCompile(@NotNull String testSource) {
// doCompile(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// @NotNull
// protected CompilationResult doCompile(@NotNull String qualifiedClassName, @NotNull String testSource) {
// return compiler.compile(singleton(new TestSourceImpl(testSource, qualifiedClassName)),
// settingsBuilder.build(),
// expectCompilationResult.build());
// }
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.suite.AbstractTrauteTest;
import java.lang.reflect.Field;
package tech.harmonysoft.oss.traute.test.impl.engine;
public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
public AbstractTrauteExtension() {
System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
}
@Override
public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) { | if (field.getType() == TestCompiler.class) { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/AbstractTrauteTest.java
// @SuppressWarnings("NullableProblems")
// @ExtendWith(TestDurationPrinter.class)
// public abstract class AbstractTrauteTest {
//
// public static final String ACTIVATION_PROPERTY = AbstractTrauteTest.class.getName();
//
// @NotNull protected TestCompiler compiler;
// @NotNull protected TestRunner runner;
// @NotNull protected TrautePluginSettingsBuilder settingsBuilder;
// @NotNull protected CompilationResultExpectationBuilder expectCompilationResult;
// @NotNull protected RunResultExpectationBuilder expectRunResult;
//
// @BeforeEach
// public void commonSetUp() {
// settingsBuilder = TrautePluginSettingsBuilder.settingsBuilder();
// expectCompilationResult = CompilationResultExpectationBuilder.expectCompilationResult();
// expectRunResult = RunResultExpectationBuilder.expectRunResult();
//
// Assumptions.assumeTrue(Boolean.getBoolean(ACTIVATION_PROPERTY));
// }
//
// protected void doTest(@NotNull String testSource) {
// doTest(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// protected void doTest(@NotNull TestSource ... testSources) {
// CompilationResult compilationResult = compiler.compile(asList(testSources),
// settingsBuilder.build(),
// expectCompilationResult.build());
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// protected void doTest(@NotNull String qualifiedClassName, @NotNull String testSource) {
// CompilationResult compilationResult = doCompile(qualifiedClassName, testSource);
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// @NotNull
// protected void doCompile(@NotNull String testSource) {
// doCompile(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// @NotNull
// protected CompilationResult doCompile(@NotNull String qualifiedClassName, @NotNull String testSource) {
// return compiler.compile(singleton(new TestSourceImpl(testSource, qualifiedClassName)),
// settingsBuilder.build(),
// expectCompilationResult.build());
// }
// }
| import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.suite.AbstractTrauteTest;
import java.lang.reflect.Field; | package tech.harmonysoft.oss.traute.test.impl.engine;
public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
public AbstractTrauteExtension() {
System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
}
@Override
public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.getType() == TestCompiler.class) {
field.setAccessible(true);
field.set(testInstance, getCompiler()); | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/suite/AbstractTrauteTest.java
// @SuppressWarnings("NullableProblems")
// @ExtendWith(TestDurationPrinter.class)
// public abstract class AbstractTrauteTest {
//
// public static final String ACTIVATION_PROPERTY = AbstractTrauteTest.class.getName();
//
// @NotNull protected TestCompiler compiler;
// @NotNull protected TestRunner runner;
// @NotNull protected TrautePluginSettingsBuilder settingsBuilder;
// @NotNull protected CompilationResultExpectationBuilder expectCompilationResult;
// @NotNull protected RunResultExpectationBuilder expectRunResult;
//
// @BeforeEach
// public void commonSetUp() {
// settingsBuilder = TrautePluginSettingsBuilder.settingsBuilder();
// expectCompilationResult = CompilationResultExpectationBuilder.expectCompilationResult();
// expectRunResult = RunResultExpectationBuilder.expectRunResult();
//
// Assumptions.assumeTrue(Boolean.getBoolean(ACTIVATION_PROPERTY));
// }
//
// protected void doTest(@NotNull String testSource) {
// doTest(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// protected void doTest(@NotNull TestSource ... testSources) {
// CompilationResult compilationResult = compiler.compile(asList(testSources),
// settingsBuilder.build(),
// expectCompilationResult.build());
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// protected void doTest(@NotNull String qualifiedClassName, @NotNull String testSource) {
// CompilationResult compilationResult = doCompile(qualifiedClassName, testSource);
// try {
// runner.run(compilationResult, expectRunResult.build());
// } finally {
// compiler.release(compilationResult);
// }
// }
//
// @NotNull
// protected void doCompile(@NotNull String testSource) {
// doCompile(TestUtil.QUALIFIED_CLASS_NAME, testSource);
// }
//
// @NotNull
// protected CompilationResult doCompile(@NotNull String qualifiedClassName, @NotNull String testSource) {
// return compiler.compile(singleton(new TestSourceImpl(testSource, qualifiedClassName)),
// settingsBuilder.build(),
// expectCompilationResult.build());
// }
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.suite.AbstractTrauteTest;
import java.lang.reflect.Field;
package tech.harmonysoft.oss.traute.test.impl.engine;
public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
public AbstractTrauteExtension() {
System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
}
@Override
public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.getType() == TestCompiler.class) {
field.setAccessible(true);
field.set(testInstance, getCompiler()); | } else if (field.getType() == TestRunner.class) { |
denis-zhdanov/traute | core/javac/src/test/java/tech/harmonysoft/oss/traute/javac/test/impl/TrauteJavacExtension.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
// public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
//
// public AbstractTrauteExtension() {
// System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
// }
//
// @Override
// public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
// for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// if (field.getType() == TestCompiler.class) {
// field.setAccessible(true);
// field.set(testInstance, getCompiler());
// } else if (field.getType() == TestRunner.class) {
// field.setAccessible(true);
// field.set(testInstance, TrauteInMemoryTestRunner.INSTANCE);
// }
// }
// }
// }
//
// @NotNull
// protected abstract TestCompiler getCompiler();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.impl.engine.AbstractTrauteExtension; | package tech.harmonysoft.oss.traute.javac.test.impl;
public class TrauteJavacExtension extends AbstractTrauteExtension {
@Override
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
// public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
//
// public AbstractTrauteExtension() {
// System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
// }
//
// @Override
// public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
// for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// if (field.getType() == TestCompiler.class) {
// field.setAccessible(true);
// field.set(testInstance, getCompiler());
// } else if (field.getType() == TestRunner.class) {
// field.setAccessible(true);
// field.set(testInstance, TrauteInMemoryTestRunner.INSTANCE);
// }
// }
// }
// }
//
// @NotNull
// protected abstract TestCompiler getCompiler();
// }
// Path: core/javac/src/test/java/tech/harmonysoft/oss/traute/javac/test/impl/TrauteJavacExtension.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.impl.engine.AbstractTrauteExtension;
package tech.harmonysoft.oss.traute.javac.test.impl;
public class TrauteJavacExtension extends AbstractTrauteExtension {
@Override
@NotNull | protected TestCompiler getCompiler() { |
denis-zhdanov/traute | facade/ant/src/test/java/tech/harmonysoft/oss/traute/ant/test/impl/TrauteAntExtension.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
// public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
//
// public AbstractTrauteExtension() {
// System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
// }
//
// @Override
// public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
// for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// if (field.getType() == TestCompiler.class) {
// field.setAccessible(true);
// field.set(testInstance, getCompiler());
// } else if (field.getType() == TestRunner.class) {
// field.setAccessible(true);
// field.set(testInstance, TrauteInMemoryTestRunner.INSTANCE);
// }
// }
// }
// }
//
// @NotNull
// protected abstract TestCompiler getCompiler();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.impl.engine.AbstractTrauteExtension; | package tech.harmonysoft.oss.traute.ant.test.impl;
public class TrauteAntExtension extends AbstractTrauteExtension {
@Override | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestCompiler.java
// public interface TestCompiler {
//
// /**
// * Produces a {@link CompilationResult} from the given {@link TestSource}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @return compilation result
// */
// @NotNull
// CompilationResult compile(@NotNull Collection<TestSource> testSources, @NotNull TrautePluginSettings settings);
//
// /**
// * Behaves like {@link #compile(Collection, TrautePluginSettings)} but additionally checks
// * resulting {@link CompilationResult} against the given {@link Expectation}
// *
// * @param testSources test sources to compile
// * @param settings plugin settings to use
// * @param expectation a compilation result's expectation
// * @return compilation result for the given test sources
// */
// @NotNull
// default CompilationResult compile(@NotNull Collection<TestSource> testSources,
// @NotNull TrautePluginSettings settings,
// @NotNull Expectation<CompilationResult> expectation)
// {
// CompilationResult result = compile(testSources, settings);
// expectation.match(result);
// return result;
// }
//
// /**
// * @param result notifies that given compilation result is not needed anymore and all resources associated
// * with it can be released
// */
// void release(@NotNull CompilationResult result);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/AbstractTrauteExtension.java
// public abstract class AbstractTrauteExtension implements TestInstancePostProcessor {
//
// public AbstractTrauteExtension() {
// System.setProperty(AbstractTrauteTest.ACTIVATION_PROPERTY, Boolean.TRUE.toString());
// }
//
// @Override
// public final void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
// for (Class<?> clazz = testInstance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// if (field.getType() == TestCompiler.class) {
// field.setAccessible(true);
// field.set(testInstance, getCompiler());
// } else if (field.getType() == TestRunner.class) {
// field.setAccessible(true);
// field.set(testInstance, TrauteInMemoryTestRunner.INSTANCE);
// }
// }
// }
// }
//
// @NotNull
// protected abstract TestCompiler getCompiler();
// }
// Path: facade/ant/src/test/java/tech/harmonysoft/oss/traute/ant/test/impl/TrauteAntExtension.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestCompiler;
import tech.harmonysoft.oss.traute.test.impl.engine.AbstractTrauteExtension;
package tech.harmonysoft.oss.traute.ant.test.impl;
public class TrauteAntExtension extends AbstractTrauteExtension {
@Override | protected @NotNull TestCompiler getCompiler() { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult; | package tech.harmonysoft.oss.traute.test.api.engine;
public interface TestRunner {
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
package tech.harmonysoft.oss.traute.test.api.engine;
public interface TestRunner {
@NotNull | RunResult run(@NotNull CompilationResult compilationResult); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult; | package tech.harmonysoft.oss.traute.test.api.engine;
public interface TestRunner {
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
package tech.harmonysoft.oss.traute.test.api.engine;
public interface TestRunner {
@NotNull | RunResult run(@NotNull CompilationResult compilationResult); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult; | package tech.harmonysoft.oss.traute.test.api.engine;
public interface TestRunner {
@NotNull
RunResult run(@NotNull CompilationResult compilationResult);
| // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/expectation/Expectation.java
// public interface Expectation<T> {
//
// /**
// * Ensures that given data matches current expectations. Is expected to call {@link Assertions#fail(String)}
// * in case of the mismatch.
// *
// * @param actual data to match
// */
// void match(@NotNull T actual);
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.expectation.Expectation;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
package tech.harmonysoft.oss.traute.test.api.engine;
public interface TestRunner {
@NotNull
RunResult run(@NotNull CompilationResult compilationResult);
| default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO; | package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO;
package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull | public RunResult run(@NotNull CompilationResult compilationResult) { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO; | package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO;
package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull | public RunResult run(@NotNull CompilationResult compilationResult) { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO; | package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream() | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO;
package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream() | .collect(toMap(ClassFile::getName, |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO; | package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream()
.collect(toMap(ClassFile::getName,
ClassFile::getBinaries));
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) {
byte[] compiledBinaries = compiled.get(name);
if (compiledBinaries == null) {
throw new IllegalArgumentException(String.format(
"Can't find compiled binaries for class %s. Available binaries found for %s",
name, compiled.keySet()
));
}
return defineClass(name, compiledBinaries, 0, compiledBinaries.length);
}
};
Class<?> clazz;
try {
clazz = classLoader.loadClass(getStartClass(compilationResult.getInput()));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Can't load compiled test class", e);
}
Method method;
try {
method = clazz.getMethod("main", String[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find the 'main()' method in the compiled test class", e);
}
try {
method.invoke(null, MAIN_ARGUMENTS); | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO;
package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream()
.collect(toMap(ClassFile::getName,
ClassFile::getBinaries));
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) {
byte[] compiledBinaries = compiled.get(name);
if (compiledBinaries == null) {
throw new IllegalArgumentException(String.format(
"Can't find compiled binaries for class %s. Available binaries found for %s",
name, compiled.keySet()
));
}
return defineClass(name, compiledBinaries, 0, compiledBinaries.length);
}
};
Class<?> clazz;
try {
clazz = classLoader.loadClass(getStartClass(compilationResult.getInput()));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Can't load compiled test class", e);
}
Method method;
try {
method = clazz.getMethod("main", String[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find the 'main()' method in the compiled test class", e);
}
try {
method.invoke(null, MAIN_ARGUMENTS); | return new RunResultImpl(compilationResult, null); |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO; | package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream()
.collect(toMap(ClassFile::getName,
ClassFile::getBinaries));
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) {
byte[] compiledBinaries = compiled.get(name);
if (compiledBinaries == null) {
throw new IllegalArgumentException(String.format(
"Can't find compiled binaries for class %s. Available binaries found for %s",
name, compiled.keySet()
));
}
return defineClass(name, compiledBinaries, 0, compiledBinaries.length);
}
};
Class<?> clazz;
try {
clazz = classLoader.loadClass(getStartClass(compilationResult.getInput()));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Can't load compiled test class", e);
}
Method method;
try {
method = clazz.getMethod("main", String[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find the 'main()' method in the compiled test class", e);
}
try {
method.invoke(null, MAIN_ARGUMENTS);
return new RunResultImpl(compilationResult, null);
} catch (IllegalAccessException e) {
return new RunResultImpl(compilationResult, e);
} catch (InvocationTargetException e) {
return new RunResultImpl(compilationResult, e.getCause());
}
}
@NotNull | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO;
package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream()
.collect(toMap(ClassFile::getName,
ClassFile::getBinaries));
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) {
byte[] compiledBinaries = compiled.get(name);
if (compiledBinaries == null) {
throw new IllegalArgumentException(String.format(
"Can't find compiled binaries for class %s. Available binaries found for %s",
name, compiled.keySet()
));
}
return defineClass(name, compiledBinaries, 0, compiledBinaries.length);
}
};
Class<?> clazz;
try {
clazz = classLoader.loadClass(getStartClass(compilationResult.getInput()));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Can't load compiled test class", e);
}
Method method;
try {
method = clazz.getMethod("main", String[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find the 'main()' method in the compiled test class", e);
}
try {
method.invoke(null, MAIN_ARGUMENTS);
return new RunResultImpl(compilationResult, null);
} catch (IllegalAccessException e) {
return new RunResultImpl(compilationResult, e);
} catch (InvocationTargetException e) {
return new RunResultImpl(compilationResult, e.getCause());
}
}
@NotNull | private static String getStartClass(@NotNull Collection<TestSource> testSources) { |
denis-zhdanov/traute | core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
| import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO; | package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream()
.collect(toMap(ClassFile::getName,
ClassFile::getBinaries));
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) {
byte[] compiledBinaries = compiled.get(name);
if (compiledBinaries == null) {
throw new IllegalArgumentException(String.format(
"Can't find compiled binaries for class %s. Available binaries found for %s",
name, compiled.keySet()
));
}
return defineClass(name, compiledBinaries, 0, compiledBinaries.length);
}
};
Class<?> clazz;
try {
clazz = classLoader.loadClass(getStartClass(compilationResult.getInput()));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Can't load compiled test class", e);
}
Method method;
try {
method = clazz.getMethod("main", String[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find the 'main()' method in the compiled test class", e);
}
try {
method.invoke(null, MAIN_ARGUMENTS);
return new RunResultImpl(compilationResult, null);
} catch (IllegalAccessException e) {
return new RunResultImpl(compilationResult, e);
} catch (InvocationTargetException e) {
return new RunResultImpl(compilationResult, e.getCause());
}
}
@NotNull
private static String getStartClass(@NotNull Collection<TestSource> testSources) {
for (TestSource testSource : testSources) {
String candidate = testSource.getQualifiedClassName(); | // Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/engine/TestRunner.java
// public interface TestRunner {
//
// @NotNull
// RunResult run(@NotNull CompilationResult compilationResult);
//
// default void run(@NotNull CompilationResult compilationResult, @NotNull Expectation<RunResult> expectation) {
// expectation.match(run(compilationResult));
// }
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/ClassFile.java
// public interface ClassFile {
//
// @NotNull String getName();
//
// @NotNull byte[] getBinaries();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/CompilationResult.java
// public interface CompilationResult extends Result<Collection<TestSource>> {
//
// /**
// * @return compiled classes. We use a {@link Supplier} here because there is a possible case that
// * compilation is failed and the test wants to check its {@code stderr}. We return a collection
// * of {@link ClassFile} because a single source file might result in multiple binaries after
// * compilation, e.g. when an inner/anonymous classes are involved
// */
// @NotNull
// Supplier<Collection<ClassFile>> getCompiledClassesSupplier();
//
// /**
// * @return compiler's output generated during processing {@link #getInput() target binaries}
// */
// @NotNull
// String getCompilationOutput();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/RunResult.java
// public interface RunResult extends Result<CompilationResult> {
//
// @NotNull
// Optional<Throwable> getException();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/api/model/TestSource.java
// public interface TestSource {
//
// /**
// * @return complete test source
// */
// @NotNull
// String getSourceText();
//
// /**
// * @return qualified class name for the given test source
// */
// @NotNull
// String getQualifiedClassName();
// }
//
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/model/RunResultImpl.java
// public class RunResultImpl implements RunResult {
//
// @NotNull private final CompilationResult input;
// @Nullable private final Throwable exception;
//
// public RunResultImpl(@NotNull CompilationResult input, @Nullable Throwable exception) {
// this.input = input;
// this.exception = exception;
// }
//
// @Override
// @NotNull
// public Optional<Throwable> getException() {
// return Optional.ofNullable(exception);
// }
//
// @NotNull
// @Override
// public CompilationResult getInput() {
// return input;
// }
// }
//
// Path: core/common/src/main/java/tech/harmonysoft/oss/traute/common/util/TrauteConstants.java
// public static final String PACKAGE_INFO = "package-info";
// Path: core/test/src/test/java/tech/harmonysoft/oss/traute/test/impl/engine/TrauteInMemoryTestRunner.java
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.test.api.engine.TestRunner;
import tech.harmonysoft.oss.traute.test.api.model.ClassFile;
import tech.harmonysoft.oss.traute.test.api.model.CompilationResult;
import tech.harmonysoft.oss.traute.test.api.model.RunResult;
import tech.harmonysoft.oss.traute.test.api.model.TestSource;
import tech.harmonysoft.oss.traute.test.impl.model.RunResultImpl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static tech.harmonysoft.oss.traute.common.util.TrauteConstants.PACKAGE_INFO;
package tech.harmonysoft.oss.traute.test.impl.engine;
public class TrauteInMemoryTestRunner implements TestRunner {
public static final TrauteInMemoryTestRunner INSTANCE = new TrauteInMemoryTestRunner();
/** Arguments to call {@code main()} in the compiled test sources. */
private static final Object[] MAIN_ARGUMENTS = { new String[0]};
@Override
@NotNull
public RunResult run(@NotNull CompilationResult compilationResult) {
Map<String, byte[]> compiled = compilationResult.getCompiledClassesSupplier().get()
.stream()
.collect(toMap(ClassFile::getName,
ClassFile::getBinaries));
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) {
byte[] compiledBinaries = compiled.get(name);
if (compiledBinaries == null) {
throw new IllegalArgumentException(String.format(
"Can't find compiled binaries for class %s. Available binaries found for %s",
name, compiled.keySet()
));
}
return defineClass(name, compiledBinaries, 0, compiledBinaries.length);
}
};
Class<?> clazz;
try {
clazz = classLoader.loadClass(getStartClass(compilationResult.getInput()));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Can't load compiled test class", e);
}
Method method;
try {
method = clazz.getMethod("main", String[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find the 'main()' method in the compiled test class", e);
}
try {
method.invoke(null, MAIN_ARGUMENTS);
return new RunResultImpl(compilationResult, null);
} catch (IllegalAccessException e) {
return new RunResultImpl(compilationResult, e);
} catch (InvocationTargetException e) {
return new RunResultImpl(compilationResult, e.getCause());
}
}
@NotNull
private static String getStartClass(@NotNull Collection<TestSource> testSources) {
for (TestSource testSource : testSources) {
String candidate = testSource.getQualifiedClassName(); | if (!PACKAGE_INFO.equals(candidate)) { |