org.apache.axiom.attachments.utils
Class IOUtils

java.lang.Object
  extended by org.apache.axiom.attachments.utils.IOUtils

public class IOUtils
extends java.lang.Object

Utility class containing IO helper methods


Method Summary
static byte[] getStreamAsByteArray(java.io.InputStream stream)
          Returns the contents of the input stream as byte array.
static byte[] getStreamAsByteArray(java.io.InputStream stream, int length)
          Returns the contents of the input stream as byte array.
static int readFully(java.io.InputStream in, byte[] b)
          Reads into a byte array.
static int readFully(java.io.InputStream in, byte[] b, int off, int len)
          Same as the normal in.read(b, off, len), but tries to ensure that the entire len number of bytes is read.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readFully

public static int readFully(java.io.InputStream in,
                            byte[] b)
                     throws java.io.IOException
Reads into a byte array. Ensures that the full buffer is read. Helper method, just calls readFully(in, b, 0, b.length)

Throws:
java.io.IOException
See Also:
readFully(java.io.InputStream, byte[], int, int)

readFully

public static int readFully(java.io.InputStream in,
                            byte[] b,
                            int off,
                            int len)
                     throws java.io.IOException
Same as the normal in.read(b, off, len), but tries to ensure that the entire len number of bytes is read.

Returns:
Returns the number of bytes read, or -1 if the end of file is reached before any bytes are read
Throws:
java.io.IOException

getStreamAsByteArray

public static byte[] getStreamAsByteArray(java.io.InputStream stream)
                                   throws java.io.IOException
Returns the contents of the input stream as byte array.

Parameters:
stream - the InputStream
Returns:
the stream content as byte array
Throws:
java.io.IOException

getStreamAsByteArray

public static byte[] getStreamAsByteArray(java.io.InputStream stream,
                                          int length)
                                   throws java.io.IOException
Returns the contents of the input stream as byte array.

Parameters:
stream - the InputStream
length - the number of bytes to copy, if length < 0, the number is unlimited
Returns:
the stream content as byte array
Throws:
java.io.IOException


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.