<commit_before>package org.wikimedia.wikipedia.savedpages;

import android.content.Context;
import android.provider.MediaStore;
import org.json.JSONException;
import org.json.JSONObject;
import org.wikimedia.wikipedia.Page;
import org.wikimedia.wikipedia.PageTitle;
import org.wikimedia.wikipedia.data.ContentPersister;

import java.io.*;

public class SavedPagePerister extends ContentPersister<SavedPage> {
    private final Context context;
    public SavedPagePerister(Context context) {
        // lolJava
        super(
                context.getContentResolver().acquireContentProviderClient(
                        SavedPage.persistanceHelper.getBaseContentURI()
                ),
                SavedPage.persistanceHelper
        );
        this.context = context;
    }

    private String getSavePageName(PageTitle title) {
        return "savedpage-" + title.getHashedItentifier();
    }


    public void savePageContent(Page page) throws IOException {
        FileOutputStream out = context.openFileOutput(getSavePageName(page.getTitle()), Context.MODE_PRIVATE);
        try {
            out.write(page.toJSON().toString().getBytes("utf-8"));
        } catch (IOException e) {
            // Won't happen. EVER. JESUS CHRIST, Java!
            throw new RuntimeException(e);
        }
        out.close();
    }

    public Page loadPageContent(PageTitle title) throws IOException {
        FileInputStream in = context.openFileInput(getSavePageName(title));

        BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
        String contents = reader.readLine();
        if (reader.readLine() != null) {
            // Somehow we have a newline in there! THROW UP!
            throw new RuntimeException("Raw newline found in Saved Page for " + title);
        }
        try {
            return new Page(new JSONObject(contents));<commit_msg>Ensure we close opened files<commit_after>package org.wikimedia.wikipedia.savedpages;

import android.content.Context;
import android.provider.MediaStore;
import org.json.JSONException;
import org.json.JSONObject;
import org.wikimedia.wikipedia.Page;
import org.wikimedia.wikipedia.PageTitle;
import org.wikimedia.wikipedia.data.ContentPersister;

import java.io.*;

public class SavedPagePerister extends ContentPersister<SavedPage> {
    private final Context context;
    public SavedPagePerister(Context context) {
        // lolJava
        super(
                context.getContentResolver().acquireContentProviderClient(
                        SavedPage.persistanceHelper.getBaseContentURI()
                ),
                SavedPage.persistanceHelper
        );
        this.context = context;
    }

    private String getSavePageName(PageTitle title) {
        return "savedpage-" + title.getHashedItentifier();
    }


    public void savePageContent(Page page) throws IOException {
        FileOutputStream out = context.openFileOutput(getSavePageName(page.getTitle()), Context.MODE_PRIVATE);
        try {
            out.write(page.toJSON().toString().getBytes("utf-8"));
        } catch (IOException e) {
            // Won't happen. EVER. JESUS CHRIST, Java!
            throw new RuntimeException(e);
        }
        out.close();
    }

    public Page loadPageContent(PageTitle title) throws IOException {
        FileInputStream in = context.openFileInput(getSavePageName(title));

        BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
        String contents = reader.readLine();
        if (reader.readLine() != null) {
            // Somehow we have a newline in there! THROW UP!
            throw new RuntimeException("Raw newline found in Saved Page for " + title);
        }
        reader.close();
        try {
            return new Page(new JSONObject(contents));
{'fraction_non_alphanumeric': 0.09411764705882353, 'fraction_numerical': 0.0010457516339869282, 'mean_word_length': 2.7254138266796493, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '683013', 'n_tokens_mistral': 1014, 'n_tokens_neox': 990, 'n_words': 232}