de.enough.polish.util
Class StreamUtil

java.lang.Object
  extended by de.enough.polish.util.StreamUtil

public class StreamUtil
extends Object

Provides some useful Stream methods.

Copyright Enough Software 2008

 history
        10-Jul-2008 - asc creation
 

Author:
Andre Schmidt, andre@enough.de

Field Summary
static int DEFAULT_BUFFER
          the default length for the temporary buffer is 8 kb
 
Constructor Summary
StreamUtil()
           
 
Method Summary
static String[] getLines(InputStream in, String encoding, int bufferLength)
          Returns the lines of a InputStream as an ArrayList of Strings
static String getString(InputStream in)
          Returns the content of a stream as a String
static String getString(InputStream in, String encoding, int bufferLength)
          Returns the content of a stream as a String
static String getStringSafe(InputStream in)
          Returns the content of a stream as a String
static String getStringSafe(InputStream in, String encoding, int bufferLength)
          Returns the content of a stream as a String
static byte[] readFully(InputStream in)
          Reads the complete input stream into a byte array using a 8kb temporary buffer
static byte[] readFully(InputStream in, byte[] buffer)
          Reads the complete input stream into a byte array using the specified buffer
static byte[] readFully(InputStream in, int bufferLength)
          Reads the complete input stream into a byte array using the specified buffer size
static byte[] readFullySafe(InputStream in)
          Reads the complete input stream into a byte array using a 8kb temporary buffer The input stream is read until it is empty or until an error occurred.
static byte[] readFullySafe(InputStream in, byte[] buffer)
          Reads the complete input stream into a byte array using a the specified buffer.
static byte[] readFullySafe(InputStream in, int bufferLength)
          Reads the complete input stream into a byte array using a the specified buffer size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER

public static final int DEFAULT_BUFFER
the default length for the temporary buffer is 8 kb

See Also:
Constant Field Values
Constructor Detail

StreamUtil

public StreamUtil()
Method Detail

getLines

public static String[] getLines(InputStream in,
                                String encoding,
                                int bufferLength)
                         throws IOException
Returns the lines of a InputStream as an ArrayList of Strings

Parameters:
in - the stream to read
encoding - the encoding to use
bufferLength - the length of the used temporary buffer
Returns:
the lines as an ArrayList
Throws:
IOException - when reading fails
NullPointerException - when the given input stream is null

getString

public static String getString(InputStream in)
                        throws IOException
Returns the content of a stream as a String

Parameters:
in - the stream to read with the text in the default encoding
Returns:
the resulting String
Throws:
IOException - when reading fails

getString

public static String getString(InputStream in,
                               String encoding,
                               int bufferLength)
                        throws IOException
Returns the content of a stream as a String

Parameters:
in - the stream to read
encoding - the encoding to use
bufferLength - the length of the used temporary buffer
Returns:
the resulting String
Throws:
IOException - when reading fails
NullPointerException - when the given input stream is null

getStringSafe

public static String getStringSafe(InputStream in)
Returns the content of a stream as a String

Parameters:
in - the stream to read with the text in the default encoding
Returns:
the resulting String

getStringSafe

public static String getStringSafe(InputStream in,
                                   String encoding,
                                   int bufferLength)
Returns the content of a stream as a String

Parameters:
in - the stream to read
encoding - the encoding to use
bufferLength - the length of the used temporary buffer
Returns:
the resulting String

readFully

public static byte[] readFully(InputStream in)
                        throws IOException
Reads the complete input stream into a byte array using a 8kb temporary buffer

Parameters:
in - the input stream
Returns:
the read data
Throws:
IOException - when reading fails
NullPointerException - when the given input stream is null

readFully

public static byte[] readFully(InputStream in,
                               int bufferLength)
                        throws IOException
Reads the complete input stream into a byte array using the specified buffer size

Parameters:
in - the input stream
bufferLength - the length of the used temporary buffer
Returns:
the read data
Throws:
IOException - when reading fails
NullPointerException - when the given input stream is null

readFully

public static byte[] readFully(InputStream in,
                               byte[] buffer)
                        throws IOException
Reads the complete input stream into a byte array using the specified buffer

Parameters:
in - the input stream
buffer - the used temporary buffer
Returns:
the read data
Throws:
IOException - when reading fails
NullPointerException - when the given input stream is null

readFullySafe

public static byte[] readFullySafe(InputStream in)
Reads the complete input stream into a byte array using a 8kb temporary buffer The input stream is read until it is empty or until an error occurred.

Parameters:
in - the input stream
Returns:
the read data or null when the input stream is null

readFullySafe

public static byte[] readFullySafe(InputStream in,
                                   int bufferLength)
Reads the complete input stream into a byte array using a the specified buffer size. The input stream is read until it is empty or until an error occurred.

Parameters:
in - the input stream
bufferLength - the length of the used temporary buffer
Returns:
the read data or null when the input stream is null

readFullySafe

public static byte[] readFullySafe(InputStream in,
                                   byte[] buffer)
Reads the complete input stream into a byte array using a the specified buffer. The input stream is read until it is empty or until an error occurred.

Parameters:
in - the input stream
buffer - the used temporary buffer
Returns:
the read data or null when the input stream is null