com.zipxap.vfs.dal.utility
Class FileTools

java.lang.Object
  extended by com.zipxap.vfs.dal.utility.FileTools

public class FileTools
extends java.lang.Object

This class contains a collection of utilities for working with Files (and directories).

Custom code placed here will not be overwritten/deleted by the generator. If this file is manually deleted, it will be regenerated.

Copyright 2009 ZipXap Technology, LLC. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA or visit http://www.gnu.org/licenses/lgpl.html.


Method Summary
static byte[] byteArrayFromFile(java.io.File inFile)
          Reads a file into a byte array using non-blocking I/O.
static void byteArrayToFile(java.io.File outFile, byte[] content)
          Writes the byte array to file using non-blocking I/O.
static boolean deleteRecursive(java.io.File rootDirectoryOrFile, boolean continueThroughFailures)
          Delete the directory and all files and subdirectories contained under it.
static java.util.List<java.io.File> findFilesWithName(java.io.File rootDirectory, java.lang.String filename)
           
static java.lang.String getNewlineSequence()
           
static java.util.List<java.lang.String> loadFile(java.io.File file)
          Load the specified file into a List, breaking it up by line.
static java.lang.String loadFileAsSingleString(java.io.File file)
           
static java.util.List<java.lang.String> loadFileTrimUpperCase(java.io.File file)
          Load the specified file into a List, breaking it up by line, trimming each line, and converting it to uppercase.
static java.util.List<java.lang.String> loadFileUpperCase(java.io.File file)
          Load the specified file into a List, breaking it up by line, and converting it to uppercase.
static java.lang.String loadFromReader(java.io.Reader reader)
          Retrieve the contents of the Reader and close the reader.
static void saveFile(java.io.File file, java.util.Collection<java.lang.String> lines)
          Save the lines in the collection to the specified file, placing a newline sequence between each line.
static void saveFile(java.io.File file, java.lang.String content)
          Save the specified content to the specified file, placing a newline sequence between each line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadFileTrimUpperCase

public static java.util.List<java.lang.String> loadFileTrimUpperCase(java.io.File file)
Load the specified file into a List, breaking it up by line, trimming each line, and converting it to uppercase. A line is terminated by a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Parameters:
file -
Returns:
the lines contained in the specified File.

loadFileUpperCase

public static java.util.List<java.lang.String> loadFileUpperCase(java.io.File file)
Load the specified file into a List, breaking it up by line, and converting it to uppercase. A line is terminated by a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Parameters:
file -
Returns:
the lines contained in the specified File.

loadFile

public static java.util.List<java.lang.String> loadFile(java.io.File file)
Load the specified file into a List, breaking it up by line. A line is terminated by a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Parameters:
file -
Returns:
the lines contained in the specified File.

loadFileAsSingleString

public static java.lang.String loadFileAsSingleString(java.io.File file)

saveFile

public static void saveFile(java.io.File file,
                            java.lang.String content)
Save the specified content to the specified file, placing a newline sequence between each line.

Parameters:
file - file The output file to create.
content - the content to save to the output file.

saveFile

public static void saveFile(java.io.File file,
                            java.util.Collection<java.lang.String> lines)
Save the lines in the collection to the specified file, placing a newline sequence between each line.

Parameters:
file - The output file to create.
lines - the content lines to save to the output file.

getNewlineSequence

public static java.lang.String getNewlineSequence()

findFilesWithName

public static java.util.List<java.io.File> findFilesWithName(java.io.File rootDirectory,
                                                             java.lang.String filename)

byteArrayFromFile

public static byte[] byteArrayFromFile(java.io.File inFile)
Reads a file into a byte array using non-blocking I/O. The file must be less than Integer.MAX_VALUE (2 gigabytes) in size.

Parameters:
inFile - The file to read from.
Returns:
byte array containing the file.

byteArrayToFile

public static void byteArrayToFile(java.io.File outFile,
                                   byte[] content)
Writes the byte array to file using non-blocking I/O.

Parameters:
outFile - The file to write to.
content - the byte array to be written.

deleteRecursive

public static boolean deleteRecursive(java.io.File rootDirectoryOrFile,
                                      boolean continueThroughFailures)
Delete the directory and all files and subdirectories contained under it.

Parameters:
rootDirectoryOrFile - The file or directory to begin the recursive delete.
continueThroughFailures - when set to true, the method continues trying to delete other files/directories, despite failing to delete one or more files/directories. When set to false, this method abandons the recursion at the point of first failure, leaving the directory in an unknown state.
Returns:
true if all files/directories were deleted, starting with the specified root, else false if one or more files/directories failed to delete.

loadFromReader

public static java.lang.String loadFromReader(java.io.Reader reader)
Retrieve the contents of the Reader and close the reader.