Class IOStreamUtilities


  • public class IOStreamUtilities
    extends Object
    • Constructor Detail

      • IOStreamUtilities

        public IOStreamUtilities()
    • Method Detail

      • getReaderFromInputStream

        public static BufferedReader getReaderFromInputStream​(InputStream is)
        Returns a buffered reader with UTF-8 encoding from the given input stream.
        Parameters:
        is - The input stream to get an UTF-8 reader from.
        Returns:
        A UTF-8 encoding reader.
      • getLinesFromInputStream

        public static List<String> getLinesFromInputStream​(InputStream is)
                                                    throws IOException
        Interprets is as a stream of UTF-8 encoded lines and returns all lines.
        Parameters:
        is - The input stream.
        Returns:
        All UTF-8 encoded lines from the input stream.
        Throws:
        IOException - If reading fails.
      • getStringFromInputStream

        public static String getStringFromInputStream​(InputStream is)
                                               throws IOException

        Converts an InputStream into a single String using a ByteArrayOutputStream as a buffer.

        Inspired by https://stackoverflow.com/a/48775964/1314955.

        Parameters:
        is - The InputStream to convert into a String.
        Returns:
        The string contents of is.
        Throws:
        IOException - If reading fails.