public GatewayConnection(Gateway gateway, Socket socket, String authToken,
List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners) throws IOException {
super();
this.socket = socket;
this.authToken = authToken;
if (authToken != null) {
this.authCommand = new AuthCommand(authToken);
} else {
this.authCommand = null;
}
this.reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), Charset.forName("UTF-8")));
this.writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), Charset.forName("UTF-8")));
this.commands = new HashMap<String, Command>();
initCommands(gateway, baseCommands);
if (customCommands != null) {
initCommands(gateway, customCommands);
}
if (authCommand != null) {
initCommand(gateway, authCommand);
}
this.listeners = listeners;
}