<commit_before>/*
 * Copyright 2010 NWSAlerts authors.
 *
 * 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.
 */
// From <NAME> blog at:
// http://penguinman-techtalk.blogspot.com/2010/08/loading-large-reference-database-in.html
// No license was evident at the time of retrieval: 28-Aug-2010.
package com.googlecode.iqapps;

import java.io.File;

import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.util.AndroidRuntimeException;

public abstract class ExternalStorageReadOnlyOpenHelper {
	private SQLiteDatabase database;
	private File dbFile;
	private SQLiteDatabase.CursorFactory factory;
	protected String externalSubdirectory="NWSAlerts";

	public ExternalStorageReadOnlyOpenHelper(String dbFileName,
			SQLiteDatabase.CursorFactory factory) {
		this.factory = factory;

		if (!Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED)) {
			throw new AndroidRuntimeException(
					"External storage (SD-Card) not mounted");
		}
		File appDbDir = new File(Environment.getExternalStorageDirectory(),
				externalSubdirectory);
		if (!appDbDir.exists()) {
			appDbDir.mkdirs();
		}
		this.dbFile = new File(appDbDir, dbFileName);
	}

	public boolean databaseFileExists() {
		return dbFile.exists();
	}

	private void open() {
		if (dbFile.exists()) {
			database = SQLiteDatabase.openDatabase(dbFile.getAbsolutePath(),
					factory, SQLiteDatabase.OPEN_READONLY);
		}
	}

	public synchronized void close() {
		if (database != null) {
			database.close();
			database = null;
		}
	}

	public synchronized SQLiteDatabase getReadableDatabase() {
		return getDatabase();
	}

	private SQLiteDatabase getDatabase() {
		if (database == null) {
			open();
		}
		return database;
	}
}
<commit_msg>* Adjusted open method and a few other items.<commit_after>/*
 * Copyright 2010 NWSAlerts authors.
 *
 * 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.
 */
// From <NAME> blog at:
// http://penguinman-techtalk.blogspot.com/2010/08/loading-large-reference-database-in.html
// No license was evident at the time of retrieval: 28-Aug-2010.
package com.googlecode.iqapps;

import java.io.File;

import com.googlecode.iqapps.IQNWSAlerts.CorrelationDbAdapter;

import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.util.AndroidRuntimeException;

public abstract class ExternalStorageReadOnlyOpenHelper {
	private static Logger logger = Logger
			.getLogger("ExternalStorageReadOnlyOpenHelper");
	private SQLiteDatabase database;
	private File dbFile;
	private SQLiteDatabase.CursorFactory factory;

	public ExternalStorageReadOnlyOpenHelper(String dbFileName,
			SQLiteDatabase.CursorFactory factory) {
		this.factory = factory;

		if (!Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED)) {
			throw new AndroidRuntimeException(
					"External storage (SD-Card) not mounted");
		}
		File appDbDir = new File(Environment.getExternalStorageDirectory(),
				CorrelationDbAdapter.externalSubdirectory);
		if (!appDbDir.exists()) {
			logger.trace("Creating dir: " + appDbDir.getPath());
			appDbDir.mkdirs();
		}
		this.dbFile = new File(appDbDir, dbFileName);
		logger.trace("File " + this.dbFile.getPath() + " "
				+ (this.dbFile.exists() ? "exists" : "does not exist"));
	}

	public boolean databaseFileExists() {
		return dbFile.exists();
	}

	private void open() {
		logger.trace("In open");
		if (databaseFileExists()) {
			logger.debug("open: Database file exists.");
			database = SQLiteDatabase.openDatabase(dbFile.getAbsolutePath(),
					factory, SQLiteDatabase.OPEN_READONLY);

			if (database == null) {
				logger.error("open: database is null following");
				logger.error("SQLiteDatabase.openDatabase("
						+ dbFile.getAbsolutePath()
						+ ",	factory, SQLiteDatabase.OPEN_READONLY");
			}
		} else {
			logger.error("open: Database file doesn't exist.");
		}
	}

	public synchronized void close() {
		if (database != null) {
			database.close();
			database = null;
		}
	}

	public synchronized SQLiteDatabase getReadableDatabase() {
		return getDatabase();
	}

	private SQLiteDatabase getDatabase() {
		logger.trace("In getDatabase");
		if (database == null) {
			open();
		}
		return database;
	}
}

{'fraction_non_alphanumeric': 0.10500190912562046, 'fraction_numerical': 0.007636502481863307, 'mean_word_length': 4.2972699696663295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4046772', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1472, 'n_words': 435}