ariba.util.core
Class IOUtil

java.lang.Object
  extended by ariba.util.core.IOUtil

public final class IOUtil
extends java.lang.Object

Input/Output Utilities. These are helper functions for dealing with i/o.


Nested Class Summary
static class IOUtil.BufferHolder
          Holds a byte buffer for use in this class while copying bytes around.
 
Field Summary
static int DefaultInternalBufferSize
          When internal buffers are used in buffered I/O, the size is specified by this value.
 
Method Summary
static java.io.BufferedInputStream bufferedInputStream(java.io.File file)
          Opens a binary file on top of a buffered layer.
static java.io.BufferedOutputStream bufferedOutputStream(java.io.File file)
          Opens a binary file on top of a buffered layer.
static java.io.BufferedOutputStream bufferedOutputStream(java.io.File file, boolean append)
          Opens a binary file on top of a buffered layer.
static java.io.BufferedReader bufferedReader(java.io.File file, java.lang.String encoding)
          Opens a text file on top of a buffered layer.
static java.io.BufferedReader bufferedReader(java.io.InputStream i, java.lang.String encoding)
          Opens a text stream over a binary one on top of a buffered layer.
static java.io.BufferedWriter bufferedWriter(java.io.OutputStream o, java.lang.String encoding)
          Open a writer with the specified encoding
static byte[] bytesFromURL(java.net.URL url)
          Read the contents of a URL as a byte array .
static void close(java.io.Closeable obj)
          Helper method to close an Object which implements Closeable interface without exceptions in a null safe manner.
static boolean copyDirectory(java.io.File source, java.io.File target)
          Copy recursively a directory Use this with caution.
static boolean copyDirectory(java.io.File source, java.io.File target, boolean recursive, boolean createTarget)
          Copy recursively a directory
Use this with caution.
static boolean copyFile(java.io.File sourceFile, java.io.File targetFile)
          Copy the contents of a file to another file.
static boolean copyFile(java.io.File sourceFile, java.io.File targetFile, byte[] buffer)
          Copy the contents of a file to another file.
static boolean copyFile(java.io.File sourceFile, java.io.File targetFile, char[] buffer)
          Deprecated. use copyFile(File, File, byte[])
static boolean copyFileIfNewer(java.io.File sourceFile, java.io.File targetFile)
          Copy a file if the source is newer than the target
static void copyUrlToFile(java.lang.String sourceURLString, java.io.File targetFile)
          Copy a URL (String format) to File.
static boolean deleteDirectory(java.io.File dir)
          Delete a directory and its subdirectories.
static java.lang.String executeURL(java.lang.String url)
          Returns the content of URL in String form using UTF8 encoding.
static java.lang.String executeURL(java.lang.String url, java.lang.String encoding)
          Execute the Url String.
static java.lang.String getDefaultSystemEncoding()
          Return the System Wide default encoding.
static int getInternalBufferHolderRecursionDepth()
          Returns the recursion depth of the internal per-thread BufferHolder.
static boolean grep(java.io.File file, java.lang.String regex)
          Returns true if the file contains a string matching regex and false otherwise.
static boolean grep(java.io.File file, java.lang.String regex, java.nio.charset.Charset charset)
          Returns true if the file contains a string matching regex and false otherwise.
static boolean grep(java.io.Reader reader, java.lang.String regex)
          Greps the supplied reader character stream for regex returning true the pattern is found in the character stream and false otherwise.
static boolean inputStreamToOutputStream(java.io.InputStream input, java.io.OutputStream output)
          Copies all data from an InputStream to an OutputStream.
static boolean inputStreamToOutputStream(java.io.InputStream input, java.io.OutputStream output, byte[] buffer, boolean flush)
          Copies all data from an InputStream to an OutputStream.
static int inputStreamToOutputStream(java.io.InputStream input, java.io.OutputStream output, byte[] buffer, boolean flush, int bytesToCopy)
          Deprecated. Use spool(java.io.InputStream, java.io.OutputStream, byte[], boolean, long) instead.
static byte[] makeByteBuffer()
          Returns a new byte array buffer of size DefaultInternalBufferSize.
static java.io.PrintWriter printWriter(java.io.File file, java.lang.String encoding)
          Opens a text file with a reasonable stream interface on top of a buffered layer.
static java.io.PrintWriter printWriter(java.io.OutputStream o, java.lang.String encoding)
          Open a text stream over a binary one on top of a buffered layer.
static java.io.PrintWriter printWriter(java.io.OutputStream o, java.lang.String encoding, boolean autoFlush)
          Open a text stream over a binary one on top of a buffered layer.
static boolean readerToWriter(java.io.Reader reader, java.io.Writer writer)
          Copy Reader to Writer.
static boolean readerToWriter(java.io.Reader reader, java.io.Writer writer, char[] buffer)
          Copy Reader to Writer.
static java.lang.String readFileContent(java.io.File file)
          Reads the first line from file assuming UTF-8.
static java.lang.String readFileContent(java.io.File file, java.nio.charset.Charset charset)
          Reads the entire contents from file using the specified charset to convert the bytes from the file into characters.
static java.lang.String readFirstLine(java.io.File file)
          Reads the first line from file assuming UTF-8.
static java.lang.String readFirstLine(java.io.File file, java.nio.charset.Charset charset)
          Reads and returns the first line from file using the specified charset to convert the bytes from the file into characters.
static java.lang.String readLine(java.io.InputStream in)
          Read a line from an InputStream.
static java.lang.String readLine(java.io.InputStream in, char[] lineBuffer)
          Read a line from an InputStream.
static java.util.List<java.lang.String> readLines(java.io.File file, java.nio.charset.Charset charset, int n)
          Reads and returns the first n lines from file using the specified charset to convert the bytes from the file into characters.
static void searchReplace(java.io.File input, java.io.File output, java.lang.String regexToFind, java.lang.String toReplace)
          Searches and replaces input replacing regexToFind with toReplace writing to output.
static void searchReplace(java.io.File input, java.io.File output, java.lang.String regexToFind, java.lang.String toReplace, java.nio.charset.Charset charset)
          Searches and replaces input replacing regexToFind with toReplace writing to output.
static void searchReplace(java.io.File input, java.io.Writer writer, java.lang.String regexToFind, java.lang.String toReplace)
          Searches and replaces input replacing regexToFind with toReplace writing to writer.
static void searchReplace(java.io.File input, java.io.Writer writer, java.lang.String regexToFind, java.lang.String toReplace, java.nio.charset.Charset charset)
          Searches and replaces file replacing regexToFind with toReplace writing to writer.
static void searchReplace(java.io.Reader reader, java.io.Writer writer, java.lang.String regexToFind, java.lang.String toReplace)
          Searches the reader character stream and replaces every occurrence of regexToFind with the replacement string toReplace.
static int spool(java.io.InputStream input, byte[] buffer)
          Copies up to buffer.length bytes from input to buffer.
static long spool(java.io.InputStream input, java.io.OutputStream output)
          Copies all the bytes from input to output.
static long spool(java.io.InputStream input, java.io.OutputStream output, byte[] buffer, boolean flushOutput, long length)
          Copies up to length bytes from input to output using the supplied buffer.
static long spool(java.io.InputStream input, java.io.OutputStream output, byte[] buffer, long length)
          Copies up to length bytes from input to output using the supplied buffer.
static long spool(java.io.InputStream input, java.io.OutputStream output, long length)
          Copies up to length bytes from input to output.
static java.lang.String stringFromURL(java.net.URL url, java.lang.String encoding)
          Read the contents of a URL as a string.
static void writeToFile(java.io.File file, java.lang.Object object, boolean append)
          Writes object to file assuming UTF-8.
static void writeToFile(java.io.File file, java.lang.Object object, boolean append, java.nio.charset.Charset charset)
          Writes object to file using the specified charset.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DefaultInternalBufferSize

public static final int DefaultInternalBufferSize
When internal buffers are used in buffered I/O, the size is specified by this value.

See Also:
Constant Field Values
Method Detail

getInternalBufferHolderRecursionDepth

public static int getInternalBufferHolderRecursionDepth()
Returns the recursion depth of the internal per-thread BufferHolder.

Returns:
the per-thread BufferHolder recursion depth

makeByteBuffer

public static byte[] makeByteBuffer()
Returns a new byte array buffer of size DefaultInternalBufferSize. This method is used by this class for internal buffer allocation.


printWriter

public static java.io.PrintWriter printWriter(java.io.File file,
                                              java.lang.String encoding)
                                       throws java.io.IOException
Opens a text file with a reasonable stream interface on top of a buffered layer.

Parameters:
file - the file to open
encoding - the encoding to use
Returns:
a buffered PrintWriter wrapped around the file
Throws:
java.io.IOException - if there was an error opening the file

printWriter

public static java.io.PrintWriter printWriter(java.io.OutputStream o,
                                              java.lang.String encoding)
                                       throws java.io.UnsupportedEncodingException
Open a text stream over a binary one on top of a buffered layer.

Throws:
java.io.UnsupportedEncodingException

printWriter

public static java.io.PrintWriter printWriter(java.io.OutputStream o,
                                              java.lang.String encoding,
                                              boolean autoFlush)
                                       throws java.io.UnsupportedEncodingException
Open a text stream over a binary one on top of a buffered layer.

Throws:
java.io.UnsupportedEncodingException

bufferedWriter

public static java.io.BufferedWriter bufferedWriter(java.io.OutputStream o,
                                                    java.lang.String encoding)
                                             throws java.io.UnsupportedEncodingException
Open a writer with the specified encoding

Throws:
java.io.UnsupportedEncodingException

bufferedReader

public static java.io.BufferedReader bufferedReader(java.io.File file,
                                                    java.lang.String encoding)
                                             throws java.io.IOException
Opens a text file on top of a buffered layer.

Parameters:
file - the File to opened
encoding - the encoding to use
Returns:
a BufferedReader around the file
Throws:
java.io.IOException - if there was an error opening the file

bufferedReader

public static java.io.BufferedReader bufferedReader(java.io.InputStream i,
                                                    java.lang.String encoding)
                                             throws java.io.UnsupportedEncodingException
Opens a text stream over a binary one on top of a buffered layer.

Throws:
java.io.UnsupportedEncodingException

bufferedInputStream

public static java.io.BufferedInputStream bufferedInputStream(java.io.File file)
                                                       throws java.io.IOException
Opens a binary file on top of a buffered layer.

Parameters:
file - the file to open
Returns:
a BufferedInputStream wrapping the file
Throws:
java.io.IOException - if there was an error opening the file

bufferedOutputStream

public static java.io.BufferedOutputStream bufferedOutputStream(java.io.File file)
                                                         throws java.io.IOException
Opens a binary file on top of a buffered layer.

Parameters:
file - the file to open
Returns:
a BufferedOutputStream wrapping the file
Throws:
java.io.IOException - if there was an error opening the file

bufferedOutputStream

public static java.io.BufferedOutputStream bufferedOutputStream(java.io.File file,
                                                                boolean append)
                                                         throws java.io.IOException
Opens a binary file on top of a buffered layer.

Parameters:
file - the file to open
append - true to append to the file, false otherwise.
Returns:
a BufferedOutputStream wrapping the file
Throws:
java.io.IOException - if there was an error opening the file

readLine

public static java.lang.String readLine(java.io.InputStream in)
                                 throws java.io.IOException
Read a line from an InputStream.

Parameters:
in - the stream to read from
Returns:
the line read, without the newline, or null if there is no more data
Throws:
java.io.IOException - if there was an error in reading from the stream

readLine

public static java.lang.String readLine(java.io.InputStream in,
                                        char[] lineBuffer)
                                 throws java.io.IOException
Read a line from an InputStream.

Parameters:
in - the stream to read from
lineBuffer - a buffer to use for reading the lines. Performance is better if the buffer is big enough for the longest line.
Returns:
the line read, without the newline, or null if there is no more data
Throws:
java.io.IOException - if there was an error in reading from the stream

copyFileIfNewer

public static boolean copyFileIfNewer(java.io.File sourceFile,
                                      java.io.File targetFile)
Copy a file if the source is newer than the target

Parameters:
sourceFile - the source of the copy
targetFile - the target of the copy
Returns:
false if there was a problem.

copyFile

public static boolean copyFile(java.io.File sourceFile,
                               java.io.File targetFile)
Copy the contents of a file to another file.

Parameters:
sourceFile - the source
targetFile - the target
Returns:
false if there was a problem. true otherwise.

copyFile

public static boolean copyFile(java.io.File sourceFile,
                               java.io.File targetFile,
                               char[] buffer)
Deprecated. use copyFile(File, File, byte[])

Copy the contents of a file to another file.

Parameters:
sourceFile - the source of the copy
targetFile - the target of the copy
buffer - a buffer to use for the copy
Returns:
false if there was a problem. true otherwise.

copyFile

public static boolean copyFile(java.io.File sourceFile,
                               java.io.File targetFile,
                               byte[] buffer)
Copy the contents of a file to another file.

Parameters:
sourceFile - the source of the copy
targetFile - the target of the copy
buffer - a buffer to use for the copy
Returns:
false if there was a problem. true otherwise.

readerToWriter

public static boolean readerToWriter(java.io.Reader reader,
                                     java.io.Writer writer)
Copy Reader to Writer.

Parameters:
reader - the source of the copy
writer - the destination of the copy, null if none
Returns:
false if there was a problem.

readerToWriter

public static boolean readerToWriter(java.io.Reader reader,
                                     java.io.Writer writer,
                                     char[] buffer)
Copy Reader to Writer.

Parameters:
reader - the source of the copy
writer - the destination of the copy, null if none
buffer - a buffer to use for the copy
Returns:
false if there was a problem.

spool

public static long spool(java.io.InputStream input,
                         java.io.OutputStream output,
                         byte[] buffer,
                         boolean flushOutput,
                         long length)
                  throws java.io.IOException
Copies up to length bytes from input to output using the supplied buffer.

The copying stops if input is exhausted before length bytes are copied. The actual number of bytes copied is returned.

Notes:

Parameters:
input - the stream to read from
output - the stream to write to
buffer - the byte buffer to use
flushOutput - if true flush output on each write
length - the maximum number of bytes to copy
Returns:
the number of bytes copied
Throws:
java.io.IOException

spool

public static long spool(java.io.InputStream input,
                         java.io.OutputStream output,
                         byte[] buffer,
                         long length)
                  throws java.io.IOException
Copies up to length bytes from input to output using the supplied buffer.

The copying stops if input is exhausted before length bytes are copied. The actual number of bytes copied is returned.

Notes:

Parameters:
input - the stream to read from
output - the stream to write to
buffer - the byte buffer to use
length - the maximum number of bytes to copy
Returns:
the number of bytes copied
Throws:
java.io.IOException

spool

public static long spool(java.io.InputStream input,
                         java.io.OutputStream output,
                         long length)
                  throws java.io.IOException
Copies up to length bytes from input to output.

The copying stops if input is exhausted before length bytes are copied. The actual number of bytes copied is returned.

Notes:

Parameters:
input - the stream to read from
output - the stream to write to
length - the maximum number of bytes to copy
Returns:
the number of bytes copied
Throws:
java.io.IOException

spool

public static long spool(java.io.InputStream input,
                         java.io.OutputStream output)
                  throws java.io.IOException
Copies all the bytes from input to output.

The copying stops when input is exhausted. The actual number of bytes copied is returned.

Parameters:
input - the stream to read from
output - the stream to write to
Returns:
the number of bytes copied
Throws:
java.io.IOException

spool

public static int spool(java.io.InputStream input,
                        byte[] buffer)
                 throws java.io.IOException
Copies up to buffer.length bytes from input to buffer.

The copying stops if input is exhausted before buffer is filled. The actual number of bytes copied is returned.

Parameters:
input - the stream to read from
buffer - the byte buffer to write to
Returns:
the number of bytes copied
Throws:
java.io.IOException

inputStreamToOutputStream

public static boolean inputStreamToOutputStream(java.io.InputStream input,
                                                java.io.OutputStream output)
Copies all data from an InputStream to an OutputStream.

If you wish to use a method which throws an IOException see spool(InputStream,OutputStream).

Parameters:
input - the source of the copy
output - the destination of the copy, null if none
Returns:
false if there was a problem.

inputStreamToOutputStream

public static boolean inputStreamToOutputStream(java.io.InputStream input,
                                                java.io.OutputStream output,
                                                byte[] buffer,
                                                boolean flush)
Copies all data from an InputStream to an OutputStream.

If you wish to use a method which throws an IOException see the spool method taking the same arguments.

Parameters:
input - the source of the copy
output - the destination of the copy, null if none
buffer - a buffer to use for copying
flush - if true output is flushed after every write call
Returns:
false if there was a problem.

inputStreamToOutputStream

public static int inputStreamToOutputStream(java.io.InputStream input,
                                            java.io.OutputStream output,
                                            byte[] buffer,
                                            boolean flush,
                                            int bytesToCopy)
                                     throws java.io.IOException
Deprecated. Use spool(java.io.InputStream, java.io.OutputStream, byte[], boolean, long) instead.

Copies the specified amount of data from an InputStream to an OutputStream.

Parameters:
input - the source of the copy
output - the destination of the copy, null if none
buffer - a buffer to use for copying
flush - if true output is flushed after every write call
bytesToCopy - the number of bytes to copy
Returns:
the number of bytes copied
Throws:
java.io.IOException

bytesFromURL

public static byte[] bytesFromURL(java.net.URL url)
Read the contents of a URL as a byte array .

Parameters:
url - the URL to read
Returns:
the contents of the URL, or null if there are any problems

executeURL

public static java.lang.String executeURL(java.lang.String url,
                                          java.lang.String encoding)
Execute the Url String. Going forward this method name makes sense for executing Url The reason for not using IOUtil.stringFromURL() api is that it uses the available() method on InputStream which is not advisable to determine the content length. This method will return the content existing at the given URL in the String form using the encoding passed. If encoding is passed as null, then it will use the UTF8 encoding.

Parameters:
url - the URL to read
encoding - encoding of the content present at given url
Returns:
the contents of the URL, or null if there are any problems

executeURL

public static java.lang.String executeURL(java.lang.String url)
Returns the content of URL in String form using UTF8 encoding.

Parameters:
url - the URL to read
Returns:
the contents of the URL, or null if there are any problems

stringFromURL

public static java.lang.String stringFromURL(java.net.URL url,
                                             java.lang.String encoding)
Read the contents of a URL as a string.

Parameters:
url - the URL to read
encoding - the encoding to use (as in a String constructor). If encoding is null, we use the default encoding
Returns:
the contents of the URL, or null if there are any problems

copyUrlToFile

public static void copyUrlToFile(java.lang.String sourceURLString,
                                 java.io.File targetFile)
                          throws java.io.FileNotFoundException,
                                 java.net.MalformedURLException,
                                 java.io.IOException
Copy a URL (String format) to File.

Parameters:
sourceURLString - the URL string reference source content
targetFile - the destination for the content
Throws:
java.io.FileNotFoundException
java.net.MalformedURLException
java.io.IOException

copyDirectory

public static boolean copyDirectory(java.io.File source,
                                    java.io.File target)
Copy recursively a directory Use this with caution. If an error occurs during the recursive copy, partial copying or deletion may result!

Parameters:
source - The source
target - The target
Returns:
false if there was a problem.
Throws:
java.lang.NullPointerException - if one of the arguments is null

copyDirectory

public static boolean copyDirectory(java.io.File source,
                                    java.io.File target,
                                    boolean recursive,
                                    boolean createTarget)
Copy recursively a directory
Use this with caution. If an error occurs during the recursive copy, partial copying or deletion may result!

Parameters:
source - The source. It has to be a directory that exists.
target - The target
recursive - if true, will also copy the subdirectories
createTarget - if true, will create the target and its subdirectories if needed
Returns:
false if there was a problem.
Throws:
java.lang.NullPointerException - if one the source or the target is null

deleteDirectory

public static boolean deleteDirectory(java.io.File dir)
Delete a directory and its subdirectories. Use this with caution. If an error occurs during the recursive delete, partial copying or deletion may result!

Parameters:
dir - Directory to delete. It has to be a directory that exists.
Returns:
false if there was a problem.
Throws:
java.lang.NullPointerException - if the argument is null

getDefaultSystemEncoding

public static java.lang.String getDefaultSystemEncoding()
Return the System Wide default encoding. This is not the method you are looking for, move along.


close

public static void close(java.io.Closeable obj)
Helper method to close an Object which implements Closeable interface without exceptions in a null safe manner.

Parameters:
obj - Object needs to be closed

grep

public static boolean grep(java.io.Reader reader,
                           java.lang.String regex)
                    throws java.io.IOException
Greps the supplied reader character stream for regex returning true the pattern is found in the character stream and false otherwise.

Notes:

Parameters:
reader - the character stream
regex - the regular expression
Throws:
java.io.IOException

grep

public static boolean grep(java.io.File file,
                           java.lang.String regex,
                           java.nio.charset.Charset charset)
                    throws java.io.IOException
Returns true if the file contains a string matching regex and false otherwise.

Parameters:
file - the file
regex - the regular expression
charset - the character set used by file
Throws:
java.io.IOException

grep

public static boolean grep(java.io.File file,
                           java.lang.String regex)
                    throws java.io.IOException
Returns true if the file contains a string matching regex and false otherwise.

Parameters:
file - the file (UTF-8 encoding assumed)
regex - the regular expression
Throws:
java.io.IOException

searchReplace

public static void searchReplace(java.io.Reader reader,
                                 java.io.Writer writer,
                                 java.lang.String regexToFind,
                                 java.lang.String toReplace)
                          throws java.io.IOException
Searches the reader character stream and replaces every occurrence of regexToFind with the replacement string toReplace. Captured groups in regexToFind can be referenced in toReplace using the standard mechanism (e.g. $1 references the first group etc.)

No support currently for across-line regexes.

This method does not close either reader or writer.

Throws:
java.io.IOException

searchReplace

public static void searchReplace(java.io.File input,
                                 java.io.Writer writer,
                                 java.lang.String regexToFind,
                                 java.lang.String toReplace,
                                 java.nio.charset.Charset charset)
                          throws java.io.IOException
Searches and replaces file replacing regexToFind with toReplace writing to writer.

Throws:
java.io.IOException

searchReplace

public static void searchReplace(java.io.File input,
                                 java.io.Writer writer,
                                 java.lang.String regexToFind,
                                 java.lang.String toReplace)
                          throws java.io.IOException
Searches and replaces input replacing regexToFind with toReplace writing to writer.

Throws:
java.io.IOException

searchReplace

public static void searchReplace(java.io.File input,
                                 java.io.File output,
                                 java.lang.String regexToFind,
                                 java.lang.String toReplace,
                                 java.nio.charset.Charset charset)
                          throws java.io.IOException
Searches and replaces input replacing regexToFind with toReplace writing to output.

Throws:
java.io.IOException

searchReplace

public static void searchReplace(java.io.File input,
                                 java.io.File output,
                                 java.lang.String regexToFind,
                                 java.lang.String toReplace)
                          throws java.io.IOException
Searches and replaces input replacing regexToFind with toReplace writing to output.

Throws:
java.io.IOException

readFirstLine

public static java.lang.String readFirstLine(java.io.File file,
                                             java.nio.charset.Charset charset)
                                      throws java.io.IOException
Reads and returns the first line from file using the specified charset to convert the bytes from the file into characters.

Parameters:
file - the file to read from
charset - the encoding to be used when reading the file
Returns:
the first line
Throws:
java.io.IOException

readLines

public static java.util.List<java.lang.String> readLines(java.io.File file,
                                                         java.nio.charset.Charset charset,
                                                         int n)
                                                  throws java.io.IOException
Reads and returns the first n lines from file using the specified charset to convert the bytes from the file into characters. Use the method with care. n should typically be small as the lines are in memory

Parameters:
file - the file to read from
charset - the encoding to be used when reading the file
n - number of lines to read
Returns:
the first line
Throws:
java.io.IOException

readFirstLine

public static java.lang.String readFirstLine(java.io.File file)
                                      throws java.io.IOException
Reads the first line from file assuming UTF-8.

Parameters:
file - the file to read from
Returns:
the first line
Throws:
java.io.IOException

readFileContent

public static java.lang.String readFileContent(java.io.File file,
                                               java.nio.charset.Charset charset)
                                        throws java.io.IOException
Reads the entire contents from file using the specified charset to convert the bytes from the file into characters.

Parameters:
file - the file to read from
charset - the encoding to be used when reading the file
Returns:
the entire file content
Throws:
java.io.IOException

readFileContent

public static java.lang.String readFileContent(java.io.File file)
                                        throws java.io.IOException
Reads the first line from file assuming UTF-8.

Parameters:
file - the file to read from
Returns:
the first line
Throws:
java.io.IOException

writeToFile

public static void writeToFile(java.io.File file,
                               java.lang.Object object,
                               boolean append,
                               java.nio.charset.Charset charset)
                        throws java.io.IOException
Writes object to file using the specified charset.

Parameters:
file - the file to write to
object - the object to write (toString() is called)
append - whether to append to the file or to truncate and write
charset - the encoding to use
Throws:
java.io.IOException

writeToFile

public static void writeToFile(java.io.File file,
                               java.lang.Object object,
                               boolean append)
                        throws java.io.IOException
Writes object to file assuming UTF-8.

Parameters:
file - the file to write to
object - the object to write (toString() is called)
append - whether to append to the file or to truncate and write
Throws:
java.io.IOException


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.