org.apache.camel.util
Class IOHelper

java.lang.Object
  extended by org.apache.camel.util.IOHelper

public final class IOHelper
extends Object

IO helper class.

Version:

Method Summary
static BufferedInputStream buffered(InputStream in)
          Wraps the passed in into a BufferedInputStream object and returns that.
static BufferedOutputStream buffered(OutputStream out)
          Wraps the passed out into a BufferedOutputStream object and returns that.
static BufferedReader buffered(Reader reader)
          Wraps the passed reader into a BufferedReader object and returns that.
static BufferedWriter buffered(Writer writer)
          Wraps the passed writer into a BufferedWriter object and returns that.
static void close(Closeable... closeables)
          Closes the given resources if they are available.
static void close(Closeable closeable)
          Closes the given resource if it is available.
static void close(Closeable closeable, String name)
          Closes the given resource if it is available.
static void close(Closeable closeable, String name, org.slf4j.Logger log)
          Closes the given resource if it is available, logging any closing exceptions to the given log.
static void close(FileChannel channel, String name, org.slf4j.Logger log, boolean force)
          Closes the given channel if it is available, logging any closing exceptions to the given log.
static void close(Writer writer, FileOutputStream os, String name, org.slf4j.Logger log, boolean force)
          Closes the given writer, logging any closing exceptions to the given log.
static int copy(InputStream input, OutputStream output)
           
static int copy(InputStream input, OutputStream output, int bufferSize)
           
static int copy(Reader input, Writer output, int bufferSize)
           
static void copyAndCloseInput(InputStream input, OutputStream output)
           
static void copyAndCloseInput(InputStream input, OutputStream output, int bufferSize)
           
static IOException createIOException(String message, Throwable cause)
          Deprecated. IOException support nested exception in Java 1.6. Will be removed in Camel 3.0
static IOException createIOException(Throwable cause)
          Deprecated. IOException support nested exception in Java 1.6. Will be removed in Camel 3.0
static void force(FileChannel channel, String name, org.slf4j.Logger log)
          Forces any updates to this channel's file to be written to the storage device that contains it.
static void force(FileOutputStream os, String name, org.slf4j.Logger log)
          Forces any updates to a FileOutputStream be written to the storage device that contains it.
static String getCharsetName(Exchange exchange)
           
static String getCharsetName(Exchange exchange, boolean useDefault)
          Gets the charset name if set as property Exchange.CHARSET_NAME.
static String newStringFromBytes(byte[] bytes)
          Use this function instead of new String(byte[]) to avoid surprises from non-standard default encodings.
static String newStringFromBytes(byte[] bytes, int start, int length)
          Use this function instead of new String(byte[], int, int) to avoid surprises from non-standard default encodings.
static String normalizeCharset(String charset)
          This method will take off the quotes and double quotes of the charset
static void validateCharset(String charset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newStringFromBytes

public static String newStringFromBytes(byte[] bytes)
Use this function instead of new String(byte[]) to avoid surprises from non-standard default encodings.


newStringFromBytes

public static String newStringFromBytes(byte[] bytes,
                                        int start,
                                        int length)
Use this function instead of new String(byte[], int, int) to avoid surprises from non-standard default encodings.


buffered

public static BufferedInputStream buffered(InputStream in)
Wraps the passed in into a BufferedInputStream object and returns that. If the passed in is already an instance of BufferedInputStream returns the same passed in reference as is (avoiding double wrapping).

Parameters:
in - the wrapee to be used for the buffering support
Returns:
the passed in decorated through a BufferedInputStream object as wrapper

buffered

public static BufferedOutputStream buffered(OutputStream out)
Wraps the passed out into a BufferedOutputStream object and returns that. If the passed out is already an instance of BufferedOutputStream returns the same passed out reference as is (avoiding double wrapping).

Parameters:
out - the wrapee to be used for the buffering support
Returns:
the passed out decorated through a BufferedOutputStream object as wrapper

buffered

public static BufferedReader buffered(Reader reader)
Wraps the passed reader into a BufferedReader object and returns that. If the passed reader is already an instance of BufferedReader returns the same passed reader reference as is (avoiding double wrapping).

Parameters:
reader - the wrapee to be used for the buffering support
Returns:
the passed reader decorated through a BufferedReader object as wrapper

buffered

public static BufferedWriter buffered(Writer writer)
Wraps the passed writer into a BufferedWriter object and returns that. If the passed writer is already an instance of BufferedWriter returns the same passed writer reference as is (avoiding double wrapping).

Parameters:
writer - the wrapee to be used for the buffering support
Returns:
the passed writer decorated through a BufferedWriter object as wrapper

createIOException

@Deprecated
public static IOException createIOException(Throwable cause)
Deprecated. IOException support nested exception in Java 1.6. Will be removed in Camel 3.0

A factory method which creates an IOException from the given exception and message


createIOException

@Deprecated
public static IOException createIOException(String message,
                                                       Throwable cause)
Deprecated. IOException support nested exception in Java 1.6. Will be removed in Camel 3.0

A factory method which creates an IOException from the given exception and message


copy

public static int copy(InputStream input,
                       OutputStream output)
                throws IOException
Throws:
IOException

copy

public static int copy(InputStream input,
                       OutputStream output,
                       int bufferSize)
                throws IOException
Throws:
IOException

copyAndCloseInput

public static void copyAndCloseInput(InputStream input,
                                     OutputStream output)
                              throws IOException
Throws:
IOException

copyAndCloseInput

public static void copyAndCloseInput(InputStream input,
                                     OutputStream output,
                                     int bufferSize)
                              throws IOException
Throws:
IOException

copy

public static int copy(Reader input,
                       Writer output,
                       int bufferSize)
                throws IOException
Throws:
IOException

force

public static void force(FileChannel channel,
                         String name,
                         org.slf4j.Logger log)
Forces any updates to this channel's file to be written to the storage device that contains it.

Parameters:
channel - the file channel
name - the name of the resource
log - the log to use when reporting warnings, will use this class's own Logger if log == null

force

public static void force(FileOutputStream os,
                         String name,
                         org.slf4j.Logger log)
Forces any updates to a FileOutputStream be written to the storage device that contains it.

Parameters:
os - the file output stream
name - the name of the resource
log - the log to use when reporting warnings, will use this class's own Logger if log == null

close

public static void close(Writer writer,
                         FileOutputStream os,
                         String name,
                         org.slf4j.Logger log,
                         boolean force)
Closes the given writer, logging any closing exceptions to the given log. An associated FileOutputStream can optionally be forced to disk.

Parameters:
writer - the writer to close
os - an underlying FileOutputStream that will to be forced to disk according to the the force parameter
name - the name of the resource
log - the log to use when reporting warnings, will use this class's own Logger if log == null
force - forces the FileOutputStream to disk

close

public static void close(Closeable closeable,
                         String name,
                         org.slf4j.Logger log)
Closes the given resource if it is available, logging any closing exceptions to the given log.

Parameters:
closeable - the object to close
name - the name of the resource
log - the log to use when reporting closure warnings, will use this class's own Logger if log == null

close

public static void close(FileChannel channel,
                         String name,
                         org.slf4j.Logger log,
                         boolean force)
Closes the given channel if it is available, logging any closing exceptions to the given log. The file's channel can optionally be forced to disk.

Parameters:
channel - the file channel
name - the name of the resource
log - the log to use when reporting warnings, will use this class's own Logger if log == null
force - forces the file channel to disk

close

public static void close(Closeable closeable,
                         String name)
Closes the given resource if it is available.

Parameters:
closeable - the object to close
name - the name of the resource

close

public static void close(Closeable closeable)
Closes the given resource if it is available.

Parameters:
closeable - the object to close

close

public static void close(Closeable... closeables)
Closes the given resources if they are available.

Parameters:
closeables - the objects to close

validateCharset

public static void validateCharset(String charset)
                            throws UnsupportedCharsetException
Throws:
UnsupportedCharsetException

normalizeCharset

public static String normalizeCharset(String charset)
This method will take off the quotes and double quotes of the charset


getCharsetName

public static String getCharsetName(Exchange exchange)

getCharsetName

public static String getCharsetName(Exchange exchange,
                                    boolean useDefault)
Gets the charset name if set as property Exchange.CHARSET_NAME.

Parameters:
exchange - the exchange
useDefault - should we fallback and use JVM default charset if no property existed?
Returns:
the charset, or null if no found


Apache CAMEL