Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Zirco Browser for Android
 * 
 * Copyright (C) 2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

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

import android.content.Context;

import android.util.Log;

public class Main {
    /**
     * Load a raw string resource.
     * @param context The current context.
     * @param resourceId The resource id.
     * @return The loaded string.
     */
    private static String getStringFromRawResource(Context context, int resourceId) {
        String result = null;

        InputStream is = context.getResources().openRawResource(resourceId);
        if (is != null) {
            StringBuilder sb = new StringBuilder();
            String line;

            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append("\n");
                }
            } catch (IOException e) {
                Log.w("ApplicationUtils",
                        String.format("Unable to load resource %s: %s", resourceId, e.getMessage()));
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    Log.w("ApplicationUtils",
                            String.format("Unable to load resource %s: %s", resourceId, e.getMessage()));
                }
            }
            result = sb.toString();
        } else {
            result = "";
        }

        return result;
    }
}