Bug 999398 - Rename RawResource.get() to RawResource.getAsString() (r=nalexander)
--- a/mobile/android/base/db/HomeProvider.java
+++ b/mobile/android/base/db/HomeProvider.java
@@ -78,17 +78,17 @@ public class HomeProvider extends SQLite
}
/**
* Returns a cursor populated with static fake data.
*/
private Cursor queryFakeItems(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
JSONArray items = null;
try {
- final String jsonString = RawResource.get(getContext(), R.raw.fake_home_items);
+ final String jsonString = RawResource.getAsString(getContext(), R.raw.fake_home_items);
items = new JSONArray(jsonString);
} catch (IOException e) {
Log.e(LOGTAG, "Error getting fake home items", e);
return null;
} catch (JSONException e) {
Log.e(LOGTAG, "Error parsing fake_home_items.json", e);
return null;
}
--- a/mobile/android/base/util/RawResource.java
+++ b/mobile/android/base/util/RawResource.java
@@ -7,18 +7,27 @@ package org.mozilla.gecko.util;
import android.content.Context;
import android.content.res.Resources;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
+/**
+ * {@code RawResource} provides API to load raw resources in different
+ * forms. For now, we only load them as strings. We're using raw resources
+ * as localizable 'assets' as opposed to a string that can be directly
+ * translatable e.g. JSON file vs string.
+ *
+ * This is just a utility class to avoid code duplication for the different
+ * cases where need to read such assets.
+ */
public final class RawResource {
- public static String get(Context context, int id) throws IOException {
+ public static String getAsString(Context context, int id) throws IOException {
InputStreamReader reader = null;
try {
final Resources res = context.getResources();
final InputStream is = res.openRawResource(id);
if (is == null) {
return null;
}
--- a/mobile/android/tests/browser/junit3/src/tests/TestRawResource.java
+++ b/mobile/android/tests/browser/junit3/src/tests/TestRawResource.java
@@ -11,17 +11,17 @@ import android.util.TypedValue;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import org.mozilla.gecko.util.RawResource;
/**
- * Tests whether RawResource.get() produces the right String
+ * Tests whether RawResource.getAsString() produces the right String
* result after reading the returned raw resource's InputStream.
*/
public class TestRawResource extends BrowserTestCase {
private static final int RAW_RESOURCE_ID = 1;
private static final String RAW_CONTENTS = "RAW";
private static class TestContext extends MockContext {
private final Resources resources;
@@ -52,16 +52,16 @@ public class TestRawResource extends Bro
}
}
public void testGet() {
Context context = new TestContext();
String result;
try {
- result = RawResource.get(context, RAW_RESOURCE_ID);
+ result = RawResource.getAsString(context, RAW_RESOURCE_ID);
} catch (IOException e) {
result = null;
}
assertEquals(RAW_CONTENTS, result);
}
}
\ No newline at end of file