<commit_before>package com.frostwire.jlibtorrent.demo;

import com.frostwire.jlibtorrent.*;
import com.frostwire.jlibtorrent.alerts.*;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * @author gubatron
 * @author aldenml
 */
public final class DhtShell {

    public static void main(String[] args) throws Throwable {

        System.out.println("Using libtorrent version: " + LibTorrent.fullVersion());

        AlertListener mainListener = new AlertListener() {
            @Override
            public int[] types() {
                return null;
            }

            @Override
            public void alert(Alert<?> alert) {
                AlertType type = alert.getType();
                log(alert.getMessage());

                if (type == AlertType.LISTEN_SUCCEEDED) {
                    ListenSucceededAlert a = (ListenSucceededAlert) alert;
                    log(a.getMessage());
                }

                if (type == AlertType.LISTEN_FAILED) {
                    ListenFailedAlert a = (ListenFailedAlert) alert;
                    log(a.getMessage());
                }

                if (type == AlertType.DHT_PUT) {
                    DhtPutAlert a = (DhtPutAlert) alert;
                    log(a.getMessage());
                }
            }
        };

        Session s = new Session("0.0.0.0", 33123, 10, false, mainListener);
        DHT dht = new DHT(s);

        try {
            File f = new File("dht_shell.dat");
            if (f.exists()) {
                byte[] data = Utils.readFileToByteArray(f);
                s.loadState(data);
            }
        } catch (Throwable e) {
            log(e.getMessage());
        }

        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("$ ");

            String line = in.nextLine().trim();

            if (is_quit(line)) {
                quit(s);
            } else if (is_put(line)) {
                put(dht, line);
            } else if (is_invalid(line)) {
                invalid(line);
            }
        }
    }

    private static void print(String s, boolean dollar) {
        System.out.println();
        System.out.println(s);
        if (dollar) {
            System.out.print("$ ");
        }
    }

    private static void print(String s) {
        print(s, false);
    }

    private static void log(String s) {
        print(s, true);
    }

    private static boolean is_quit(String s) {
        s = s.split(" ")[0];
        return s.equals("quit") || s.equals("exit") || s.equals("stop");
    }

    private static void quit(Session s) {
        print("Exiting...");
        s.saveState();
        byte[] data = s.saveState();
        try {
            Utils.writeByteArrayToFile(new File("dht_shell.dat"), data, false);
        } catch (Throwable e) {
            print(e.getMessage());
        }
        s.abort();
        System.exit(0);
    }

    private static boolean is_put(String s) {
        return s.startsWith("put ");
    }

    private static void put(DHT dht, String s) {
        String data = s.split(" ")[1];
        String key = dht.put(new Entry(data));
        print("Wait for completion of put for key: " + key);
    }

    private static boolean is_invalid(String s) {
        return !s.isEmpty();
    }
<commit_msg>DhtShell get operation<commit_after>package com.frostwire.jlibtorrent.demo;

import com.frostwire.jlibtorrent.*;
import com.frostwire.jlibtorrent.alerts.*;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * @author gubatron
 * @author aldenml
 */
public final class DhtShell {

    public static void main(String[] args) throws Throwable {

        System.out.println("Using libtorrent version: " + LibTorrent.fullVersion());

        AlertListener mainListener = new AlertListener() {
            @Override
            public int[] types() {
                return null;
            }

            @Override
            public void alert(Alert<?> alert) {
                AlertType type = alert.getType();

                if (type == AlertType.LISTEN_SUCCEEDED) {
                    ListenSucceededAlert a = (ListenSucceededAlert) alert;
                    log(a.getMessage());
                }

                if (type == AlertType.LISTEN_FAILED) {
                    ListenFailedAlert a = (ListenFailedAlert) alert;
                    log(a.getMessage());
                }

                if (type == AlertType.DHT_PUT) {
                    DhtPutAlert a = (DhtPutAlert) alert;
                    log(a.getMessage());
                }
            }
        };

        Session s = new Session("0.0.0.0", 33123, 10, false, mainListener);
        DHT dht = new DHT(s);

        try {
            File f = new File("dht_shell.dat");
            if (f.exists()) {
                byte[] data = Utils.readFileToByteArray(f);
                s.loadState(data);
            }
        } catch (Throwable e) {
            log(e.getMessage());
        }

        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("$ ");

            String line = in.nextLine().trim();

            if (is_quit(line)) {
                quit(s);
            } else if (is_put(line)) {
                put(dht, line);
            } else if (is_get(line)) {
                get(dht, line);
            } else if (is_invalid(line)) {
                invalid(line);
            }
        }
    }

    private static void print(String s, boolean dollar) {
        System.out.println();
        System.out.println(s);
        if (dollar) {
            System.out.print("$ ");
        }
    }

    private static void print(String s) {
        print(s, false);
    }

    private static void log(String s) {
        print(s, true);
    }

    private static boolean is_quit(String s) {
        s = s.split(" ")[0];
        return s.equals("quit") || s.equals("exit") || s.equals("stop");
    }

    private static void quit(Session s) {
        print("Exiting...");
        s.saveState();
        byte[] data = s.saveState();
        try {
            Utils.writeByteArrayToFile(new File("dht_shell.dat"), data, false);
        } catch (Throwable e) {
            print(e.getMessage());
        }
        s.abort();
        System.exit(0);
    }

    private static boolean is_put(String s) {
        return s.startsWith("put ");
    }

    private static void put(DHT dht, String s) {
        String data = s.split(" ")[1];
        String key = dht.put(new Entry(data));
        print("Wait for completion of put for key: " + key);
    }

    private static boolean is_get(String s) {
        return s.startsWith("get ");
    }

    private static void get(DHT dht, String s) {
        String sha1 = s.split(" ")[1];
        Entry data = dht.get(sha1, 20000);
        print("Waiting a max of 20 seconds to get data for key: " + sha1);
        print(data.toString());
    }

    private static boolean is_invalid(String s) {
        return !s.isEmpty();
    }

{'fraction_non_alphanumeric': 0.12666666666666668, 'fraction_numerical': 0.005531914893617021, 'mean_word_length': 1.5999262536873156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5829228', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2023, 'n_words': 479}