Example usage for java.io BufferedReader close

List of usage examples for java.io BufferedReader close

Introduction

In this page you can find the example usage for java.io BufferedReader close.

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:Main.java

public static void writeFile(String filepath, InputStream is) throws IOException {
    File file = new File(filepath);
    BufferedWriter bw = new BufferedWriter(new FileWriter(file));

    BufferedReader br = new BufferedReader(new InputStreamReader(is));

    String line;/*w w w . j av  a  2  s. c  om*/
    while ((line = br.readLine()) != null) {
        bw.write(line + "\n");
    }

    bw.close();
    br.close();
}

From source file:Main.java

public static void setCookie(Context context, String url) {
    FileInputStream in = null;//from w  w w . j  a  v a2  s  .  c o  m
    try {
        in = context.openFileInput(TAXICOOKIE_FILE);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    if (in == null) {
        Log.w(TAG, "saveCookie: Cannot open file: " + TAXICOOKIE_FILE);
    }

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String cookieStr = null;
    try {
        cookieStr = reader.readLine();
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(TAG, "cookieStr: " + cookieStr);
    if (cookieStr == null) {
        return;
    }

    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeSessionCookie();
    cookieManager.setCookie(url, cookieStr);
    CookieSyncManager.getInstance().sync();
}

From source file:Main.java

public static String streamToString(InputStream input) throws IOException {

    InputStreamReader isr = new InputStreamReader(input);
    BufferedReader reader = new BufferedReader(isr);

    String line;/* w  w  w.  j  a v a  2s  . c o  m*/
    StringBuffer sb = new StringBuffer();
    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }
    reader.close();
    isr.close();
    return sb.toString();
}

From source file:Main.java

public static String readStream(InputStream is) throws IOException {
    StringBuilder result = new StringBuilder();
    BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
    String line;/*from  ww  w  .j  a  va 2  s.  c  om*/
    while ((line = in.readLine()) != null) {
        result.append(line);
        result.append('\n');
    }
    in.close();
    return result.toString();
}

From source file:Main.java

private static String streamToString(InputStream is) throws IOException {
    String str = "";

    if (is != null) {
        StringBuilder sb = new StringBuilder();
        String line;//from  w  w w.  j  a v a2 s  . c o m

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));

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

            reader.close();
        } finally {
            is.close();
        }

        str = sb.toString();
    }

    return str;
}

From source file:Main.java

static private String readString(File file) {
    String value = "";
    try {/* ww w .  j  a va2  s  . co  m*/
        int BUFFER_SIZE = 8192;
        String UTF8 = "utf8";

        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF8),
                BUFFER_SIZE);
        value = br.readLine();
        br.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return value;
}

From source file:Main.java

private static boolean hasUTF8BOM(File f) throws FileNotFoundException, IOException {
    FileInputStream fis = new FileInputStream(f);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8")));
    String s = br.readLine();//from w  w  w .j a  va2 s.  c om
    boolean ret = false;
    if (s.startsWith(UTF8_BOM))
        ret = true;

    br.close();
    return ret;
}

From source file:Main.java

static String getSaveLocation(String saveName) {
    String saveLocation;/*from  w  w w .jav  a  2s  .c om*/
    File notification = new File(
            Environment.getExternalStorageDirectory().toString() + "/.Instagram/" + saveName + ".txt");

    try {
        BufferedReader br = new BufferedReader(new FileReader(notification));

        saveLocation = br.readLine();
        saveLocation = saveLocation.replace("file://", "").replaceAll(" ", "%20");
        br.close();
    } catch (Throwable t) {
        saveLocation = "Instagram";
    }

    if (!saveLocation.substring(saveLocation.length() - 1).equals("/") && !saveLocation.equals("Instagram")) {
        saveLocation = saveLocation + "/";
    }

    return saveLocation;
}

From source file:Main.java

public static boolean startLastActivity(Activity activity) {
    try {/*from   w ww  .  ja v a  2  s.  c  o m*/
        BufferedReader reader = new BufferedReader(new InputStreamReader(activity.openFileInput(FILENAME)));
        String nextClassName = reader.readLine();
        reader.close();

        if (null == nextClassName || nextClassName.length() < 3) {
            return false;
        }

        String currClassName = activity.getClass().getName();
        if (currClassName.equals(nextClassName)) {
            return false;
        }

        @SuppressWarnings("unchecked")
        Class<? extends Activity> clazz = (Class<? extends Activity>) Class.forName(nextClassName);
        if (null == clazz) {
            return false;
        }

        Intent i = new Intent(activity, clazz);
        activity.startActivity(i);
        activity.finish();
        reader.close();

        return true;
    } catch (Exception e) {
        Toast.makeText(activity, "startLastActivity: " + e, Toast.LENGTH_LONG).show();
    }
    return false;
}

From source file:net.duckling.ddl.web.agent.util.AuthUtil.java

private synchronized static void initClientKey() {
    if (clientKey == null) {
        try {//from  www .  j a v a2 s. c o m
            InputStream in = LynxEmailResourceController.class.getResourceAsStream("/ddlclientkey");
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
            String key = reader.readLine();
            reader.close();
            clientKey = Base64.decodeBase64(key);
        } catch (UnsupportedEncodingException e) {
            LOG.error("", e);
        } catch (IOException e) {
            LOG.error("", e);
        }
    }
}