Spring for Android

org.springframework.util
Class StreamUtils

java.lang.Object
  extended by org.springframework.util.StreamUtils

public abstract class StreamUtils
extends java.lang.Object

Simple utility methods for dealing with streams. The copy methods of this class are similar to those defined in FileCopyUtils except that all affected streams are left open when done. All copy methods use a block size of 4096 bytes.

Mainly for use within the framework, but also useful for application code.

Since:
2.0
Author:
Juergen Hoeller, Phillip Webb
See Also:
FileCopyUtils

Field Summary
static int BUFFER_SIZE
           
 
Constructor Summary
StreamUtils()
           
 
Method Summary
static void copy(byte[] in, java.io.OutputStream out)
          Copy the contents of the given byte array to the given OutputStream.
static int copy(java.io.InputStream in, java.io.OutputStream out)
          Copy the contents of the given InputStream to the given OutputStream.
static void copy(java.lang.String in, java.nio.charset.Charset charset, java.io.OutputStream out)
          Copy the contents of the given String to the given output OutputStream.
static byte[] copyToByteArray(java.io.InputStream in)
          Copy the contents of the given InputStream into a new byte array.
static java.lang.String copyToString(java.io.InputStream in, java.nio.charset.Charset charset)
          Copy the contents of the given InputStream into a String.
static java.io.InputStream nonClosing(java.io.InputStream in)
          Returns a variant of the given InputStream where calling close() has no effect.
static java.io.OutputStream nonClosing(java.io.OutputStream out)
          Returns a variant of the given OutputStream where calling close() has no effect.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

StreamUtils

public StreamUtils()
Method Detail

copyToByteArray

public static byte[] copyToByteArray(java.io.InputStream in)
                              throws java.io.IOException
Copy the contents of the given InputStream into a new byte array. Leaves the stream open when done.

Parameters:
in - the stream to copy from
Returns:
the new byte array that has been copied to
Throws:
java.io.IOException - in case of I/O errors

copyToString

public static java.lang.String copyToString(java.io.InputStream in,
                                            java.nio.charset.Charset charset)
                                     throws java.io.IOException
Copy the contents of the given InputStream into a String. Leaves the stream open when done.

Parameters:
in - the InputStream to copy from
Returns:
the String that has been copied to
Throws:
java.io.IOException - in case of I/O errors

copy

public static void copy(byte[] in,
                        java.io.OutputStream out)
                 throws java.io.IOException
Copy the contents of the given byte array to the given OutputStream. Leaves the stream open when done.

Parameters:
in - the byte array to copy from
out - the OutputStream to copy to
Throws:
java.io.IOException - in case of I/O errors

copy

public static void copy(java.lang.String in,
                        java.nio.charset.Charset charset,
                        java.io.OutputStream out)
                 throws java.io.IOException
Copy the contents of the given String to the given output OutputStream. Leaves the stream open when done.

Parameters:
in - the String to copy from
charset - the Charset
out - the OutputStream to copy to
Throws:
java.io.IOException - in case of I/O errors

copy

public static int copy(java.io.InputStream in,
                       java.io.OutputStream out)
                throws java.io.IOException
Copy the contents of the given InputStream to the given OutputStream. Leaves both streams open when done.

Parameters:
in - the InputStream to copy from
out - the OutputStream to copy to
Returns:
the number of bytes copied
Throws:
java.io.IOException - in case of I/O errors

nonClosing

public static java.io.InputStream nonClosing(java.io.InputStream in)
Returns a variant of the given InputStream where calling close() has no effect.

Parameters:
in - the InputStream to decorate
Returns:
a version of the InputStream that ignores calls to close

nonClosing

public static java.io.OutputStream nonClosing(java.io.OutputStream out)
Returns a variant of the given OutputStream where calling close() has no effect.

Parameters:
out - the OutputStream to decorate
Returns:
a version of the OutputStream that ignores calls to close

Spring for Android