public class IOUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static int |
bufferSize |
| Constructor and Description |
|---|
IOUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeQuietly(Closeable closeable)
Closes a {#link Closable} instance catching any exceptions
|
static long |
copyLarge(InputStream input,
OutputStream output)
Re-implement copy method to allow buffer size to be configured.
|
static long |
copyLarge(Reader input,
Writer output)
Re-implement copy method to allow buffer size to be configured.
|
static InputStream |
getResourceAsStream(String resourceName,
Class callingClass)
Attempts to load a resource from the file system, from a URL, or from the classpath, in that order.
|
static InputStream |
getResourceAsStream(String resourceName,
Class callingClass,
boolean tryAsFile,
boolean tryAsUrl)
Attempts to load a resource from the file system, from a URL, or from the classpath, in that order.
|
static String |
getResourceAsString(String resourceName,
Class callingClass)
Attempts to load a resource from the file system, from a URL, or from the classpath, in that order.
|
static URL |
getResourceAsUrl(String resourceName,
Class callingClass)
Attempts to load a resource from the file system or from the classpath, in that order.
|
static URL |
getResourceAsUrl(String resourceName,
Class callingClass,
boolean tryAsFile,
boolean tryAsUrl)
Attempts to load a resource from the file system or from the classpath, in that order.
|
static void |
ifInputStream(Object value,
CheckedConsumer<InputStream> consumer) |
static <T> T |
ifInputStream(Object value,
CheckedFunction<InputStream,T> function) |
static byte[] |
toByteArray(org.mule.runtime.api.streaming.bytes.CursorStreamProvider cursorStreamProvider)
This method wraps
IOUtils' toByteArray(InputStream) method but catches any
IOException and wraps it into a RuntimeException. |
static byte[] |
toByteArray(InputStream input)
This method wraps
IOUtils' toByteArray(InputStream) method but catches any
IOException and wraps it into a RuntimeException. |
static DataHandler |
toDataHandler(String name,
Object object,
org.mule.runtime.api.metadata.MediaType contentType)
Transforms an Object into a DataHandler of its corresponding type.
|
static org.mule.runtime.api.message.Message |
toMuleMessagePart(String name,
Object object,
org.mule.runtime.api.metadata.MediaType contentType)
Transforms an Object into a
Message to be used in a MultiPartPayload. |
static String |
toString(org.mule.runtime.api.streaming.bytes.CursorStreamProvider cursorStreamProvider)
Similar to
toByteArray(InputStream) but obtaining the stream from the given
cursorStreamProvider |
static String |
toString(InputStream input)
This method wraps
IOUtils' toString(InputStream) method but catches any
IOException and wraps it into a RuntimeException. |
static String |
toString(InputStream input,
Charset encoding)
This method wraps
IOUtils' toString(InputStream, Charset) method but catches any
IOException and wraps it into a RuntimeException. |
public static String getResourceAsString(String resourceName, Class callingClass) throws IOException
resourceName - The name of the resource to loadcallingClass - The Class object of the calling objectIOException - IO errorpublic static InputStream getResourceAsStream(String resourceName, Class callingClass) throws IOException
resourceName - The name of the resource to loadcallingClass - The Class object of the calling objectIOException - IO errorpublic static InputStream getResourceAsStream(String resourceName, Class callingClass, boolean tryAsFile, boolean tryAsUrl) throws IOException
resourceName - The name of the resource to loadcallingClass - The Class object of the calling objecttryAsFile - - try to load the resource from the local file systemtryAsUrl - - try to load the resource as a URLIOException - IO errorpublic static URL getResourceAsUrl(String resourceName, Class callingClass)
resourceName - The name of the resource to loadcallingClass - The Class object of the calling objectpublic static URL getResourceAsUrl(String resourceName, Class callingClass, boolean tryAsFile, boolean tryAsUrl)
resourceName - The name of the resource to loadcallingClass - The Class object of the calling objecttryAsFile - - try to load the resource from the local file systemtryAsUrl - - try to load the resource as a Url stringpublic static String toString(InputStream input)
IOUtils' toString(InputStream) method but catches any
IOException and wraps it into a RuntimeException.public static String toString(InputStream input, Charset encoding)
IOUtils' toString(InputStream, Charset) method but catches any
IOException and wraps it into a RuntimeException.public static String toString(org.mule.runtime.api.streaming.bytes.CursorStreamProvider cursorStreamProvider)
toByteArray(InputStream) but obtaining the stream from the given
cursorStreamProviderpublic static byte[] toByteArray(InputStream input)
IOUtils' toByteArray(InputStream) method but catches any
IOException and wraps it into a RuntimeException.public static byte[] toByteArray(org.mule.runtime.api.streaming.bytes.CursorStreamProvider cursorStreamProvider)
IOUtils' toByteArray(InputStream) method but catches any
IOException and wraps it into a RuntimeException.public static long copyLarge(InputStream input, OutputStream output) throws IOException
IOExceptionpublic static long copyLarge(Reader input, Writer output) throws IOException
IOExceptionpublic static DataHandler toDataHandler(String name, Object object, org.mule.runtime.api.metadata.MediaType contentType) throws IOException
name - the name of the attachment being handledobject - the attachment to be handledcontentType - the Content-Type of the attachment that is being handledDataHandler of the corresponding attachmentIOException - if the transformation fails.public static org.mule.runtime.api.message.Message toMuleMessagePart(String name, Object object, org.mule.runtime.api.metadata.MediaType contentType) throws IOException
Message to be used in a MultiPartPayload.name - the name of the attachment being handledobject - the attachment to be handledcontentType - the Content-Type of the attachment that is being handledMessage of the corresponding attachmentIOException - if the transformation fails.public static void ifInputStream(Object value, CheckedConsumer<InputStream> consumer) throws NotAnInputStreamException
NotAnInputStreamExceptionpublic static <T> T ifInputStream(Object value, CheckedFunction<InputStream,T> function) throws NotAnInputStreamException
NotAnInputStreamExceptionpublic static void closeQuietly(Closeable closeable)
closeable - instance to be closed. Non null.Copyright © 2003–2017 MuleSoft, Inc.. All rights reserved.