com.googlecode.flyway.core.util
Class ResourceUtils

java.lang.Object
  extended by com.googlecode.flyway.core.util.ResourceUtils

public class ResourceUtils
extends java.lang.Object

Utility class for dealing with classpath resources.


Method Summary
static java.lang.Long calculateChecksum(java.lang.String source)
           
static long checksum(org.springframework.core.io.Resource resource)
          Computes the checksum of a classpath resource using.
static java.util.zip.Checksum checksum(org.springframework.core.io.Resource resource, java.util.zip.Checksum checksum)
          Computes the checksum of a classpath resource using the specified checksum object.
static void closeQuietly(java.io.InputStream input)
          Unconditionally close an InputStream.
static void closeQuietly(java.io.Reader reader)
          Unconditionally close an Reader.
static long copyLarge(java.io.InputStream input, java.io.OutputStream output)
          Copy bytes from a large (over 2GB) InputStream to an OutputStream.
static java.lang.String loadResourceAsString(org.springframework.core.io.Resource resource, java.lang.String encoding)
          Loads this resource in a string using this encoding.
static java.lang.String loadResourceAsString(org.springframework.core.io.Resource resource, java.lang.String encoding, java.util.zip.Checksum checksum)
          Loads this resource in a string using this encoding and optionally calculates a CRC-32 checksum
static java.lang.String loadResourceAsString(java.lang.String location)
          Loads the resource at this location within the classpath in a string using UTF-8 encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadResourceAsString

public static java.lang.String loadResourceAsString(java.lang.String location)
Loads the resource at this location within the classpath in a string using UTF-8 encoding.

Parameters:
location - The location of the resource on the classpath.
Returns:
The resource contents as a string.

loadResourceAsString

public static java.lang.String loadResourceAsString(org.springframework.core.io.Resource resource,
                                                    java.lang.String encoding)
Loads this resource in a string using this encoding.

Parameters:
resource - The resource to load.
encoding - The encoding of the resource.
Returns:
The resource contents as a string.

loadResourceAsString

public static java.lang.String loadResourceAsString(org.springframework.core.io.Resource resource,
                                                    java.lang.String encoding,
                                                    java.util.zip.Checksum checksum)
Loads this resource in a string using this encoding and optionally calculates a CRC-32 checksum

Parameters:
resource - The resource to load.
encoding - The encoding of the resource.
checksum - the checksum object to be used, if null no checksum is calculated
Returns:
The resource contents as a string.

checksum

public static long checksum(org.springframework.core.io.Resource resource)
                     throws java.io.IOException
Computes the checksum of a classpath resource using.

Parameters:
resource - the classpath resource.
Returns:
the calculated checksum
Throws:
java.io.IOException - if an IO error occurs reading the resource

checksum

public static java.util.zip.Checksum checksum(org.springframework.core.io.Resource resource,
                                              java.util.zip.Checksum checksum)
                                       throws java.io.IOException
Computes the checksum of a classpath resource using the specified checksum object.

Parameters:
resource - the classpath resource.
checksum - the checksum object to be used, must not be null
Returns:
the checksum specified, updated with the content of the file
Throws:
java.io.IOException - if an IO error occurs reading the resource

copyLarge

public static long copyLarge(java.io.InputStream input,
                             java.io.OutputStream output)
                      throws java.io.IOException
Copy bytes from a large (over 2GB) InputStream to an OutputStream.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

Parameters:
input - the InputStream to read from
output - the OutputStream to write to
Returns:
the number of bytes copied
Throws:
java.lang.NullPointerException - if the input or output is null
java.io.IOException - if an I/O error occurs
Since:
Commons IO 1.3

closeQuietly

public static void closeQuietly(java.io.InputStream input)
Unconditionally close an InputStream.

Equivalent to InputStream.close(), except any exceptions will be ignored. This is typically used in finally blocks.

Parameters:
input - the InputStream to close, may be null or already closed

closeQuietly

public static void closeQuietly(java.io.Reader reader)
Unconditionally close an Reader.

Equivalent to Reader.close(), except any exceptions will be ignored. This is typically used in finally blocks.

Parameters:
reader - the Reader to close, may be null or already closed

calculateChecksum

public static java.lang.Long calculateChecksum(java.lang.String source)


Copyright © 2010. All Rights Reserved.