public class StreamUtils extends Object
Utility methods to work with streams.
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(InputStream stream)
Close a stream without raising an exception.
|
static ByteArrayInputStream |
createByteArrayInputStream(byte[] buffer)
Creates a new
ByteArrayInputStream . |
static InputStream |
toInputStream(File file)
Convert a File to an InputStream.
|
public static void closeQuietly(InputStream stream)
Close a stream without raising an exception.
stream
- The stream to close.public static InputStream toInputStream(File file)
Convert a File to an InputStream. This uses WrappedFileInputStream
so the caller still has access to the original file if needed. If the file is not valid, an IllegalArgumentException will be raised.
file
- The file to convert to a stream.public static ByteArrayInputStream createByteArrayInputStream(byte[] buffer)
Creates a new ByteArrayInputStream
. This uses WrappedByteArrayInputStream
so the underlying buffer can be reused by multiple copies of the stream if needed.
buffer
- The byte buffer.Copyright © 2016–2020. All rights reserved.