net.sf.jpkgmk.util
Class FileUtil

java.lang.Object
  extended by net.sf.jpkgmk.util.FileUtil

public class FileUtil
extends java.lang.Object

Since:
1.0
Version:
$Revision: 2 $ $Date: 2008-08-20 21:14:19 +0200 (Mi, 20 Aug 2008) $
Author:
gommma (gommma AT users.sourceforge.net), Last changed by: $Author: gommma $

Field Summary
static java.lang.String UNIX_FILE_SEPARATOR
           
 
Method Summary
static void assertContainsFiles(java.io.File dirToCheck, java.io.File[] expectedFiles)
          Non-recursively checks the content of the given directory against the given array of file objects.
static java.lang.String buildPath(java.io.File fileOrDir, java.lang.String pathSeparator)
          Builds a path and separates the given file or directory using the given pathSeparator.
static void copyFile(java.io.File sourceFile, java.io.File destFile)
          Copies one file to a different location
static void copyFiles(java.io.File sourceDir, java.io.File targetDir, java.io.FileFilter fileFilter)
          Recursively copies the source directory with all files to the target directory.
static int countFiles(java.io.File directory)
          Recursively counts the files in the given directory.
static int countFiles(java.io.File directory, boolean countDirectories)
          Recursively counts the files in the given directory.
static int countFilesAndDirectories(java.io.File directory)
          Recursively counts the files in the given directory.
static void createDir(java.io.File dir, boolean failOnError)
           
static java.io.File createGzip(java.io.File inputFile)
          Creates a ".gz" file of the given input file.
static void createTar(java.io.File directoryToPack, java.io.File targetTarFile)
          Creates a tar file of all files in the given directory.
static void deleteRecursively(java.io.File fileOrDirectory)
           
static java.lang.Long getBlockCount(java.io.File basedir)
          Returns the number of 512 byte blocks that are needed to store the given directory.
static java.util.List<java.io.File> getFiles(java.io.File destDir, java.io.FileFilter filter)
          Returns all files and directories from the given dir recursively
static long getSize(java.io.File basedir)
           
static boolean isRelocatable(java.lang.String path)
          Determines if the given unix path is a relocatable path or not in the sense of a prototype file.
static boolean isSubdir(java.io.File subDirToCheck, java.io.File basedir)
           
static java.lang.String readFile(java.io.File file)
           
static java.lang.String readString(java.io.InputStream input)
          Reads the bytes from the given input stream using the default platform character set.
static java.lang.String readString(java.io.InputStream input, java.nio.charset.Charset charset)
          Reads the string from the given input stream using the given charset.
static java.lang.String readString(java.net.URL file)
           
static void writeFile(java.io.File target, java.lang.String content)
           
static void writeFile(java.io.File target, java.lang.String content, java.nio.charset.Charset charset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIX_FILE_SEPARATOR

public static java.lang.String UNIX_FILE_SEPARATOR
Method Detail

createGzip

public static java.io.File createGzip(java.io.File inputFile)
Creates a ".gz" file of the given input file.

Parameters:
inputFile -
Returns:
Returns the newly created file

createTar

public static void createTar(java.io.File directoryToPack,
                             java.io.File targetTarFile)
                      throws java.io.IOException
Creates a tar file of all files in the given directory.

Parameters:
directoryToPack - The directory to be packed
targetTarFile - The target file for storing the new tar
Throws:
java.io.IOException

deleteRecursively

public static void deleteRecursively(java.io.File fileOrDirectory)

writeFile

public static void writeFile(java.io.File target,
                             java.lang.String content)
                      throws java.io.IOException
Throws:
java.io.IOException

writeFile

public static void writeFile(java.io.File target,
                             java.lang.String content,
                             java.nio.charset.Charset charset)
                      throws java.io.IOException
Throws:
java.io.IOException

readFile

public static java.lang.String readFile(java.io.File file)
                                 throws java.io.IOException
Throws:
java.io.IOException

readString

public static java.lang.String readString(java.net.URL file)
                                   throws java.io.IOException
Throws:
java.io.IOException

readString

public static java.lang.String readString(java.io.InputStream input)
                                   throws java.io.IOException
Reads the bytes from the given input stream using the default platform character set. It is strongly recommended that you use the method readString(InputStream, Charset) to ensure that the character conversion is correctly done.

Parameters:
input -
Returns:
Throws:
java.io.IOException

readString

public static java.lang.String readString(java.io.InputStream input,
                                          java.nio.charset.Charset charset)
                                   throws java.io.IOException
Reads the string from the given input stream using the given charset. Does not close the stream after reading.

Parameters:
input -
charset -
Returns:
Throws:
java.io.IOException

isSubdir

public static boolean isSubdir(java.io.File subDirToCheck,
                               java.io.File basedir)

buildPath

public static java.lang.String buildPath(java.io.File fileOrDir,
                                         java.lang.String pathSeparator)
Builds a path and separates the given file or directory using the given pathSeparator.

Parameters:
fileOrDir -
pathSeparator -
Returns:

getFiles

public static java.util.List<java.io.File> getFiles(java.io.File destDir,
                                                    java.io.FileFilter filter)
Returns all files and directories from the given dir recursively

Parameters:
destDir -
filter -
Returns:

copyFiles

public static void copyFiles(java.io.File sourceDir,
                             java.io.File targetDir,
                             java.io.FileFilter fileFilter)
                      throws java.io.IOException
Recursively copies the source directory with all files to the target directory. Includes all subdirectories and their files.

Parameters:
sourceDir -
targetDir -
fileFilter - File filter used for copying. Can be null which will include all files to the copy process.
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File sourceFile,
                            java.io.File destFile)
                     throws java.io.IOException
Copies one file to a different location

Parameters:
sourceFile -
destFile - The destination file
Throws:
java.io.IOException

createDir

public static void createDir(java.io.File dir,
                             boolean failOnError)

isRelocatable

public static boolean isRelocatable(java.lang.String path)
Determines if the given unix path is a relocatable path or not in the sense of a prototype file. It is relocatable if the path is relative (not starting with a '/').

Parameters:
path - The path to check.
Returns:

countFilesAndDirectories

public static int countFilesAndDirectories(java.io.File directory)
Recursively counts the files in the given directory. Subdirectories are also counted.

Parameters:
directory -
Returns:
The number of files/directories in the given directory

countFiles

public static int countFiles(java.io.File directory)
Recursively counts the files in the given directory. Subdirectories are not counted.

Parameters:
directory -
Returns:
The number of files in the given directory that are no directories

countFiles

public static int countFiles(java.io.File directory,
                             boolean countDirectories)
Recursively counts the files in the given directory. Subdirectories are not counted.

Parameters:
directory -
countDirectories - If subdirectories should also be included into the count
Returns:
The number of files in the given directory that are no directories

getBlockCount

public static java.lang.Long getBlockCount(java.io.File basedir)
Returns the number of 512 byte blocks that are needed to store the given directory.

Parameters:
basedir -
Returns:

getSize

public static long getSize(java.io.File basedir)
Parameters:
basedir -
Returns:
Returns the size in bytes of the content of the given directory

assertContainsFiles

public static void assertContainsFiles(java.io.File dirToCheck,
                                       java.io.File[] expectedFiles)
Non-recursively checks the content of the given directory against the given array of file objects.

Parameters:
dirToCheck -
expectedFiles -


Copyright © 2007-2008. All Rights Reserved.