<commit_before>/**
 * ##library.name##
 * ##library.sentence##
 * ##library.url##
 *
 * Copyright ##copyright## ##author##
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 * 
 * @author      ##author##
 * @modified    ##date##
 * @version     ##library.prettyVersion## (##library.version##)
 */

package processing.mqtt;

import java.lang.*;
import java.lang.Class;
import java.lang.reflect.*;
import java.lang.Exception;
import java.lang.Override;
import java.lang.String;
import java.lang.System;
import java.lang.Throwable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;

import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import processing.core.PApplet;

/**
 * An MQTTClient that can publish and subscribe.
 *
 * @example PublishSubscribe
 */

public class MQTTClient implements MqttCallback {
	PApplet parent;

	Method messageReceivedMethod;

	public MqttClient client;

	/**
	 * a Constructor, usually called in the setup() method in your sketch to
	 * initialize and start the library.
	 * 
	 * @example PublishSubscribe
	 * @param theParent
	 */
	public MQTTClient(PApplet theParent) {
		parent = theParent;
		parent.registerMethod("dispose", this);
		messageReceivedMethod = findCallback("messageReceived");
		System.out.println("##library.name## ##library.prettyVersion## by ##author##");
	}

	public void connect(String theUri, String theID) {
		URI uri = null;
		try {
			uri = new URI(theUri);
		} catch(URISyntaxException e) {
			System.out.println("[MQTT] failed to parse URI: " + e.getMessage());
		}

		try {
			MqttConnectOptions options = new MqttConnectOptions();

			String[] auth = uri.getUserInfo().split(":");
			if(auth.length > 0) {
				String user = auth[0];
				String pass = auth[1];
				options.setUserName(user);
				options.setPassword(<PASSWORD>());
			}

			client = new MqttClient("tcp://" + uri.getHost(), theID);
			client.setCallback(this);
			client.connect(options);
		} catch (MqttException e) {
			System.out.println("[MQTT] failed to connect: " + e.getMessage());
		}
	}

	public void publish(String topic, String payload) {
		try {
			client.publish(topic, payload.getBytes(Charset.forName("UTF-8")), 0, false);
		} catch (MqttException e) {
			System.out.println("[MQTT] failed to publish: " + e.getMessage());
		}
	}

	public void subscribe(String topic) {
		try {<commit_msg>added log for connect<commit_after>/**
 * ##library.name##
 * ##library.sentence##
 * ##library.url##
 *
 * Copyright ##copyright## ##author##
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 * 
 * @author      ##author##
 * @modified    ##date##
 * @version     ##library.prettyVersion## (##library.version##)
 */

package processing.mqtt;

import java.lang.*;
import java.lang.Class;
import java.lang.reflect.*;
import java.lang.Exception;
import java.lang.Override;
import java.lang.String;
import java.lang.System;
import java.lang.Throwable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;

import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import processing.core.PApplet;

/**
 * An MQTTClient that can publish and subscribe.
 *
 * @example PublishSubscribe
 */

public class MQTTClient implements MqttCallback {
	PApplet parent;

	Method messageReceivedMethod;

	public MqttClient client;

	/**
	 * a Constructor, usually called in the setup() method in your sketch to
	 * initialize and start the library.
	 * 
	 * @example PublishSubscribe
	 * @param theParent
	 */
	public MQTTClient(PApplet theParent) {
		parent = theParent;
		parent.registerMethod("dispose", this);
		messageReceivedMethod = findCallback("messageReceived");
		System.out.println("##library.name## ##library.prettyVersion## by ##author##");
	}

	public void connect(String theUri, String theID) {
		URI uri = null;
		try {
			uri = new URI(theUri);
		} catch(URISyntaxException e) {
			System.out.println("[MQTT] failed to parse URI: " + e.getMessage());
		}

		try {
			MqttConnectOptions options = new MqttConnectOptions();

			String[] auth = uri.getUserInfo().split(":");
			if(auth.length > 0) {
				String user = auth[0];
				String pass = auth[1];
				options.setUserName(user);
				options.setPassword(<PASSWORD>());
			}

			client = new MqttClient("tcp://" + uri.getHost(), theID);
			client.setCallback(this);
			client.connect(options);

			System.out.println("[MQTT] connected to: " + uri.getHost());
		} catch (MqttException e) {
			System.out.println("[MQTT] failed to connect: " + e.getMessage());
		}
	}

	public void publish(String topic, String payload) {
		try {
			client.publish(topic, payload.getBytes(Charset.forName("UTF-8")), 0, false);
		} catch (MqttException e) {
			System.out.println("[MQTT] failed to publish: " + e.getMessage());
		}
	}

	public void subscribe(String topic) {
		try {
{'fraction_non_alphanumeric': 0.12373552265063774, 'fraction_numerical': 0.008209939891511508, 'mean_word_length': 4.133182844243792, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3086830', 'n_tokens_mistral': 2281, 'n_tokens_neox': 2103, 'n_words': 613}