org.deduced.utilities
Class ObjectUtilities

java.lang.Object
  extended by org.deduced.utilities.ObjectUtilities

public class ObjectUtilities
extends java.lang.Object

ObjectUtilities is used to host static utility methods to deal with java objects

Author:
Steve McDuff

Field Summary
private static int DEFAULT_READ_ARRAY_SIZE
          default read array size when reading an input stream
 
Constructor Summary
ObjectUtilities()
           
 
Method Summary
static
<E> E
callCloneOnObject(E valueToClone)
          Call the clone method on an object if it exists.
static
<T> T[]
enlargeArrayIfTooSmall(int size, T[] sourceArray)
          Enlarge an array if it is too small.
static byte[] inputStreamToByteArray(java.io.InputStream stream, int initialSize)
          convert an input stream to a byte array
static java.lang.String inputStreamToString(java.io.InputStream stream)
          convert an input stream to a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_READ_ARRAY_SIZE

private static final int DEFAULT_READ_ARRAY_SIZE
default read array size when reading an input stream

See Also:
Constant Field Values
Constructor Detail

ObjectUtilities

public ObjectUtilities()
Method Detail

callCloneOnObject

public static <E> E callCloneOnObject(E valueToClone)
Call the clone method on an object if it exists.

Type Parameters:
E - the type of object to clone
Parameters:
valueToClone - the value to clone
Returns:
the cloned value. Null if cloning failed.

inputStreamToString

public static java.lang.String inputStreamToString(java.io.InputStream stream)
                                            throws java.io.IOException
convert an input stream to a string

Parameters:
stream - the stream to convert
Returns:
the converted string
Throws:
java.io.IOException - if reading fails

inputStreamToByteArray

public static byte[] inputStreamToByteArray(java.io.InputStream stream,
                                            int initialSize)
                                     throws java.io.IOException
convert an input stream to a byte array

Parameters:
stream - the stream to convert
initialSize - the initial buffer size
Returns:
the converted byte array
Throws:
java.io.IOException - if reading fails

enlargeArrayIfTooSmall

public static <T> T[] enlargeArrayIfTooSmall(int size,
                                             T[] sourceArray)
Enlarge an array if it is too small. IF the array is big enough, Then the same array is reused, otherwise a new array is created that is big enough to hold enough elements to match the size parameter.

Type Parameters:
T - the type of objects contained in the array
Parameters:
size - the size the array must contain
sourceArray - the source array that might be reused if it is large enough
Returns:
the array that is guaranteed to be length >= size