Class StreamUtils


  • public class StreamUtils
    extends Object
    Contains general utility functions for handling streams.
    Author:
    Michele Mostarda (mostarda@fbk.eu)
    • Method Detail

      • asLines

        public static String[] asLines​(InputStream is)
                                throws IOException
        Returns all the lines read from an input stream.
        Parameters:
        is - input stream.
        Returns:
        list of not null lines.
        Throws:
        IOException - if an error occurs while consuming the is stream.
      • asString

        public static String asString​(InputStream is,
                                      boolean preserveNL)
                               throws IOException
        Returns the string content of a stream.
        Parameters:
        is - input stream.
        preserveNL - preserves new line chars.
        Returns:
        the string content.
        Throws:
        IOException - if an error occurs while consuming the is stream.
      • asString

        public static String asString​(InputStream is)
                               throws IOException
        Returns the string content of a stream, new line chars will be removed.
        Parameters:
        is - input stream.
        Returns:
        the string content.
        Throws:
        IOException - if an error occurs while consuming the is stream.
      • closeGracefully

        public static void closeGracefully​(Closeable closable)
        Closes the closable interface and reports error if any.
        Parameters:
        closable - the closable object to be closed.
      • inputStreamToDocument

        public static Document inputStreamToDocument​(InputStream is)
                                              throws org.apache.xerces.impl.io.MalformedByteSequenceException
        Throws:
        org.apache.xerces.impl.io.MalformedByteSequenceException