diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2013-10-04 20:31:58 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2013-10-04 20:31:58 +0000 |
| commit | c015af71a11c76785a20dc31c41aa830b00fa85b (patch) | |
| tree | 95ea03a7d3d7ef24605db16ceadce792c9b9ff15 | |
| parent | a35b286ce040919a71d27e5bf696886237c6c470 (diff) | |
remove the grammar copying from the Android UI since now we can load grammars from InputStream
| -rw-r--r-- | src/ui/android/src/org/grammaticalframework/ui/android/Translator.java | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java index 9ecdb104e..610a03ce3 100644 --- a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java +++ b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java @@ -8,11 +8,9 @@ import org.grammaticalframework.pgf.Expr; import org.grammaticalframework.pgf.PGF; import org.grammaticalframework.pgf.ParseError; -import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.Arrays; import java.util.List; @@ -89,38 +87,24 @@ public class Translator { private synchronized void ensureLoaded(String grammarName) { if (mPgf != null) return; + InputStream in = null; + try { // TODO: use PGF API to read this directly from assets - Log.d(TAG, "Copying grammar..."); - File file = copyAsset(grammarName); - Log.d(TAG, "Trying to open " + file); - mPgf = PGF.readPGF(file.getPath()); + in = getContext().getAssets().open(grammarName); + Log.d(TAG, "Trying to open " + grammarName); + mPgf = PGF.readPGF(in); } catch (FileNotFoundException e) { Log.e(TAG, "File not found", e); } catch (IOException e) { Log.e(TAG, "Error loading grammar", e); - } - } - - private File copyAsset(String asset) throws IOException { - InputStream in = null; - OutputStream out = null; - try { - in = getContext().getAssets().open(asset); - out = getContext().openFileOutput(asset, Context.MODE_PRIVATE); - byte[] buf = new byte[4096]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - return getContext().getFileStreamPath(asset); } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); - } + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } + } } } |
