org.apache.servicemix.util
Class FileUtil

java.lang.Object
  extended by org.apache.servicemix.util.FileUtil

public final class FileUtil
extends java.lang.Object

File utilities

Version:
$Revision: 658853 $

Method Summary
static boolean archiveContainsEntry(java.io.File theFile, java.lang.String name)
          Validate that an archive contains a named entry
static boolean buildDirectory(java.io.File file)
          Build a directory path - creating directories if neccesary
static void copyInputStream(java.io.InputStream in, java.io.OutputStream out)
          Copy in stream to an out stream
static int countFilesInDirectory(java.io.File directory)
          Count files in a directory (including files in all subdirectories)
static java.io.File createUniqueDirectory(java.io.File rootDir, java.lang.String seed)
          Create a unique directory within a directory 'root'
static boolean deleteFile(java.io.File fileToDelete)
          Delete a file
static void fastCopy(java.io.InputStream input, java.io.OutputStream output)
          Copies the whole content from the input stream to the output stream using nio channels to speed it up.
static java.io.File getDirectoryPath(java.io.File parent, java.lang.String subDirectory)
          Build a path- but do not create it
static boolean isFileFullyAvailable(java.io.File file)
          checks whether a file is fully transmitted or still being copied
static boolean isFileFullyAvailable(java.lang.String path)
          checks whether a file is fully transmitted or still being copied
static void moveFile(java.io.File src, java.io.File targetDirectory)
          Move a File
static java.io.File unpackArchive(java.io.File theFile, java.io.File targetDir)
          Unpack a zip file
static java.io.File unpackArchive(java.net.URL url, java.io.File targetDir)
          Unpack an archive from a URL
static void zipDir(java.lang.String directory, java.lang.String zipName)
          Zip up a directory
static void zipDir(java.lang.String directory, java.util.zip.ZipOutputStream zos, java.lang.String path)
          Zip up a directory path
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

moveFile

public static void moveFile(java.io.File src,
                            java.io.File targetDirectory)
                     throws java.io.IOException
Move a File

Parameters:
src -
targetDirectory -
Throws:
java.io.IOException

getDirectoryPath

public static java.io.File getDirectoryPath(java.io.File parent,
                                            java.lang.String subDirectory)
Build a path- but do not create it

Parameters:
parent -
subDirectory -
Returns:
a File representing the path

buildDirectory

public static boolean buildDirectory(java.io.File file)
Build a directory path - creating directories if neccesary

Parameters:
file -
Returns:
true if the directory exists, or making it was successful

countFilesInDirectory

public static int countFilesInDirectory(java.io.File directory)
Count files in a directory (including files in all subdirectories)

Parameters:
directory - the directory to start in
Returns:
the total number of files

copyInputStream

public static void copyInputStream(java.io.InputStream in,
                                   java.io.OutputStream out)
                            throws java.io.IOException
Copy in stream to an out stream

Parameters:
in -
out -
Throws:
java.io.IOException

unpackArchive

public static java.io.File unpackArchive(java.io.File theFile,
                                         java.io.File targetDir)
                                  throws java.io.IOException
Unpack a zip file

Parameters:
theFile -
targetDir -
Returns:
the file
Throws:
java.io.IOException

unpackArchive

public static java.io.File unpackArchive(java.net.URL url,
                                         java.io.File targetDir)
                                  throws java.io.IOException
Unpack an archive from a URL

Parameters:
url -
targetDir -
Returns:
the file to the url
Throws:
java.io.IOException

archiveContainsEntry

public static boolean archiveContainsEntry(java.io.File theFile,
                                           java.lang.String name)
                                    throws java.io.IOException
Validate that an archive contains a named entry

Parameters:
theFile -
name -
Returns:
true if the entry exists
Throws:
java.io.IOException

createUniqueDirectory

public static java.io.File createUniqueDirectory(java.io.File rootDir,
                                                 java.lang.String seed)
                                          throws java.io.IOException
Create a unique directory within a directory 'root'

Parameters:
rootDir -
seed -
Returns:
unique directory
Throws:
java.io.IOException

deleteFile

public static boolean deleteFile(java.io.File fileToDelete)
Delete a file

Parameters:
fileToDelete -
Returns:
true if the File is deleted

zipDir

public static void zipDir(java.lang.String directory,
                          java.lang.String zipName)
                   throws java.io.IOException
Zip up a directory

Parameters:
directory -
zipName -
Throws:
java.io.IOException

zipDir

public static void zipDir(java.lang.String directory,
                          java.util.zip.ZipOutputStream zos,
                          java.lang.String path)
                   throws java.io.IOException
Zip up a directory path

Parameters:
directory -
zos -
path -
Throws:
java.io.IOException

isFileFullyAvailable

public static boolean isFileFullyAvailable(java.lang.String path)
checks whether a file is fully transmitted or still being copied

Parameters:
path - the full file path

isFileFullyAvailable

public static boolean isFileFullyAvailable(java.io.File file)
checks whether a file is fully transmitted or still being copied

Parameters:
file - the file to check

fastCopy

public static void fastCopy(java.io.InputStream input,
                            java.io.OutputStream output)
                     throws java.io.IOException
Copies the whole content from the input stream to the output stream using nio channels to speed it up.

Parameters:
input - the input stream
output - the output stream
Throws:
java.io.IOException - if any IO error occurs during read/write


Copyright © 2005-2011 Apache Software Foundation. All Rights Reserved.