Class StreamUtils


  • public class StreamUtils
    extends java.lang.Object
    Utilities for handling streams.
    • Constructor Summary

      Constructors 
      Constructor Description
      StreamUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyInputStreamToJspWriter​(java.io.InputStream in, javax.servlet.jsp.JspWriter out)
      Will copy everything from input stream to jsp writer, closing input stream afterwards.
      static void copyInputStreamToOutputStream​(java.io.InputStream in, java.io.OutputStream out)
      Will copy everything from input stream to output stream, closing input stream afterwards.
      static java.lang.String getFileReaderAsString​(java.io.FileReader fr)
      Get FileReader as String.
      static java.lang.String getInputStreamAsString​(java.io.InputStream in)
      Reads an input stream and returns it as a string.
      static byte[] inputStreamToBytes​(java.io.InputStream data, int dataLength)
      Convert inputStream to byte array.
      static void writeXmlToStream​(org.dom4j.Document doc, java.io.OutputStream os)
      Write document tree to stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • copyInputStreamToJspWriter

        public static void copyInputStreamToJspWriter​(java.io.InputStream in,
                                                      javax.servlet.jsp.JspWriter out)
        Will copy everything from input stream to jsp writer, closing input stream afterwards. Charset UTF-8 is assumed.
        Parameters:
        in - InputStream to copy from
        out - JspWriter to copy to
        Throws:
        ArgumentNotValid - if either parameter is null
        IOFailure - if a read or write error happens during copy
      • copyInputStreamToOutputStream

        public static void copyInputStreamToOutputStream​(java.io.InputStream in,
                                                         java.io.OutputStream out)
        Will copy everything from input stream to output stream, closing input stream afterwards.
        Parameters:
        in - Inputstream to copy from
        out - Outputstream to copy to
        Throws:
        ArgumentNotValid - if either parameter is null
        IOFailure - if a read or write error happens during copy
      • writeXmlToStream

        public static void writeXmlToStream​(org.dom4j.Document doc,
                                            java.io.OutputStream os)
        Write document tree to stream. Note, the stream is flushed, but not closed.
        Parameters:
        doc - the document tree to save.
        os - the stream to write xml to
        Throws:
        IOFailure - On trouble writing XML to stream.
      • getInputStreamAsString

        public static java.lang.String getInputStreamAsString​(java.io.InputStream in)
                                                       throws ArgumentNotValid,
                                                              IOFailure
        Reads an input stream and returns it as a string.
        Parameters:
        in - The input stream.
        Returns:
        The string content of the input stream in the UTF8-charset.
        Throws:
        ArgumentNotValid - If the input stream is null.
        IOFailure - If an IOException is caught while reading the inputstream.
      • getFileReaderAsString

        public static java.lang.String getFileReaderAsString​(java.io.FileReader fr)
                                                      throws ArgumentNotValid,
                                                             IOFailure
        Get FileReader as String.
        Parameters:
        fr - a given FileReader
        Returns:
        the FileReader as a String.
        Throws:
        ArgumentNotValid - If the FileReader is null.
        IOFailure - If an IOException is caught while reading the FileReader.
      • inputStreamToBytes

        public static byte[] inputStreamToBytes​(java.io.InputStream data,
                                                int dataLength)
        Convert inputStream to byte array.
        Parameters:
        data - a given InputStream
        dataLength - length of the InputStream (must be larger than 0)
        Returns:
        byte[] containing the data in the given InputStream