sk.baka.tools
Class IOUtils

java.lang.Object
  extended by sk.baka.tools.IOUtils

public final class IOUtils
extends Object

Contains various I/O utility methods.

Author:
Martin Vysny

Method Summary
static void closeQuietly(Closeable conn)
          Closes given Closeable quietly.
static long copy(InputStream in, OutputStream out)
          Reads given input stream fully and writes it to given output stream.
static long copy(Reader in, Writer out)
          Reads given reader fully and writes it to given output stream.
static String toString(InputStream in)
          Reads given input stream fully and returns it as a string with platform-default encoding.
static String toString(InputStream in, String encoding)
          Reads given input stream fully and returns it as a string with platform-default encoding.
static String toString(Reader r)
          Reads given input stream fully and returns it as a string with platform-default encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

closeQuietly

public static void closeQuietly(Closeable conn)
Closes given Closeable quietly.

Parameters:
conn - the connection. Does nothing if null is passed

toString

public static String toString(InputStream in)
                       throws IOException
Reads given input stream fully and returns it as a string with platform-default encoding.

Parameters:
in - the stream to read, always closed.
Returns:
the stream contents
Throws:
IOException - if reading fails.

toString

public static String toString(InputStream in,
                              String encoding)
                       throws IOException
Reads given input stream fully and returns it as a string with platform-default encoding.

Parameters:
in - the stream to read, always closed.
encoding - the encoding to use
Returns:
the stream contents
Throws:
IOException - if reading fails.

toString

public static String toString(Reader r)
                       throws IOException
Reads given input stream fully and returns it as a string with platform-default encoding.

Parameters:
r - the reader to read, always closed.
Returns:
the stream contents
Throws:
IOException - if reading fails.

copy

public static long copy(InputStream in,
                        OutputStream out)
                 throws IOException
Reads given input stream fully and writes it to given output stream.

Parameters:
in - the stream to read, always closed.
out - the stream to write, always closed.
Returns:
number of bytes copied.
Throws:
IOException - if copy fails.

copy

public static long copy(Reader in,
                        Writer out)
                 throws IOException
Reads given reader fully and writes it to given output stream.

Parameters:
in - the stream to read, always closed.
out - the stream to write, always closed.
Returns:
number of characters copied.
Throws:
IOException - if copy fails.


Copyright © 2009-2010. All Rights Reserved.