<commit_before>/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.hellojni;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.Activity;
import android.content.res.AssetManager;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;


public class HelloJni extends Activity
{
	
	String mDBdir;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        /*
         * Use the files dir to store the database /data/data/package..../db
         */
        mDBdir =  this.getFilesDir().getAbsolutePath() + File.separator+"db" ;
		new File(mDBdir).mkdirs();
		
    }
    
    @Override
	protected void onResume() {
    	/*
    	 * Sample Database code:
    	 * Open the database using the path to its directory
    	 * Insert some keys,
    	 * Delete a key, 
    	 * Create a TextView and show the value of a key retrieved from the DB.
    	 */
		dbOpen(mDBdir);
		dbPut("firstkey","this is the value of the first key");
		dbPut("secondkey","this is the value of the first key");
		dbPut("keyToDelete","this is the value of the key that i want to delete");
		dbPut("fourthkey","this is the value of the fourth key");
		dbDelete("keyToDelete");
		
		TextView  tv = new TextView(this);
		tv.setText( dbGet("fourthkey")  );
        setContentView(tv);
        
        
        try {
        	AssetManager assetManager = getAssets();
    	  	InputStream in = assetManager.open("sample.json");
    	  	BufferedReader sourcefile = new BufferedReader(new InputStreamReader(in, "UTF-8"));
    	  	String contents = "";
    	  	String line = "";
    	  	int linecount=0;
    	  	while ((line = sourcefile.readLine()) != null) {
    	  		//contents = contents+"\n"+line;
    	  		dbPut("element"+linecount, line);
    	  		linecount++;
    	  	}
    	  	sourcefile.close();
    	  	int j = linecount-1;
			tv.setText( dbGet("element"+j) );
	        setContentView(tv);
//    	  	JSONArray json = new JSONArray(contents);
//			for(int i = 0; i< json.length(); i++){
//				dbPut("element"+i, json.get(i).toString());
//			}
//			int j = json.length()-1;
//			tv.setText( dbGet("element"+j) );
//	        setContentView(tv);
	        
		} catch (IOException e) {
			Toast.makeText(this, "File read problem"+e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
		} 
//        catch (JSONException e) {
//			Toast.makeText(this, "Json problem"+e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
//		}

		
        
        
		super.onResume();<commit_msg>reading in a sample json and iterating over its keys to insert key value pairs in db<commit_after>/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.hellojni;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.Activity;
import android.content.res.AssetManager;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;


public class HelloJni extends Activity
{
	
	String mDBdir;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        /*
         * Use the files dir to store the database /data/data/package..../db
         */
        mDBdir =  this.getFilesDir().getAbsolutePath() + File.separator+"db" ;
		new File(mDBdir).mkdirs();
		
    }
    
    @Override
	protected void onResume() {
    	/*
    	 * Sample Database code:
    	 * Open the database using the path to its directory
    	 * Insert some keys,
    	 * Delete a key, 
    	 * Create a TextView and show the value of a key retrieved from the DB.
    	 */
		dbOpen(mDBdir);
		dbPut("firstkey","this is the value of the first key");
		dbPut("secondkey","this is the value of the first key");
		dbPut("keyToDelete","this is the value of the key that i want to delete");
		dbPut("fourthkey","this is the value of the fourth key");
		dbDelete("keyToDelete");
		
		TextView  tv = new TextView(this);
		tv.setText( dbGet("fourthkey")  );
        setContentView(tv);
        
        
        try {
        	AssetManager assetManager = getAssets();
    	  	InputStream in = assetManager.open("sample.json");
    	  	BufferedReader sourcefile = new BufferedReader(new InputStreamReader(in, "UTF-8"));
    	  	String contents = "";
    	  	String line = "";
    	  	while ((line = sourcefile.readLine()) != null) {
    	  		contents = contents+"\n"+line;
    	  	}
    	  	sourcefile.close();
    	  	JSONObject json = new JSONObject(contents);
			Iterator<String> keys = json.keys();
    	    while (keys.hasNext()) {
    	        String key = (String) keys.next();
    	        dbPut(key, json.get(key).toString());
    	    }
			int j = json.length()-1;
			tv.setText( "element"+j );
	        setContentView(tv);
	        
		} catch (IOException e) {
			Toast.makeText(this, "File read problem"+e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
			tv.setText( "File read problem"+e.getLocalizedMessage() );
	        setContentView(tv);
		} 
        catch (JSONException e) {
			Toast.makeText(this, "Json problem"+e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
			tv.setText( "JSON problem"+e.getLocalizedMessage() );
        	setContentView(tv);
        }

		
        
        
		super.onResume();
{'fraction_non_alphanumeric': 0.11428970136756908, 'fraction_numerical': 0.0032096008931063354, 'mean_word_length': 2.9444138690148596, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '3732769', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2118, 'n_words': 632}