<commit_before>package com.github.ghostpassword.ghostpasswordbackend;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.ParcelUuid;
import android.util.Log;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Set;

/**
 * Created by udeyoje on 10/2/15.
 */
public class BlueToothDao {

    private OutputStream outputStream;
    private BluetoothSocket socket;

    public  BlueToothDao() {
        BluetoothAdapter blueAdapter = BluetoothAdapter.getDefaultAdapter();
        if (blueAdapter != null) {
            if (blueAdapter.isEnabled()) {
                Set<BluetoothDevice> bondedDevices = blueAdapter.getBondedDevices();

                if (bondedDevices.size() > 0) {
                    ArrayList<BluetoothDevice> devices = new ArrayList<>();
                    for (BluetoothDevice device : bondedDevices) {
                        devices.add(device);
                    }
                    BluetoothDevice device = devices.get(0);
                    ParcelUuid[] uuids = device.getUuids();
                    BluetoothSocket socket = null;
                    try {
                        socket = device.createRfcommSocketToServiceRecord(uuids[0].getUuid());
                        socket.connect();
                        outputStream = socket.getOutputStream();
                    } catch (IOException | ArrayIndexOutOfBoundsException | IllegalStateException | NullPointerException e) {
                        e.printStackTrace();
                        System.out.println("\n--------------------Could not connect to bluetooth device!---------------\n");
                        //TODO: error handling here -- display a message or something
                    }

                } else {
                    Log.e("error", "No appropriate paired devices.");
                }
            } else {
                Log.e("error", "Bluetooth is disabled.");
            }
        }

    }

    public void write(String s) throws IOException {
        if (outputStream == null) {
            System.out.println("Output stream is null.");
        }
        s = "Abcdefgh";
        System.out.println("\n\tWriting string to bluetooth: " + s); //TODO: take this out!
        outputStream.flush();
        outputStream.write(s.getBytes());
        outputStream.flush();
        try{Thread.sleep(1000);}catch (Exception e){}
    }

    public void close() {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }<commit_msg>cleanup<commit_after>package com.github.ghostpassword.ghostpasswordbackend;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.ParcelUuid;
import android.util.Log;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Set;

/**
 * Created by udeyoje on 10/2/15.
 */
public class BlueToothDao {

    private OutputStream outputStream;
    private BluetoothSocket socket;

    public  BlueToothDao() {
        BluetoothAdapter blueAdapter = BluetoothAdapter.getDefaultAdapter();
        if (blueAdapter != null) {
            if (blueAdapter.isEnabled()) {
                Set<BluetoothDevice> bondedDevices = blueAdapter.getBondedDevices();

                if (bondedDevices.size() > 0) {
                    ArrayList<BluetoothDevice> devices = new ArrayList<>();
                    for (BluetoothDevice device : bondedDevices) {
                        devices.add(device);
                    }
                    BluetoothDevice device = devices.get(0);
                    ParcelUuid[] uuids = device.getUuids();
                    BluetoothSocket socket = null;
                    try {
                        socket = device.createRfcommSocketToServiceRecord(uuids[0].getUuid());
                        socket.connect();
                        outputStream = socket.getOutputStream();
                    } catch (IOException | ArrayIndexOutOfBoundsException | IllegalStateException | NullPointerException e) {
                        e.printStackTrace();
                        System.out.println("\n--------------------Could not connect to bluetooth device!---------------\n");
                        //TODO: error handling here -- display a message or something
                    }

                } else {
                    Log.e("error", "No appropriate paired devices.");
                }
            } else {
                Log.e("error", "Bluetooth is disabled.");
            }
        }

    }

    public void write(String s) throws IOException {
        if (outputStream == null) {
            System.out.println("Output stream is null.");
        }
        System.out.println("\n\tWriting string to bluetooth: " + s); //TODO: take this out!
        outputStream.flush();
        outputStream.write(s.getBytes());
        outputStream.flush();
        try{Thread.sleep(1000);}catch (Exception e){}
    }

    public void close() {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
{'fraction_non_alphanumeric': 0.11164510166358595, 'fraction_numerical': 0.0044362292051756, 'mean_word_length': 1.713640922768305, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4906863', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1281, 'n_words': 296}