<commit_before>/*
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */

package samples.com.microsoft.azure.iot.service.sdk;

import com.microsoft.azure.iot.service.sdk.*;
import org.apache.commons.codec.binary.Base64;

import javax.jms.JMSException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * Service client example for:
 *  - sending message to the device
 *  - waiting and receive feedback from the device
 */
public class ServiceClientSample
{
    private static final String connectionString = "[Connection string goes here]";
    private static final String deviceId = "[Device name goes here]";
    private static final String primaryKey = "[New primary key goes here]";
    private static final String secondaryKey = "[New secondary key goes here]";

    private static ServiceClient serviceClient = null;
    private static FeedbackReceiver feedbackReceiver = null;

    /**
     * @param args
     * @throws IOException
     * @throws URISyntaxException
     */
    public static void main(String[] args) throws IOException, URISyntaxException, Exception
    {
        System.out.println("\n********* Starting ServiceClient sample...\n");

        openServiceClient();
        openFeedbackReceiver();

        Message commandMessage = new Message(Base64.decodeBase64("Cloud to device message.".getBytes(StandardCharsets.UTF_8)));

        System.out.printf("\n********* Sending message to device...\n");

        CompletableFuture<Void> completableFuture = serviceClient.sendAsync(deviceId, commandMessage);
        completableFuture.get();

        System.out.printf("\n********* Waiting for feedback...\n");
        CompletableFuture<FeedbackBatch> future = feedbackReceiver.receiveAsync();

        FeedbackBatch feedbackBatch = future.get();
        System.out.printf("\n********* FEEDBACK TIME: " + feedbackBatch.getEnqueuedTimeUtc().toString() + "\n");

        closeFeedbackReceiver();
        closeServiceClient();

        System.out.println("\n********* Shutting down ServiceClient sample...\n");
    }

    protected static void openServiceClient() throws Exception
    {
        System.out.println("Creating ServiceClient...");
        serviceClient = ServiceClient.createFromConnectionString(connectionString);
        CompletableFuture<Void> future = serviceClient.openAsync();
        future.get();
        System.out.println("********* Successfully created an ServiceClient.\n");
    }<commit_msg>Removed double decoding of text message in the sample application<commit_after>/*
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */

package samples.com.microsoft.azure.iot.service.sdk;

import com.microsoft.azure.iot.service.sdk.FeedbackBatch;
import com.microsoft.azure.iot.service.sdk.FeedbackReceiver;
import com.microsoft.azure.iot.service.sdk.Message;
import com.microsoft.azure.iot.service.sdk.ServiceClient;

import javax.jms.JMSException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * Service client example for:
 *  - sending message to the device
 *  - waiting and receive feedback from the device
 */
public class ServiceClientSample
{
    private static final String connectionString = "[Connection string goes here]";
    private static final String deviceId = "[Device name goes here]";
    private static final String primaryKey = "[New primary key goes here]";
    private static final String secondaryKey = "[New secondary key goes here]";

    private static ServiceClient serviceClient = null;
    private static FeedbackReceiver feedbackReceiver = null;

    /**
     * @param args
     * @throws IOException
     * @throws URISyntaxException
     */
    public static void main(String[] args) throws IOException, URISyntaxException, Exception
    {
        System.out.println("\n********* Starting ServiceClient sample...\n");

        openServiceClient();
        openFeedbackReceiver();

        Message commandMessage = new Message("Cloud to device message...".getBytes(StandardCharsets.UTF_8));

        System.out.printf("\n********* Sending message to device...\n");

        CompletableFuture<Void> completableFuture = serviceClient.sendAsync(deviceId, commandMessage);
        completableFuture.get();

        System.out.printf("\n********* Waiting for feedback...\n");
        CompletableFuture<FeedbackBatch> future = feedbackReceiver.receiveAsync();

        FeedbackBatch feedbackBatch = future.get();
        System.out.printf("\n********* FEEDBACK TIME: " + feedbackBatch.getEnqueuedTimeUtc().toString() + "\n");

        closeFeedbackReceiver();
        closeServiceClient();

        System.out.println("\n********* Shutting down ServiceClient sample...\n");
    }

    protected static void openServiceClient() throws Exception
    {
        System.out.println("Creating ServiceClient...");
        serviceClient = ServiceClient.createFromConnectionString(connectionString);
        CompletableFuture<Void> future = serviceClient.openAsync();
        future.get();
        System.out.println("********* Successfully created an ServiceClient.\n");
    }
{'fraction_non_alphanumeric': 0.12015852999459557, 'fraction_numerical': 0.0014411817690506215, 'mean_word_length': 3.7779690189328745, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3116461', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1372, 'n_words': 387}