dk.netarkivet.common.utils
Class StreamUtils

java.lang.Object
  extended by dk.netarkivet.common.utils.StreamUtils

public class StreamUtils
extends java.lang.Object

Utilities for handling streams.


Constructor Summary
StreamUtils()
           
 
Method Summary
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 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
 

Constructor Detail

StreamUtils

public StreamUtils()
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.

inputStreamToBytes

public static byte[] inputStreamToBytes(java.io.InputStream data,
                                        int dataLength)
Convert inputStream to byte array.

Parameters:
data - inputstream
dataLength - length of inputstream (must be larger than 0)
Returns:
byte[] containing data in inputstream