Class IOUtil


  • public class IOUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      IOUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      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[].
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IOUtil

        public IOUtil()
    • Method Detail

      • readFully

        public static byte[] readFully​(java.io.File file)
                                throws java.io.IOException
        Used as an alternate to Java's nio Files.readAllBytes.

        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

        Parameters:
        file - The file from which we should retrieve the bytes from
        Returns:
        A byte[] containing all of the file's data
        Throws:
        java.io.IOException - Thrown if there is a problem while reading the file.
      • readFully

        public static byte[] readFully​(java.io.InputStream stream)
                                throws java.io.IOException
        Provided as a simple way to fully read an InputStream into a byte[].

        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.

        Parameters:
        stream - The Stream to be read.
        Returns:
        A byte[] containing all of the data provided by the InputStream
        Throws:
        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.