Read InputStream fully to a string : Stream « File « Android






Read InputStream fully to a string

   

//package org.anddev.andengine.util;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.util.Scanner;

/**
 * (c) 2010 Nicolas Gramlich 
 * (c) 2011 Zynga Inc.
 * 
 * @author Nicolas Gramlich
 * @since 15:48:56 - 03.09.2009
 */
class StreamUtils {
  public static final int IO_BUFFER_SIZE = 8 * 1024;

  public static final String readFully(final InputStream pInputStream) throws IOException {
    final StringBuilder sb = new StringBuilder();
    final Scanner sc = new Scanner(pInputStream);
    while(sc.hasNextLine()) {
      sb.append(sc.nextLine());
    }
    return sb.toString();
  }
}

   
    
    
  








Related examples in the same category

1.Playing Back Audio Streams
2.Stream Proxy
3.Copy Stream
4.Ini File Stream Reader
5.Read Stream to byte array
6.read String From Stream
7.Read stream Fully
8.Read InputStream with ByteArrayOutputStream
9.get Resource As Stream, Loads the resource from classpath
10.InputStream to byte array, copy Reader and Writer,
11.InputStream that notifies listeners of its progress.
12.String to InputStream
13.Context.getFileStreamPath
14.stream To String
15.stream To Bytes
16.Load/save Int Map Data
17.Write InputStream into a StringBuilder