Android Open Source - OBS-Translation-App Assets Util






From Project

Back to project page OBS-Translation-App.

License

The source code is released under:

MIT License

If you think the Android project OBS-Translation-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.door43.obs.mta.util;
/*from   w  w  w .  j  a v a2 s.  c o m*/
import android.content.Context;
import android.util.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static org.door43.obs.mta.ConstApp.ENC_UTF_8;

/**
 * Utility class for handling assets.
 */
public class AssetsUtil {

  /* CONSTANTS */

    /* FIELDS */

    /* CONSTRUCTORS */

    /* METHODS */

    /**
     * Reads text from file in "/assets/" folder.
     * @param path Path to file.
     * @param context Activity context.
     * @return String from file on given path.
     */
    public static String readTextFromAsset(String path, Context context) {

        StringBuilder documentText = new StringBuilder(200);
        BufferedReader reader = null;
        String line;

        try {
            reader = new BufferedReader(
                    new InputStreamReader(context.getAssets().open(path), ENC_UTF_8));

            // do reading, usually loop until end of file reading
            line = reader.readLine();
            while (line != null) {
                documentText.append(line);
                line = reader.readLine();
            }
        } catch (IOException e) {
            Log.e(AssetsUtil.class.getName(), "Error while reading asset: " + path, e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    Log.w("Error while closing asset reader for: " + path, e);
                }
            }
        }

        return documentText.toString();
    }

    /* GETTERS AND SETTERS */

    /* OBJECT METHODS */

}




Java Source Code List

com.door43.obt.ata.MenuListActivity.java
com.door43.obt.ata.MenuListFragment.java
com.door43.obt.ata.RowAdapter.java
com.door43.obt.ata.SplashActivity.java
com.door43.obt.ata.TranslationDetailActivity.java
com.door43.obt.ata.TranslationFragment.java
org.door43.obs.mta.ConstApp.java
org.door43.obs.mta.db.AbstractDBHelper.java
org.door43.obs.mta.db.ConstTranslations.java
org.door43.obs.mta.db.TranslationDBHelper.java
org.door43.obs.mta.model.Frame.java
org.door43.obs.mta.model.IFrame.java
org.door43.obs.mta.model.IPersistenceObject.java
org.door43.obs.mta.model.ITerm.java
org.door43.obs.mta.model.IText.java
org.door43.obs.mta.model.ITranslationNotes.java
org.door43.obs.mta.model.ITranslation.java
org.door43.obs.mta.model.PersistenceObject.java
org.door43.obs.mta.model.Term.java
org.door43.obs.mta.model.Text.java
org.door43.obs.mta.model.TranslationNotes.java
org.door43.obs.mta.model.Translation.java
org.door43.obs.mta.service.FakeTranslationService.java
org.door43.obs.mta.service.ITranslationService.java
org.door43.obs.mta.service.TranslationService.java
org.door43.obs.mta.util.AssetsUtil.java
org.door43.obs.mta.util.StringUtils.java