org.hibernate.search.util.impl
Class FileHelper

java.lang.Object
  extended by org.hibernate.search.util.impl.FileHelper

public abstract class FileHelper
extends Object

Utility class for file and directory operations, like synchronisation and reading from class path.

Author:
Emmanuel Bernard, Sanne Grinovero, Hardy Ferentschik

Field Summary
static long DEFAULT_COPY_BUFFER_SIZE
           
 
Constructor Summary
FileHelper()
           
 
Method Summary
static boolean areInSync(File source, File destination)
           
static void closeResource(Closeable resource)
          Closes a resource without throwing IOExceptions
static boolean delete(File file)
          Attempts to delete a file, and if it is a directory recurse to all content.
static InputStream openResource(String resourceName)
           
static String readInputStream(InputStream inputStream)
          Reads the provided input stream into a string
static String readResourceAsString(String resourceName, ClassLoader classLoader)
          Load a resource from a specific classLoader
static void synchronize(File source, File destination, boolean smart)
           
static void synchronize(File source, File destination, boolean smart, long chunkSize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COPY_BUFFER_SIZE

public static final long DEFAULT_COPY_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

FileHelper

public FileHelper()
Method Detail

areInSync

public static boolean areInSync(File source,
                                File destination)
                         throws IOException
Throws:
IOException

synchronize

public static void synchronize(File source,
                               File destination,
                               boolean smart)
                        throws IOException
Throws:
IOException

synchronize

public static void synchronize(File source,
                               File destination,
                               boolean smart,
                               long chunkSize)
                        throws IOException
Throws:
IOException

delete

public static boolean delete(File file)
Attempts to delete a file, and if it is a directory recurse to all content.

Parameters:
file - the file or Directory to be deleted
Returns:
false if it wasn't possible to delete it or all of the contents. A common problem on Windows systems.

readInputStream

public static String readInputStream(InputStream inputStream)
                              throws IOException
Reads the provided input stream into a string

Parameters:
inputStream - the input stream to read from
Returns:
the content of the input stream as string
Throws:
IOException - in case an error occurs reading from the input stream

readResourceAsString

public static String readResourceAsString(String resourceName,
                                          ClassLoader classLoader)
Load a resource from a specific classLoader

Parameters:
resourceName - the name of the resource
classLoader - the classloader to use, or null to try the ContextClassloader first or the loading one second.
Returns:
the resource contents as a String

openResource

public static InputStream openResource(String resourceName)

closeResource

public static void closeResource(Closeable resource)
Closes a resource without throwing IOExceptions

Parameters:
resource - the resource to close


Copyright © 2006-2012 Red Hat Middleware, LLC. All Rights Reserved