com.ibm.commons.util.io
Class StreamUtil

java.lang.Object
  extended by com.ibm.commons.util.io.StreamUtil

public class StreamUtil
extends java.lang.Object

Utilities for working with streams


Constructor Summary
StreamUtil()
           
 
Method Summary
static java.io.InputStream close(java.io.InputStream s)
          Call close on an input stream and ignore any exception.
static java.io.OutputStream close(java.io.OutputStream s)
          Call close on an output stream and ignore any exception.
static java.io.Reader close(java.io.Reader r)
          Call close on a Reader and ignore any exception.
static java.io.Writer close(java.io.Writer w)
          Call close on a Writer and ignore any exception.
static long copyStream(java.io.InputStream is, java.io.OutputStream os)
          Copy contents of one stream onto another
static long copyStream(java.io.InputStream is, java.io.OutputStream os, int bufferSize)
          Copy contents of one stream onto another
static long copyStream(java.io.Reader is, java.io.Writer os)
          Copy contents of one stream onto another
static long copyStream(java.io.Reader is, java.io.Writer os, int bufferSize)
          Copy contents of one character stream onto another
static int fillBuffer(byte[] buffer, java.io.InputStream is)
          Fill a buffer as much as we can from InputStream.
static java.lang.String readString(java.io.InputStream is)
          Read a string from an input stream using the default encoding.
static java.lang.String readString(java.io.InputStream is, java.lang.String encoding)
          Read a string from an input stream using a specific encoding.
static java.lang.String readString(java.io.Reader reader)
          Read a string from a reader.
static java.lang.String readUTF(java.io.ObjectInput in)
          Read a UTF string as written by writeUTF.
static void writeUTF(java.io.ObjectOutput out, java.lang.String s)
          Writes a UTF string to be read by readUTF().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamUtil

public StreamUtil()
Method Detail

close

public static java.io.OutputStream close(java.io.OutputStream s)
Call close on an output stream and ignore any exception.

Parameters:
s - the stream to call .close() on
Returns:
OuputStream null

close

public static java.io.InputStream close(java.io.InputStream s)
Call close on an input stream and ignore any exception.

Parameters:
s - the stream to call .close() on
Returns:
InputStream null

close

public static java.io.Writer close(java.io.Writer w)
Call close on a Writer and ignore any exception.

Parameters:
s - the Writer to call .close() on
Returns:
Writer null

close

public static java.io.Reader close(java.io.Reader r)
Call close on a Reader and ignore any exception.

Parameters:
s - the Reader to call .close() on
Returns:
Reader null

copyStream

public static long copyStream(java.io.InputStream is,
                              java.io.OutputStream os)
                       throws java.io.IOException
Copy contents of one stream onto another

Parameters:
is - input stream
os - output stream
Throws:
java.io.IOException

copyStream

public static long copyStream(java.io.InputStream is,
                              java.io.OutputStream os,
                              int bufferSize)
                       throws java.io.IOException
Copy contents of one stream onto another

Parameters:
is - input stream
os - output stream
bufferSize - size of buffer to use for copy Note: there are cases where InputStream.available() returns > 0 but in actual fact the stream won't be able to read anything, so we need to handle the fact that InputStream.read() may return -1
Throws:
java.io.IOException

copyStream

public static long copyStream(java.io.Reader is,
                              java.io.Writer os)
                       throws java.io.IOException
Copy contents of one stream onto another

Parameters:
is - input stream
os - output stream
Throws:
java.io.IOException

copyStream

public static long copyStream(java.io.Reader is,
                              java.io.Writer os,
                              int bufferSize)
                       throws java.io.IOException
Copy contents of one character stream onto another

Parameters:
is - input stream
os - output stream
bufferSize - size of buffer to use for copy Note: there are cases where InputStream.available() returns > 0 but in actual fact the stream won't be able to read anything, so we need to handle the fact that InputStream.read() may return -1
Throws:
java.io.IOException

readUTF

public static java.lang.String readUTF(java.io.ObjectInput in)
                                throws java.io.IOException
Read a UTF string as written by writeUTF. This handles the null strings

Throws:
java.io.IOException

writeUTF

public static void writeUTF(java.io.ObjectOutput out,
                            java.lang.String s)
                     throws java.io.IOException
Writes a UTF string to be read by readUTF(). This handles the null strings

Throws:
java.io.IOException

readString

public static java.lang.String readString(java.io.Reader reader)
                                   throws java.io.IOException
Read a string from a reader.

Throws:
java.io.IOException

readString

public static java.lang.String readString(java.io.InputStream is)
                                   throws java.io.IOException
Read a string from an input stream using the default encoding.

Throws:
java.io.IOException

readString

public static java.lang.String readString(java.io.InputStream is,
                                          java.lang.String encoding)
                                   throws java.io.IOException
Read a string from an input stream using a specific encoding.

Throws:
java.io.IOException

fillBuffer

public static int fillBuffer(byte[] buffer,
                             java.io.InputStream is)
                      throws java.io.IOException
Fill a buffer as much as we can from InputStream.

Throws:
java.io.IOException