net.sourceforge.jaulp.file.write
Class WriteFileUtils

java.lang.Object
  extended by net.sourceforge.jaulp.file.write.WriteFileUtils

public class WriteFileUtils
extends java.lang.Object

The Class WriteFileUtils provides methods for writing in files.

Version:
1.0
Author:
Asterios Raptis

Constructor Summary
WriteFileUtils()
           
 
Method Summary
static java.io.OutputStream getOutputStream(java.io.File file)
          Gets the output stream from a File object.
static java.io.OutputStream getOutputStream(java.io.File file, boolean createFile)
          Gets the output stream from a File object.
static java.io.Writer getWriter(java.io.File file)
          Gets a Writer from the given file object.
static java.io.Writer getWriter(java.io.File file, java.lang.String encoding, boolean createFile)
          Gets a Writer from the given file object.
static void readSourceFileAndWriteDestFile(java.lang.String srcfile, java.lang.String destFile)
          Writes the source file with the best performance to the destination file.
static void storeByteArrayToFile(byte[] data, java.io.File file)
          Saves a byte array to the given file.
static boolean string2File(java.io.File file, java.lang.String string2write)
          The Method string2File(File, String) writes the String to the File.
static void string2File(java.lang.String string2write, java.lang.String nameOfFile)
          The Method string2File() writes a String to the file.
static void write2File(java.io.Reader reader, java.io.Writer writer, boolean closeStream)
          The Method write2File() reads from an opened Reader and writes it to the opened Writer.
static void write2File(java.lang.String inputFile, java.lang.String outputFile)
          The Method write2File(String, String) copys a file from one filename to another.
static void write2File(java.lang.String inputFile, java.io.Writer writer, boolean closeWriter)
          The Method write2File() writes the File into the PrintWriter.
static void write2FileWithBuffer(java.lang.String inputFile, java.lang.String outputFile)
          The Method write2FileWithBuffer() copy the content from one file to another.
static void writeByteArrayToFile(java.io.File file, byte[] byteArray)
          Writes the given byte array to the given file.
static void writeByteArrayToFile(java.lang.String filename, byte[] byteArray)
          Writes the given byte array to a file.
static void writeLinesToFile(java.util.Collection<java.lang.String> collection, java.io.File output)
          Writes the input from the collection into the file.
static void writeLinesToFile(java.io.File output, java.util.List<java.lang.String> input, java.lang.String encoding)
          Writes the input from the collection into the file.
static void writeProperties2File(java.lang.String filename, java.util.Properties properties)
          The Method writeProperties2File(String, Properties) writes the Properties to the file.
static boolean writeStringToFile(java.io.File file, java.lang.String string2write, java.lang.String encoding)
          The Method writeStringToFile(File, String, String) writes the String to the File.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WriteFileUtils

public WriteFileUtils()
Method Detail

getOutputStream

public static java.io.OutputStream getOutputStream(java.io.File file)
                                            throws java.io.IOException
Gets the output stream from a File object.

Parameters:
file - the file.
Returns:
the output stream.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getOutputStream

public static java.io.OutputStream getOutputStream(java.io.File file,
                                                   boolean createFile)
                                            throws java.io.IOException
Gets the output stream from a File object.

Parameters:
file - the file
createFile - If true and the file does not exist it will be create a new file.
Returns:
the output stream
Throws:
FileDoesNotExistException - the file does not exist exception
java.io.IOException - Signals that an I/O exception has occurred.

getWriter

public static java.io.Writer getWriter(java.io.File file)
                                throws java.io.IOException
Gets a Writer from the given file object.

Parameters:
file - the file.
Returns:
the Writer.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getWriter

public static java.io.Writer getWriter(java.io.File file,
                                       java.lang.String encoding,
                                       boolean createFile)
                                throws java.io.IOException
Gets a Writer from the given file object.

Parameters:
file - the file
encoding - The encoding from the file.
createFile - the create file
Returns:
the Writer.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

readSourceFileAndWriteDestFile

public static void readSourceFileAndWriteDestFile(java.lang.String srcfile,
                                                  java.lang.String destFile)
Writes the source file with the best performance to the destination file.

Parameters:
srcfile - The source file.
destFile - The destination file.

storeByteArrayToFile

public static void storeByteArrayToFile(byte[] data,
                                        java.io.File file)
Saves a byte array to the given file.

Parameters:
data - The byte array to be saved.
file - The file to save the byte array.

string2File

public static boolean string2File(java.io.File file,
                                  java.lang.String string2write)
The Method string2File(File, String) writes the String to the File.

Parameters:
file - The File to write the String.
string2write - The String to write into the File.
Returns:
The Method return true if the String was write successfull to the file otherwise false.

string2File

public static void string2File(java.lang.String string2write,
                               java.lang.String nameOfFile)
The Method string2File() writes a String to the file.

Parameters:
string2write - The String to write into the file.
nameOfFile - The path to the file and name from the file from where we want to write the String.

write2File

public static void write2File(java.io.Reader reader,
                              java.io.Writer writer,
                              boolean closeStream)
The Method write2File() reads from an opened Reader and writes it to the opened Writer.

Parameters:
reader - The opened Reader.
writer - The opened Writer.
closeStream - If true then close the outputStream otherwise keep open.

write2File

public static void write2File(java.lang.String inputFile,
                              java.lang.String outputFile)
The Method write2File(String, String) copys a file from one filename to another.

Parameters:
inputFile - The Name from the File to read and copy.
outputFile - The Name from the File to write into.

write2File

public static void write2File(java.lang.String inputFile,
                              java.io.Writer writer,
                              boolean closeWriter)
The Method write2File() writes the File into the PrintWriter.

Parameters:
inputFile - The Name from the File to read and copy.
writer - The PrintWriter to write into.
closeWriter - If true then close the outputStream otherwise keep open.

write2FileWithBuffer

public static void write2FileWithBuffer(java.lang.String inputFile,
                                        java.lang.String outputFile)
The Method write2FileWithBuffer() copy the content from one file to another. It use a buffer as the name says.

Parameters:
inputFile - The Path to the File and name from the file from where we read.
outputFile - The Path to the File and name from the file from where we want to write.

writeByteArrayToFile

public static void writeByteArrayToFile(java.io.File file,
                                        byte[] byteArray)
                                 throws java.io.IOException
Writes the given byte array to the given file.

Parameters:
file - The file.
byteArray - The byte array.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

writeByteArrayToFile

public static void writeByteArrayToFile(java.lang.String filename,
                                        byte[] byteArray)
                                 throws java.io.IOException
Writes the given byte array to a file.

Parameters:
filename - The filename from the file.
byteArray - The byte array.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

writeLinesToFile

public static void writeLinesToFile(java.util.Collection<java.lang.String> collection,
                                    java.io.File output)
Writes the input from the collection into the file.

Parameters:
collection - The collection to write to file.
output - The output-file.

writeLinesToFile

public static void writeLinesToFile(java.io.File output,
                                    java.util.List<java.lang.String> input,
                                    java.lang.String encoding)
Writes the input from the collection into the file.

Parameters:
output - The file to write the lines.
input - The list with the input data.
encoding - The encoding.

writeProperties2File

public static void writeProperties2File(java.lang.String filename,
                                        java.util.Properties properties)
The Method writeProperties2File(String, Properties) writes the Properties to the file.

Parameters:
filename - The filename from the file to write the properties.
properties - The properties.

writeStringToFile

public static boolean writeStringToFile(java.io.File file,
                                        java.lang.String string2write,
                                        java.lang.String encoding)
The Method writeStringToFile(File, String, String) writes the String to the File.

Parameters:
file - The File to write the String.
string2write - The String to write into the File.
encoding - The encoding from the file.
Returns:
The Method return true if the String was write successfull to the file otherwise false.


Copyright © 2010. All Rights Reserved.