public class IOUtils extends Object
Modifier and Type | Field and Description |
---|---|
protected static int |
bufferSize |
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(InputStream input,
OutputStream output,
int bufferSize)
|
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(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,
MediaType contentType)
Transforms an Object into a DataHandler of its corresponding type.
|
static String |
toString(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 . |
static String |
toString(InputStream input,
String encoding)
This method wraps
IOUtils ' toString(InputStream, String) 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(InputStream input, String encoding)
IOUtils
' toString(InputStream, String)
method but catches any
IOException
and wraps it into a RuntimeException
.public static String toString(CursorStreamProvider cursorStreamProvider)
toByteArray(InputStream)
but obtaining the stream from the given
cursorStreamProvider
public static byte[] toByteArray(InputStream input)
IOUtils
' toByteArray(InputStream)
method but catches any
IOException
and wraps it into a RuntimeException
.public static byte[] toByteArray(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
IOException
public static long copyLarge(Reader input, Writer output) throws IOException
IOException
public static long copyLarge(InputStream input, OutputStream output, int bufferSize) throws IOException
IOException
public static DataHandler toDataHandler(String name, Object object, 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 void ifInputStream(Object value, CheckedConsumer<InputStream> consumer) throws NotAnInputStreamException
NotAnInputStreamException
public static <T> T ifInputStream(Object value, CheckedFunction<InputStream,T> function) throws NotAnInputStreamException
NotAnInputStreamException
public static void closeQuietly(Closeable closeable)
closeable
- instance to be closed. Non null.Copyright © 2018. All rights reserved.