@java.lang.SuppressWarnings("unchecked")
public class SpringIOUtils
extends java.lang.Object
Simple 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.
| Modifiers | Name | Description |
|---|---|---|
static int |
BUFFER_SIZE |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static java.lang.Object[] |
addAll(java.lang.Object[] array1, java.lang.Object[] array2)Adds the contents of 1 array to another |
|
public static java.lang.String |
byteArrayToHexString(byte[] in)Convert a byte[] array to readable string format. |
|
public static void |
closeQuietly(java.io.Closeable closeable)Closes a closeable gracefully without throwing exceptions etc. |
|
public static java.lang.String |
computeChecksum(java.io.File f, java.lang.String algorithm) |
|
public static int |
copy(java.io.File in, java.io.File out)Copy the contents of the given input File to the given output File. |
|
public static int |
copy(Resource in, java.io.File out)Copy the contents of the given input File to the given output File. |
|
public static void |
copy(byte[] in, java.io.File out)Copy the contents of the given byte array to the given output File. |
|
public static int |
copy(java.io.InputStream in, java.io.OutputStream out)Copy the contents of the given InputStream to the given OutputStream. |
|
public static void |
copy(byte[] in, java.io.OutputStream out)Copy the contents of the given byte array to the given OutputStream. |
|
public static int |
copy(java.io.Reader in, java.io.Writer out)Copy the contents of the given Reader to the given Writer. |
|
public static void |
copy(java.lang.String in, java.io.Writer out)Copy the contents of the given String to the given output Writer. |
|
public static void |
copyAll(Resource base, Resource[] resources, java.io.File targetDir)Copies all the resources for the given target directory. |
|
public static byte[] |
copyToByteArray(java.io.File in)Copy the contents of the given input File into a new byte array. |
|
public static byte[] |
copyToByteArray(java.io.InputStream in)Copy the contents of the given InputStream into a new byte array. |
|
public static java.lang.String |
copyToString(java.io.Reader in)Copy the contents of the given Reader into a String. |
|
public static XmlSlurper |
createXmlSlurper()Creates an XmlSlurper for untrusted documents such as HTTP request bodies. |
|
public static XmlSlurper |
createXmlSlurper(boolean allowDocTypeDeclaration)Creates an XmlSlurper, optionally tolerating a DOCTYPE declaration. |
|
public static javax.xml.parsers.SAXParser |
newSAXParser()Creates a javax.xml.parsers.SAXParser for untrusted documents such as HTTP request bodies. |
|
public static javax.xml.parsers.SAXParser |
newSAXParser(boolean allowDocTypeDeclaration)Creates a javax.xml.parsers.SAXParser, optionally tolerating a DOCTYPE declaration. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Adds the contents of 1 array to another
array1 - The target arrayarray2 - The source arrayConvert a byte[] array to readable string format. This makes the "hex" readable!
in
- byte[] buffer to convert to string formatCloses a closeable gracefully without throwing exceptions etc.
closeable - The closeableCopy the contents of the given input File to the given output File.
in - the file to copy fromout - the file to copy toCopy the contents of the given input File to the given output File.
in - the file to copy fromout - the file to copy toCopy the contents of the given byte array to the given output File.
in - the byte array to copy fromout - the file to copy toCopy the contents of the given InputStream to the given OutputStream. Closes both streams when done.
in - the stream to copy fromout - the stream to copy toCopy the contents of the given byte array to the given OutputStream. Closes the stream when done.
in - the byte array to copy fromout - the OutputStream to copy toCopy the contents of the given Reader to the given Writer. Closes both when done.
in - the Reader to copy fromout - the Writer to copy toCopy the contents of the given String to the given output Writer. Closes the write when done.
in - the String to copy fromout - the Writer to copy toCopies all the resources for the given target directory. The base resource serves to calculate the relative path such that the directory structure is maintained
base - The base resourceresources - The resources to copytargetDir - The target directoryCopy the contents of the given input File into a new byte array.
in - the file to copy fromCopy the contents of the given InputStream into a new byte array. Closes the stream when done.
in - the stream to copy fromCopy the contents of the given Reader into a String. Closes the reader when done.
in - the reader to copy fromCreates an XmlSlurper for untrusted documents such as HTTP request bodies.
The parser refuses a DOCTYPE declaration outright, on top of the entity and DTD
hardening every parser handed out by this class applies. Readers of trusted descriptors that
declare one use createXmlSlurper(boolean) with true instead.
DOCTYPE declarations Creates an XmlSlurper, optionally tolerating a DOCTYPE declaration.
Documents parsed through this class fall into two trust levels, and each level gets its
own parser. Request bodies are untrusted and are refused if they declare a DOCTYPE;
that is the false form and the default. Descriptors read from the application
classpath, such as JSP tag library descriptors and web.xml, are trusted and routinely
declare one, so their readers pass true.
Tolerating the declaration does not reopen the XXE vector. External general entities, external parameter entities, DTD grammar loading and external DTD retrieval stay off on both parsers, so an entity that points at a file on disk contributes nothing and the DTD a document names is skipped rather than fetched.
allowDocTypeDeclaration - true to parse documents that declare a DOCTYPECreates a javax.xml.parsers.SAXParser for untrusted documents such as HTTP request bodies.
The parser refuses a DOCTYPE declaration outright; see
createXmlSlurper(boolean) for the two trust levels.
DOCTYPE declarations Creates a javax.xml.parsers.SAXParser, optionally tolerating a DOCTYPE declaration.
Applies the same hardening as createXmlSlurper(boolean).
allowDocTypeDeclaration - true to parse documents that declare a DOCTYPE