package makulib;

import android.content.Context;
import android.content.res.AssetManager;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by nmoya on 8/3/15.
 */
public class IOUtils {

    public static String readFile(Context context, String fileName)
    {
        String content = "";
        try {
            AssetManager am = context.getAssets();
            InputStream is = am.open(fileName);
            int letter;
            while ((letter = is.read()) != -1) {
                content += (char) letter;
            }
        }
        catch (IOException ioe) {
            ioe.printStackTrace();
        }
        return content;
    }
    public static byte[] readAll(InputStream input) throws Exception {
        ByteArrayOutputStream output = new ByteArrayOutputStream(4096);
        byte[] buffer = new byte[4096];
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
        }
        return output.toByteArray();
    }

}
