org.cruxframework.crux.core.utils
Class StreamUtils

java.lang.Object
  extended by org.cruxframework.crux.core.utils.StreamUtils

public class StreamUtils
extends Object

Tool for stream manipulation

Author:
Gesse S. F. Dafe

Constructor Summary
StreamUtils()
           
 
Method Summary
static byte[] read(InputStream in)
          Reads an input stream and writes it to a byte array
static String read(InputStream in, String charset)
          Reads an input stream and writes it to a string, using the desired charset
static String readAsUTF8(InputStream in)
          Reads an input stream and writes it to a string, using UTF-8 charset
static void safeCloseStreams(InputStream in, OutputStream out)
          Close streams without pain
static void write(InputStream in, OutputStream out, boolean closeBoth)
          Writes the input stream to the output stream.
static void write(String in, OutputStream out, boolean closeBoth)
          Writes the input stream to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamUtils

public StreamUtils()
Method Detail

read

public static byte[] read(InputStream in)
                   throws IOException
Reads an input stream and writes it to a byte array

Parameters:
responseBodyAsStream -
Returns:
Throws:
IOException

read

public static String read(InputStream in,
                          String charset)
                   throws IOException
Reads an input stream and writes it to a string, using the desired charset

Parameters:
responseBodyAsStream -
Returns:
Throws:
IOException

readAsUTF8

public static String readAsUTF8(InputStream in)
                         throws IOException
Reads an input stream and writes it to a string, using UTF-8 charset

Parameters:
responseBodyAsStream -
Returns:
Throws:
IOException

write

public static void write(InputStream in,
                         OutputStream out,
                         boolean closeBoth)
                  throws IOException
Writes the input stream to the output stream. Closes both if desired.

Parameters:
responseBodyAsStream -
Throws:
IOException

write

public static void write(String in,
                         OutputStream out,
                         boolean closeBoth)
                  throws IOException
Writes the input stream to the output stream. Closes both if desired.

Parameters:
responseBodyAsStream -
Throws:
IOException

safeCloseStreams

public static void safeCloseStreams(InputStream in,
                                    OutputStream out)
Close streams without pain

Parameters:
out -
in -


Copyright © 2014. All rights reserved.