<commit_before>package com.nutomic.syncthingandroid.syncthing;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.util.Log;
import android.view.WindowManager;

import com.nutomic.syncthingandroid.R;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Runs the syncthing binary from command line, and prints its output to logcat.
 */
public class SyncthingRunnable implements Runnable {

    private static final String TAG = "SyncthingRunnable";

    private static final String TAG_NATIVE = "SyncthingNativeCode";

    /**
     * Path to the native, integrated syncthing binary, relative to the data folder
     */
    private static final String BINARY_NAME = "lib/libsyncthing.so";

    private Handler mHandler;

    private Context mContext;

    public SyncthingRunnable(Context context) {
        mContext = context;
        mHandler = new Handler();
    }

    @Override
    public void run() {
        DataOutputStream dos = null;
        int ret = 1;
        Process process = null;
        try	{
            process = Runtime.getRuntime().exec("sh");
            dos = new DataOutputStream(process.getOutputStream());
            // Set home directory to data folder for syncthing to use.
            dos.writeBytes("HOME=" + mContext.getFilesDir() + " ");
            // Call syncthing with -home (as it would otherwise use "~/.config/syncthing/".
            dos.writeBytes(mContext.getApplicationInfo().dataDir + "/" + BINARY_NAME + " " +
                    "-home " + mContext.getFilesDir() + "\n");
            dos.writeBytes("exit\n");
            dos.flush();

            log(process.getErrorStream());

            ret = process.waitFor();
        }
        catch(IOException | InterruptedException e) {
            Log.e(TAG, "Failed to execute syncthing binary or read output", e);
        }
        finally {
            try {
                dos.close();
            }
            catch (IOException e) {
                Log.w(TAG, "Failed to close shell stream", e);
            }
            process.destroy();
            final int retVal = ret;
            if (ret != 0) {
				Log.w(TAG_NATIVE, "Syncthing binary crashed with error code " + Integer.toString(retVal));
				postCrashDialog(retVal);
            }
        }<commit_msg>Use correct stream for syncthing output.<commit_after>package com.nutomic.syncthingandroid.syncthing;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.util.Log;
import android.view.WindowManager;

import com.nutomic.syncthingandroid.R;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Runs the syncthing binary from command line, and prints its output to logcat.
 */
public class SyncthingRunnable implements Runnable {

    private static final String TAG = "SyncthingRunnable";

    private static final String TAG_NATIVE = "SyncthingNativeCode";

    /**
     * Path to the native, integrated syncthing binary, relative to the data folder
     */
    private static final String BINARY_NAME = "lib/libsyncthing.so";

    private Handler mHandler;

    private Context mContext;

    public SyncthingRunnable(Context context) {
        mContext = context;
        mHandler = new Handler();
    }

    @Override
    public void run() {
        DataOutputStream dos = null;
        int ret = 1;
        Process process = null;
        try	{
            process = Runtime.getRuntime().exec("sh");
            dos = new DataOutputStream(process.getOutputStream());
            // Set home directory to data folder for syncthing to use.
            dos.writeBytes("HOME=" + mContext.getFilesDir() + " ");
            // Call syncthing with -home (as it would otherwise use "~/.config/syncthing/".
            dos.writeBytes(mContext.getApplicationInfo().dataDir + "/" + BINARY_NAME + " " +
                    "-home " + mContext.getFilesDir() + "\n");
            dos.writeBytes("exit\n");
            dos.flush();

            log(process.getInputStream());

            ret = process.waitFor();
        }
        catch(IOException | InterruptedException e) {
            Log.e(TAG, "Failed to execute syncthing binary or read output", e);
        }
        finally {
            try {
                dos.close();
            }
            catch (IOException e) {
                Log.w(TAG, "Failed to close shell stream", e);
            }
            process.destroy();
            final int retVal = ret;
            if (ret != 0) {
				Log.w(TAG_NATIVE, "Syncthing binary crashed with error code " + Integer.toString(retVal));
				postCrashDialog(retVal);
            }
        }
{'fraction_non_alphanumeric': 0.10255893612734233, 'fraction_numerical': 0.0008059641345960105, 'mean_word_length': 2.3159652638610555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2772075', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1325, 'n_words': 369}