public class IOUtil
extends java.lang.Object
Constructor | Description |
---|---|
IOUtil() |
Modifier and Type | Method | Description |
---|---|---|
static byte[] |
readFully(java.io.File file) |
Used as an alternate to Java's nio Files.readAllBytes.
|
static byte[] |
readFully(java.io.InputStream stream) |
Provided as a simple way to fully read an InputStream into a byte[].
|
public static byte[] readFully(java.io.File file) throws java.io.IOException
This customized version for File is provide (instead of just using readFully(java.io.InputStream)
with a FileInputStream)
because with a File we can determine the total size of the array and do not need to have a buffer.
This results in a memory footprint that is half the size of readFully(java.io.InputStream)
Code provided from Stackoverflow
file
- The file from which we should retrieve the bytes fromjava.io.IOException
- Thrown if there is a problem while reading the file.public static byte[] readFully(java.io.InputStream stream) throws java.io.IOException
This method will block until the InputStream has been fully read, so if you provide an InputStream that is non-finite, you're gonna have a bad time.
stream
- The Stream to be read.java.io.IOException
- If the first byte cannot be read for any reason other than the end of the file,
if the input stream has been closed, or if some other I/O error occurs.