org.openbp.common.io
Class IOUtil

java.lang.Object
  extended by org.openbp.common.io.IOUtil

public final class IOUtil
extends java.lang.Object

The FileUtil class provides some additional static file management utility methods not contained in java.io.File. The class contains static method only.

Author:
Heiko Erhardt

Field Summary
static java.lang.String CHAR_SET_ISO_8859_1
           
static java.lang.String CHAR_SET_UTF_8
           
 
Method Summary
static java.lang.String readTextFile(java.io.File inputFile)
          Reads a text file.
static java.lang.String readTextFile(java.io.InputStream in)
          Reads a text file stream.
static java.lang.String readTextFile(java.lang.String inputFileName)
          Reads a text file.
static boolean writeFile(java.lang.String outputFileName, byte[] outBytes, RetryNotifier rn)
          Write a byte array to file.
static boolean writeFile(java.lang.String outputFileName, byte[] outBytes, RetryNotifier rn, boolean append)
          Write a byte array to file.
static boolean writeFile(java.lang.String outputFileName, byte[] outBytes, RetryNotifier rn, java.lang.String charSet)
          Write a byte array to file.
static boolean writeFile(java.lang.String outputFileName, byte[] outBytes, RetryNotifier rn, java.lang.String charSet, boolean append)
          Write a byte array to file.
static boolean writeFile(java.lang.String outputFileName, java.lang.String outString, RetryNotifier rn)
          Write a string to file.
static boolean writeFile(java.lang.String outputFileName, java.lang.String outString, RetryNotifier rn, boolean append)
          Write a string to file.
static boolean writeFile(java.lang.String outputFileName, java.lang.String outString, RetryNotifier rn, java.lang.String charSet)
          Write a string to file.
static boolean writeFile(java.lang.String outputFileName, java.lang.String outString, RetryNotifier rn, java.lang.String charSet, boolean append)
          Write a string to file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHAR_SET_UTF_8

public static final java.lang.String CHAR_SET_UTF_8
See Also:
Constant Field Values

CHAR_SET_ISO_8859_1

public static final java.lang.String CHAR_SET_ISO_8859_1
See Also:
Constant Field Values
Method Detail

readTextFile

public static java.lang.String readTextFile(java.io.InputStream in)
                                     throws java.io.IOException
Reads a text file stream.

Parameters:
in - Inputstream
Returns:
The contents of the file.
The lines will be separated by "\\n".
Throws:
java.io.IOException - On i/o error

readTextFile

public static java.lang.String readTextFile(java.lang.String inputFileName)
                                     throws java.io.IOException
Reads a text file.

Parameters:
inputFileName - Name of the file to read
Returns:
The contents of the file.
The lines will be separated by "\\n".
Throws:
java.io.IOException - On i/o error

readTextFile

public static java.lang.String readTextFile(java.io.File inputFile)
                                     throws java.io.IOException
Reads a text file.

Parameters:
inputFile - File to read
Returns:
The contents of the file.
The lines will be separated by "\\n".
Throws:
java.io.IOException - On i/o error

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                java.lang.String outString,
                                RetryNotifier rn)
                         throws java.io.IOException
Write a string to file.

Parameters:
outString - String to save; When writing the string, UTF8 encoding will be used
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                java.lang.String outString,
                                RetryNotifier rn,
                                boolean append)
                         throws java.io.IOException
Write a string to file.

Parameters:
outString - String to save; When writing the string, UTF8 encoding will be used
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
append - true The string/byteArray will be appended to the file if the file exists.
false A new file will be created if the file does not exist.
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                java.lang.String outString,
                                RetryNotifier rn,
                                java.lang.String charSet)
                         throws java.io.IOException
Write a string to file.

Parameters:
outString - String to save; When writing the string, UTF8 encoding will be used
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
charSet - The character set to be used, i.e. UTF-8, ISO 8859-1 etc. If null, then the UTF-8 character set will be used.
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                java.lang.String outString,
                                RetryNotifier rn,
                                java.lang.String charSet,
                                boolean append)
                         throws java.io.IOException
Write a string to file.

Parameters:
outString - String to save; When writing the string, UTF8 encoding will be used
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
charSet - The character set to be used, i.e. UTF-8, ISO 8859-1 etc. If null, then the UTF-8 character set will be used.
append - true The string/byteArray will be appended to the file if the file exists.
false A new file will be created if the file does not exist.
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                byte[] outBytes,
                                RetryNotifier rn)
                         throws java.io.IOException
Write a byte array to file.

Parameters:
outBytes - Byte array to save
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                byte[] outBytes,
                                RetryNotifier rn,
                                boolean append)
                         throws java.io.IOException
Write a byte array to file.

Parameters:
outBytes - Byte array to save
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
append - true The string/byteArray will be appended to the file if the file exists.
false A new file will be created if the file does not exist.
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                byte[] outBytes,
                                RetryNotifier rn,
                                java.lang.String charSet)
                         throws java.io.IOException
Write a byte array to file.

Parameters:
outBytes - Byte array to save
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
charSet - The character set to be used, i.e. UTF-8, ISO 8859-1 etc. If null, then the UTF-8 character set will be used.
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.

writeFile

public static boolean writeFile(java.lang.String outputFileName,
                                byte[] outBytes,
                                RetryNotifier rn,
                                java.lang.String charSet,
                                boolean append)
                         throws java.io.IOException
Write a byte array to file.

Parameters:
outBytes - Byte array to save
outputFileName - File name
rn - Retry notifier object to be called in case of i/o error or null to suppress retries
charSet - The character set to be used, i.e. UTF-8, ISO 8859-1 etc. If null, then the UTF-8 character set will be used.
append - true The string/byteArray will be appended to the file if the file exists.
false A new file will be created if the file does not exist.
Returns:
true The file was successfully written.
false There was a file write error and the retry notification method returned false (this usually means that the user chose 'Abort').
Throws:
java.io.IOException - On error if there is no retry notifier supplied.


Copyright © 2011. All Rights Reserved.