org.inria.ns.reflex.util.io
Class IOHelper

java.lang.Object
  extended by org.inria.ns.reflex.util.io.IOHelper

public final class IOHelper
extends Object

A set of constants and static methods related to I/O.

Author:
Philippe Poulard

Field Summary
static OutputStream NULL_OUTPUT_STREAM
          The /dev/null output stream.
static PrintStream NULL_PRINT_STREAM
          The /dev/null print stream.
 
Method Summary
static void close(OutputStream os)
          Close output streams that are not print streams.
static void copy(InputStream input, OutputStream output)
          Copy an input to an output.
static void fastCopy(FileInputStream input, FileOutputStream output)
          Perform a fast copy from file to file.
static int getPort(URI uri)
          Return the specified port or default port of an URI.
static boolean isSecure(String scheme)
          Indicates whether the given scheme is secure or not.
static String readAll(InputStream input)
          Read all an input stream in a string.
static String readAll(Reader input)
          Read all a character stream in a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_OUTPUT_STREAM

public static final OutputStream NULL_OUTPUT_STREAM
The /dev/null output stream.


NULL_PRINT_STREAM

public static final PrintStream NULL_PRINT_STREAM
The /dev/null print stream.

Method Detail

close

public static void close(OutputStream os)
                  throws IOException
Close output streams that are not print streams.

Parameters:
os - The output stream to close.
Throws:
IOException - When an I/O exception occurs.
See Also:
PrintStream

fastCopy

public static void fastCopy(FileInputStream input,
                            FileOutputStream output)
                     throws IOException
Perform a fast copy from file to file.

Parameters:
input - The input to read from.
output - The output to write to.
Throws:
IOException - When an I/O error occurs.

copy

public static void copy(InputStream input,
                        OutputStream output)
                 throws IOException
Copy an input to an output. If both arguments are related to files, a fast copy is performed.

Parameters:
input - The input to read from.
output - The output to write to.
Throws:
IOException - When an I/O error occurs.
See Also:
fastCopy(FileInputStream, FileOutputStream)

readAll

public static String readAll(InputStream input)
                      throws IOException
Read all an input stream in a string.

Parameters:
input - The input stream to read.
Returns:
The whole content of the input as a single string.
Throws:
IOException - When an I/O error occurs.

readAll

public static String readAll(Reader input)
                      throws IOException
Read all a character stream in a string.

Parameters:
input - The character stream to read.
Returns:
The whole content of the input as a single string.
Throws:
IOException - When an I/O error occurs.

isSecure

public static boolean isSecure(String scheme)
Indicates whether the given scheme is secure or not.

Parameters:
scheme - The scheme to test.
Returns:
true for https, sftp, ftps, or webdavs, false otherwise.

getPort

public static int getPort(URI uri)
Return the specified port or default port of an URI.

Parameters:
uri - The URI.
Returns:
The port specified in the URI, or the default port according to the URI scheme (e.g. 80 for "http").