org.milyn.io
Class StreamUtils

java.lang.Object
  extended by org.milyn.io.StreamUtils

public abstract class StreamUtils
extends Object

Stream Utilities.

Author:
tfennelly

Constructor Summary
StreamUtils()
           
 
Method Summary
static boolean compareCharStreams(InputStream s1, InputStream s2)
          Compares the 2 streams.
static boolean compareCharStreams(Reader s1, Reader s2)
          Compares the 2 streams.
static boolean compareCharStreams(String s1, String s2)
          Compares the 2 streams.
static String normalizeLines(Reader charStream, boolean trim)
          Read the lines lines of characters from the stream, trim each line (optional) and add a single newline character.
static String normalizeLines(String string, boolean trim)
          Read the lines lines of characters from the supplied string, trim each line (optional) and add a single newline character.
static byte[] readFile(File file)
          Deprecated. Use FileUtils.readFile(java.io.File).
static byte[] readStream(InputStream stream)
          Read the supplied InputStream and return as a byte array.
static String readStream(Reader stream)
           
static String readStreamAsString(InputStream stream)
          Read the supplied InputStream and return as a byte array.
static StringBuffer trimLines(InputStream charStream)
          Read the lines lines of characters from the stream and trim each line i.e.
static StringBuffer trimLines(Reader charStream)
          Read the lines lines of characters from the stream and trim each line i.e.
static String trimLines(String charStream)
          Read the lines lines of characters from the stream and trim each line i.e.
static void writeFile(File file, byte[] data)
           
 
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

readStream

public static byte[] readStream(InputStream stream)
                         throws IOException
Read the supplied InputStream and return as a byte array.

Parameters:
stream - The stream to read.
Returns:
byte array containing the Stream data.
Throws:
IOException - Exception reading from the stream.

readStreamAsString

public static String readStreamAsString(InputStream stream)
                                 throws IOException
Read the supplied InputStream and return as a byte array.

Parameters:
stream - The stream to read.
Returns:
A String containing the Stream data.
Throws:
IOException - Exception reading from the stream.

readFile

public static byte[] readFile(File file)
                       throws IOException
Deprecated. Use FileUtils.readFile(java.io.File).

Read the contents of the specified file.

Parameters:
file - The file to read.
Returns:
The file contents.
Throws:
IOException - Error readiong file.

writeFile

public static void writeFile(File file,
                             byte[] data)
                      throws IOException
Throws:
IOException

readStream

public static String readStream(Reader stream)
                         throws IOException
Throws:
IOException

compareCharStreams

public static boolean compareCharStreams(InputStream s1,
                                         InputStream s2)
Compares the 2 streams.

Calls trimLines(InputStream) on each stream before comparing.

Parameters:
s1 - Stream 1.
s2 - Stream 2.
Returns:
True if the streams are equal not including leading and trailing whitespace on each line and blank lines, otherwise returns false.

compareCharStreams

public static boolean compareCharStreams(Reader s1,
                                         Reader s2)
Compares the 2 streams.

Calls trimLines(java.io.Reader) on each stream before comparing.

Parameters:
s1 - Stream 1.
s2 - Stream 2.
Returns:
True if the streams are equal not including leading and trailing whitespace on each line and blank lines, otherwise returns false.

compareCharStreams

public static boolean compareCharStreams(String s1,
                                         String s2)
Compares the 2 streams.

Calls trimLines(java.io.Reader) on each stream before comparing.

Parameters:
s1 - Stream 1.
s2 - Stream 2.
Returns:
True if the streams are equal not including leading and trailing whitespace on each line and blank lines, otherwise returns false.

trimLines

public static StringBuffer trimLines(Reader charStream)
                              throws IOException
Read the lines lines of characters from the stream and trim each line i.e. remove all leading and trailing whitespace.

Parameters:
charStream - Character stream.
Returns:
StringBuffer containing the line trimmed stream.
Throws:
IOException

normalizeLines

public static String normalizeLines(String string,
                                    boolean trim)
                             throws IOException
Read the lines lines of characters from the supplied string, trim each line (optional) and add a single newline character.

Parameters:
string - The String.
trim - Trim each line i.e. to ignore leading and trailing whitespace.
Returns:
String containing the line trimmed stream.
Throws:
IOException

normalizeLines

public static String normalizeLines(Reader charStream,
                                    boolean trim)
                             throws IOException
Read the lines lines of characters from the stream, trim each line (optional) and add a single newline character.

Parameters:
charStream - Character stream.
trim - Trim each line i.e. to ignore leading and trailing whitespace.
Returns:
String containing the line trimmed stream.
Throws:
IOException

trimLines

public static StringBuffer trimLines(InputStream charStream)
                              throws IOException
Read the lines lines of characters from the stream and trim each line i.e. remove all leading and trailing whitespace.

Parameters:
charStream - Character stream.
Returns:
StringBuffer containing the line trimmed stream.
Throws:
IOException

trimLines

public static String trimLines(String charStream)
                        throws IOException
Read the lines lines of characters from the stream and trim each line i.e. remove all leading and trailing whitespace.

Parameters:
charStream - Character stream.
Returns:
String containing the line trimmed stream.
Throws:
IOException


Copyright © 2018. All rights reserved.