<commit_before>package data;

import crypto.CryptoConstants;
import crypto.Cryptography;

import java.security.PublicKey;
import java.sql.*;

/**
 * @author <NAME>
 * @version 11/30/13
 */
public class SQLiteManager {
    // suggestion: using the jdbc pooling method described here:
    // http://www.javaranch.com/journal/200601/JDBCConnectionPooling.html
    private String url;

    public SQLiteManager(String db) {
        try {
            Class.forName("org.sqlite.JDBC");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        this.url = "jdbc:sqlite:" + db;
    }

    public PublicKey getPublicKeyFromId(String receiverId) {
        String query = "SELECT public_key FROM user";
        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        System.out.println(CryptoConstants.asymm_keylength / 8);
        byte[] publicKeyBytes = new byte[CryptoConstants.asymm_keylength / 8];

        System.out.println(publicKeyBytes.length);

        for(int i = 0; i < publicKeyBytes.length; i++)
            publicKeyBytes[i] = (byte)0;

        try {
            connection = DriverManager.getConnection(url);
            statement = connection.createStatement();
            rs = statement.executeQuery(query);
            while (rs.next()) {
                publicKeyBytes = rs.getBlob("public_key").getBytes(0, CryptoConstants.asymm_keylength / 8);
            }
        } catch (SQLException e) {
            System.err.println(e.getMessage());
        } finally {
            try {
                if (rs != null) rs.close();
                if (statement != null) statement.close();
                if (connection != null) connection.close();
            } catch (SQLException ignored) {
            }
        }

        return Cryptography.getPublicKeyFromBytes(publicKeyBytes);
    }

    public void insertUser(User user){
        // String query = String.format("INSERT INTO user VALUES ()
    }
}<commit_msg>Insert into User works now<commit_after>package data;

import crypto.CryptoConstants;
import crypto.Cryptography;

import java.io.Writer;
import java.security.PublicKey;
import java.sql.*;
import java.util.ArrayList;

/**
 * @author <NAME>
 * @version 11/30/13
 */
public class SQLiteManager {
    // suggestion: using the jdbc pooling method described here:
    // http://www.javaranch.com/journal/200601/JDBCConnectionPooling.html
    private String url;

    public SQLiteManager(String db) {
        try {
            Class.forName("org.sqlite.JDBC");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        this.url = "jdbc:sqlite:" + db;
    }

    public PublicKey getPublicKeyFromId(String receiverId) {
        String query = "SELECT public_key FROM user";
        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        System.out.println(CryptoConstants.asymm_keylength / 8);
        byte[] publicKeyBytes = new byte[CryptoConstants.asymm_keylength / 8];

        System.out.println(publicKeyBytes.length);

        for(int i = 0; i < publicKeyBytes.length; i++)
            publicKeyBytes[i] = (byte)0;

        try {
            connection = DriverManager.getConnection(url);
            statement = connection.createStatement();
            rs = statement.executeQuery(query);
            while (rs.next()) {
                publicKeyBytes = rs.getBlob("public_key").getBytes(0, CryptoConstants.asymm_keylength / 8);
            }
        } catch (SQLException e) {
            System.err.println(e.getMessage());
        } finally {
            try {
                if (rs != null) rs.close();
                if (statement != null) statement.close();
                if (connection != null) connection.close();
            } catch (SQLException ignored) {
            }
        }

        return Cryptography.getPublicKeyFromBytes(publicKeyBytes);
    }

    public void insertUser(User user){
        String sql = "INSERT INTO user VALUES(?,?,?) ";
        try (Connection connection = DriverManager.getConnection(url);
             PreparedStatement pstmt = connection.prepareStatement(sql);
            ){
            Blob publicKeyBlob, symmetricKeyBlob;
            pstmt.setString(1, user.getId());

            publicKeyBlob = connection.createBlob();
            publicKeyBlob.setBytes(0, user.getKeyPair().getPublic().getEncoded());
            pstmt.setBlob(2, publicKeyBlob);

            symmetricKeyBlob = connection.createBlob();
            symmetricKeyBlob.setBytes(0, user.getSecretKey().getEncoded());
            pstmt.setBlob(3, symmetricKeyBlob);

            pstmt.executeUpdate();
        } catch (SQLException ex) {
            System.out.println("Unexpected exception: " + ex.toString());
        }
    }

    /**
     * Load the names of all users
     * @return the name of all users
     */
    public ArrayList<String> loadUsers(){
        return null;
    }
}
{'fraction_non_alphanumeric': 0.11175529788084766, 'fraction_numerical': 0.00819672131147541, 'mean_word_length': 2.209108402822322, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '227783', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1342, 'n_words': 300}