// Path: app/src/main/java/javax/microedition/util/ContextHolder.java
// public class ContextHolder {
// 
// 	private static final String tag = "ContextHolder";
// 
// 	private static MainActivity context;
// 	private static ArrayList<ActivityResultListener> resultListeners = new ArrayList<ActivityResultListener>();
// 	private static LayoutInflater inflater;
// 
// 	public static void setContext(MainActivity cx) {
// 		context = cx;
// 		inflater = LayoutInflater.from(cx);
// 	}
// 
// 	public static Context getContext() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getContext()");
// 		}
// 		return context;
// 	}
// 
// 	public static LayoutInflater getInflater() {
// 		return inflater;
// 	}
// 
// 	public static InputStream getResourceAsStream(String filename) {
// 		if (filename.startsWith("/")) {
// 			filename = filename.substring(1);
// 		}
// 
// 		try {
// 			return getContext().getAssets().open(filename);
// 		} catch (IOException e) {
// 			Log.d(tag, "getResourceAsStream err: " + e.getMessage());
// 			return null;
// 		}
// 	}
// 
// 	public static File getCacheDir() {
// 		if (Environment.MEDIA_MOUNTED.equals(Environment
// 				.getExternalStorageState())) {
// 			return getContext().getExternalCacheDir();
// 		} else {
// 			return getContext().getCacheDir();
// 		}
// 	}
// 
// 	public static int getRequestCode(String requestString) {
// 		return requestString.hashCode() & 0x7FFFFFFF;
// 	}
// 
// 	public static MainActivity getActivity() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getActivity()");
// 		}
// 		return context;
// 	}
// 
// 	public static void addActivityResultListener(ActivityResultListener listener) {
// 		if (!resultListeners.contains(listener)) {
// 			resultListeners.add(listener);
// 		}
// 	}
// 
// 	public static void removeActivityResultListener(
// 			ActivityResultListener listener) {
// 		resultListeners.remove(listener);
// 	}
// 
// 	public static void notifyOnActivityResult(int requestCode, int resultCode,
// 			Intent data) {
// 		for (ActivityResultListener listener : resultListeners) {
// 			listener.onActivityResult(requestCode, resultCode, data);
// 		}
// 	}
// }


import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import javax.microedition.util.ContextHolder;
import android.content.Context;

/*
 * Copyright 2012 Kulikov Dmitriy
 *
 * 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 javax.microedition.rms;




public class RecordStore
{
	private static final String INDEX_SUFFIX = ".idx";
	private static final String RECORD_SUFFIX = ".dat";
	private static final String SEPARATOR = "-";
	
	private String recordStoreName;
	
	private int nextRecordID;
	private ArrayList<Integer> ids;
	
	private static String getFileNamePrefix(String recordStoreName)
	{
		return recordStoreName + SEPARATOR + Integer.toHexString(recordStoreName.hashCode()).toUpperCase();
	}
	
	private String getIndexFileName()
	{
		return getFileNamePrefix(recordStoreName) + INDEX_SUFFIX;
	}
	
	private String getRecordFileName(int id)
	{
		return getFileNamePrefix(recordStoreName) + SEPARATOR + id + RECORD_SUFFIX;
	}
	
	private RecordStore(String recordStoreName, boolean createIfNecessary) throws RecordStoreException
	{
		this.recordStoreName = recordStoreName;
		
		try
		{

// Path: app/src/main/java/javax/microedition/util/ContextHolder.java
// public class ContextHolder {
// 
// 	private static final String tag = "ContextHolder";
// 
// 	private static MainActivity context;
// 	private static ArrayList<ActivityResultListener> resultListeners = new ArrayList<ActivityResultListener>();
// 	private static LayoutInflater inflater;
// 
// 	public static void setContext(MainActivity cx) {
// 		context = cx;
// 		inflater = LayoutInflater.from(cx);
// 	}
// 
// 	public static Context getContext() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getContext()");
// 		}
// 		return context;
// 	}
// 
// 	public static LayoutInflater getInflater() {
// 		return inflater;
// 	}
// 
// 	public static InputStream getResourceAsStream(String filename) {
// 		if (filename.startsWith("/")) {
// 			filename = filename.substring(1);
// 		}
// 
// 		try {
// 			return getContext().getAssets().open(filename);
// 		} catch (IOException e) {
// 			Log.d(tag, "getResourceAsStream err: " + e.getMessage());
// 			return null;
// 		}
// 	}
// 
// 	public static File getCacheDir() {
// 		if (Environment.MEDIA_MOUNTED.equals(Environment
// 				.getExternalStorageState())) {
// 			return getContext().getExternalCacheDir();
// 		} else {
// 			return getContext().getCacheDir();
// 		}
// 	}
// 
// 	public static int getRequestCode(String requestString) {
// 		return requestString.hashCode() & 0x7FFFFFFF;
// 	}
// 
// 	public static MainActivity getActivity() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getActivity()");
// 		}
// 		return context;
// 	}
// 
// 	public static void addActivityResultListener(ActivityResultListener listener) {
// 		if (!resultListeners.contains(listener)) {
// 			resultListeners.add(listener);
// 		}
// 	}
// 
// 	public static void removeActivityResultListener(
// 			ActivityResultListener listener) {
// 		resultListeners.remove(listener);
// 	}
// 
// 	public static void notifyOnActivityResult(int requestCode, int resultCode,
// 			Intent data) {
// 		for (ActivityResultListener listener : resultListeners) {
// 			listener.onActivityResult(requestCode, resultCode, data);
// 		}
// 	}
// }


// Path: app/src/main/java/javax/microedition/rms/RecordStore.java
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import javax.microedition.util.ContextHolder;
import android.content.Context;

/*
 * Copyright 2012 Kulikov Dmitriy
 *
 * 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 javax.microedition.rms;




public class RecordStore
{
	private static final String INDEX_SUFFIX = ".idx";
	private static final String RECORD_SUFFIX = ".dat";
	private static final String SEPARATOR = "-";
	
	private String recordStoreName;
	
	private int nextRecordID;
	private ArrayList<Integer> ids;
	
	private static String getFileNamePrefix(String recordStoreName)
	{
		return recordStoreName + SEPARATOR + Integer.toHexString(recordStoreName.hashCode()).toUpperCase();
	}
	
	private String getIndexFileName()
	{
		return getFileNamePrefix(recordStoreName) + INDEX_SUFFIX;
	}
	
	private String getRecordFileName(int id)
	{
		return getFileNamePrefix(recordStoreName) + SEPARATOR + id + RECORD_SUFFIX;
	}
	
	private RecordStore(String recordStoreName, boolean createIfNecessary) throws RecordStoreException
	{
		this.recordStoreName = recordStoreName;
		
		try
		{

			DataInputStream dis = new DataInputStream(ContextHolder.getContext().openFileInput(getIndexFileName()));
