Android Open Source - GreenGear Asset Util






From Project

Back to project page GreenGear.

License

The source code is released under:

MIT License

If you think the Android project GreenGear 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 com.bradleycurran.greengear.util;
/*from w  ww  .j  a v a2 s  .c  o  m*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;

/**
 * Various utility methods to help with assets.
 * 
 * @author Bradley Curran
 */
public class AssetUtil {

    private static final String TAG         = AssetUtil.class.getSimpleName();

    private static final String FORMAT_UTF8 = "UTF-8";

    /**
     * Gets a given file from the assets directory and returns it as a string.
     * 
     * @param context
     * @param filename
     *            A file in the assets directory of your application. A valid file would be in
     *            /assets/data.txt, which you would refer to with "data.txt".
     * @return The contents of a file as a string, otherwise null if there was an IO error.
     */
    public static String get(Context context, String filename) {
        StringBuilder sb = new StringBuilder();

        try {
            InputStream is = context.getAssets().open(filename);
            InputStreamReader isr = new InputStreamReader(is, FORMAT_UTF8);
            BufferedReader reader = new BufferedReader(isr);
            String line = null;

            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }

            reader.close();
        }
        catch (IOException e) {
            Log.e(TAG, "error", e);
            return null;
        }

        return sb.toString();
    }
}




Java Source Code List

com.bradleycurran.droidprefs.DroidPrefs.java
com.bradleycurran.greengear.model.KeyValue.java
com.bradleycurran.greengear.util.AssetUtil.java
com.bradleycurran.greengear.util.Log.java
com.bradleycurran.greengear.util.ViewUtil.java
com.bradleycurran.velocadapter.ArrayVelocAdapter.java
com.bradleycurran.velocadapter.VelocAdapter.java
com.bradleycurran.velocadapter.ViewBinder.java
com.bradleycurran.viewquery.Operation.java
com.bradleycurran.viewquery.ViewQuery.java
com.bradleycurran.viewquery.animation.hc.BounceTouchListener.java