net.sourceforge.cobertura.util
Class IOUtil

java.lang.Object
  extended bynet.sourceforge.cobertura.util.IOUtil

public abstract class IOUtil
extends java.lang.Object

Helper class with useful I/O operations.

Author:
Grzegorz Lukasik

Constructor Summary
IOUtil()
           
 
Method Summary
static java.io.InputStream closeInputStream(java.io.InputStream in)
          Closes an input stream.
static java.io.OutputStream closeOutputStream(java.io.OutputStream out)
          Closes an output stream.
static void copyStream(java.io.InputStream in, java.io.OutputStream out)
          Copies bytes from input stream into the output stream.
static byte[] createByteArrayFromInputStream(java.io.InputStream in)
          Returns an array that contains values read from the given input stream.
static java.io.PrintWriter getPrintWriter(java.io.File file)
           
static void moveFile(java.io.File sourceFile, java.io.File destinationFile)
          Moves a file from one location to other.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtil

public IOUtil()
Method Detail

copyStream

public static void copyStream(java.io.InputStream in,
                              java.io.OutputStream out)
                       throws java.io.IOException
Copies bytes from input stream into the output stream. Stops when the input stream read method returns -1. Does not close the streams.

Throws:
java.io.IOException - If either passed stream will throw IOException.
java.lang.NullPointerException - If either passed stream is null.

createByteArrayFromInputStream

public static byte[] createByteArrayFromInputStream(java.io.InputStream in)
                                             throws java.io.IOException
Returns an array that contains values read from the given input stream.

Throws:
java.lang.NullPointerException - If null stream is passed.
java.io.IOException

moveFile

public static void moveFile(java.io.File sourceFile,
                            java.io.File destinationFile)
                     throws java.io.IOException
Moves a file from one location to other.

Throws:
java.io.IOException - If IO exception occur during moving.
java.lang.NullPointerException - If either passed file is null.

closeInputStream

public static java.io.InputStream closeInputStream(java.io.InputStream in)
Closes an input stream.

Parameters:
in - The stream to close.
Returns:
null unless an exception was thrown while closing, else returns the stream

closeOutputStream

public static java.io.OutputStream closeOutputStream(java.io.OutputStream out)
Closes an output stream.

Parameters:
out - The stream to close.
Returns:
null unless an exception was thrown while closing, else returns the stream.

getPrintWriter

public static java.io.PrintWriter getPrintWriter(java.io.File file)
                                          throws java.io.UnsupportedEncodingException,
                                                 java.io.FileNotFoundException
Throws:
java.io.UnsupportedEncodingException
java.io.FileNotFoundException