Package org.grails.io.support
Class SpringIOUtils
- java.lang.Object
-
- org.grails.io.support.SpringIOUtils
-
public class SpringIOUtils extends java.lang.ObjectSimple utility methods for file and stream copying. All copy methods use a block size of 4096 bytes, and close all affected streams when done.Mainly for use within the framework, but also useful for application code.
- Since:
- 06.10.2003
-
-
Field Summary
Fields Modifier and Type Field Description static intBUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description SpringIOUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Object[]addAll(java.lang.Object[] array1, java.lang.Object[] array2)Adds the contents of 1 array to anotherstatic java.lang.StringbyteArrayToHexString(byte[] in)Convert a byte[] array to readable string format.static voidcloseQuietly(java.io.Closeable closeable)Closes a closeable gracefully without throwing exceptions etc.static java.lang.StringcomputeChecksum(java.io.File f, java.lang.String algorithm)static voidcopy(byte[] in, java.io.File out)Copy the contents of the given byte array to the given output File.static voidcopy(byte[] in, java.io.OutputStream out)Copy the contents of the given byte array to the given OutputStream.static intcopy(java.io.File in, java.io.File out)Copy the contents of the given input File to the given output File.static intcopy(java.io.InputStream in, java.io.OutputStream out)Copy the contents of the given InputStream to the given OutputStream.static intcopy(java.io.Reader in, java.io.Writer out)Copy the contents of the given Reader to the given Writer.static voidcopy(java.lang.String in, java.io.Writer out)Copy the contents of the given String to the given output Writer.static intcopy(Resource in, java.io.File out)Copy the contents of the given input File to the given output File.static voidcopyAll(Resource base, Resource[] resources, java.io.File targetDir)Copies all the resources for the given target directory.static byte[]copyToByteArray(java.io.File in)Copy the contents of the given input File into a new byte array.static byte[]copyToByteArray(java.io.InputStream in)Copy the contents of the given InputStream into a new byte array.static java.lang.StringcopyToString(java.io.Reader in)Copy the contents of the given Reader into a String.static groovy.util.XmlSlurpercreateXmlSlurper()static javax.xml.parsers.SAXParsernewSAXParser()
-
-
-
Field Detail
-
BUFFER_SIZE
public static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
byteArrayToHexString
public static java.lang.String byteArrayToHexString(byte[] in)
Convert a byte[] array to readable string format. This makes the "hex" readable!- Parameters:
in- byte[] buffer to convert to string format- Returns:
- result String buffer in String format
-
computeChecksum
public static java.lang.String computeChecksum(java.io.File f, java.lang.String algorithm) throws java.io.IOException- Throws:
java.io.IOException
-
addAll
public static java.lang.Object[] addAll(java.lang.Object[] array1, java.lang.Object[] array2)Adds the contents of 1 array to another- Parameters:
array1- The target arrayarray2- The source array- Returns:
- The new array
-
copyAll
public static void copyAll(Resource base, Resource[] resources, java.io.File targetDir) throws java.io.IOException
Copies all the resources for the given target directory. The base resource serves to calculate the relative path such that the directory structure is maintained- Parameters:
base- The base resourceresources- The resources to copytargetDir- The target directory- Throws:
java.io.IOException
-
copy
public static int copy(java.io.File in, java.io.File out) throws java.io.IOExceptionCopy the contents of the given input File to the given output File.- Parameters:
in- the file to copy fromout- the file to copy to- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static int copy(Resource in, java.io.File out) throws java.io.IOException
Copy the contents of the given input File to the given output File.- Parameters:
in- the file to copy fromout- the file to copy to- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static void copy(byte[] in, java.io.File out) throws java.io.IOExceptionCopy the contents of the given byte array to the given output File.- Parameters:
in- the byte array to copy fromout- the file to copy to- Throws:
java.io.IOException- in case of I/O errors
-
copyToByteArray
public static byte[] copyToByteArray(java.io.File in) throws java.io.IOExceptionCopy the contents of the given input File into a new byte array.- Parameters:
in- the file to copy from- Returns:
- the new byte array that has been copied to
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static int copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionCopy the contents of the given InputStream to the given OutputStream. Closes both streams when done.- Parameters:
in- the stream to copy fromout- the stream to copy to- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static void copy(byte[] in, java.io.OutputStream out) throws java.io.IOExceptionCopy the contents of the given byte array to the given OutputStream. Closes the stream when done.- Parameters:
in- the byte array to copy fromout- the OutputStream to copy to- Throws:
java.io.IOException- in case of I/O errors
-
copyToByteArray
public static byte[] copyToByteArray(java.io.InputStream in) throws java.io.IOExceptionCopy the contents of the given InputStream into a new byte array. Closes the stream when done.- Parameters:
in- the stream to copy from- Returns:
- the new byte array that has been copied to
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static int copy(java.io.Reader in, java.io.Writer out) throws java.io.IOExceptionCopy the contents of the given Reader to the given Writer. Closes both when done.- Parameters:
in- the Reader to copy fromout- the Writer to copy to- Returns:
- the number of characters copied
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static void copy(java.lang.String in, java.io.Writer out) throws java.io.IOExceptionCopy the contents of the given String to the given output Writer. Closes the write when done.- Parameters:
in- the String to copy fromout- the Writer to copy to- Throws:
java.io.IOException- in case of I/O errors
-
closeQuietly
public static void closeQuietly(java.io.Closeable closeable)
Closes a closeable gracefully without throwing exceptions etc.- Parameters:
closeable- The closeable
-
copyToString
public static java.lang.String copyToString(java.io.Reader in) throws java.io.IOExceptionCopy the contents of the given Reader into a String. Closes the reader when done.- Parameters:
in- the reader to copy from- Returns:
- the String that has been copied to
- Throws:
java.io.IOException- in case of I/O errors
-
createXmlSlurper
public static groovy.util.XmlSlurper createXmlSlurper() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException- Throws:
javax.xml.parsers.ParserConfigurationExceptionorg.xml.sax.SAXException
-
newSAXParser
public static javax.xml.parsers.SAXParser newSAXParser() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException- Throws:
javax.xml.parsers.ParserConfigurationExceptionorg.xml.sax.SAXException
-
-