Android Open Source - mirror-notify-android I O Utils






From Project

Back to project page mirror-notify-android.

License

The source code is released under:

Apache License

If you think the Android project mirror-notify-android 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.rahulrav.glassnotify.util;
//from w  w  w .j ava 2  s .  c  o  m
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public final class IOUtils {

  /**
   * Reads a @link{InputStream} till the end of the stream is reached.
   *
   * @param in      is the @link{InputStream}
   * @param closeIn indicates to close the stream after the end of stream has been reached
   * @return the @link{String} contents of the stream
   */
  public static String readAsString(final InputStream in, final boolean closeIn) {
    if (in == null) {
      return null;
    }

    ByteArrayOutputStream out = null;
    try {
      out = new ByteArrayOutputStream();
      final byte[] buffer = new byte[4096];
      int length = -1;
      while ((length = in.read(buffer)) >= 0) {
        out.write(buffer, 0, length);
      }
      return new String(out.toByteArray(), "UTF-8");
    } catch (final Exception e) {
      Logger.e("Error reading input stream", e);
    } finally {
      if (out != null) {
        try {
          out.close();
        } catch (Exception ignore) {
          Logger.d("Error closing stream", ignore);
        }
      }
      if (in != null && closeIn) {
        try {
          in.close();
        } catch (Exception ignore) {
          Logger.d("Error closing stream", ignore);
        }
      }
    }
    return null;
  }
}




Java Source Code List

com.rahulrav.glassnotify.AppItemAdapter.java
com.rahulrav.glassnotify.AppItemViewHolder.java
com.rahulrav.glassnotify.AppItem.java
com.rahulrav.glassnotify.MainActivity.java
com.rahulrav.glassnotify.NotificationListenerService.java
com.rahulrav.glassnotify.NotifierService.java
com.rahulrav.glassnotify.WhitelistActivity.java
com.rahulrav.glassnotify.util.IOUtils.java
com.rahulrav.glassnotify.util.Logger.java