Package org.gcube.common.gxhttp.util
Class ContentUtils
java.lang.Object
org.gcube.common.gxhttp.util.ContentUtils
Manipulation of a response's content.
- Author:
- Manuele Simi (ISTI CNR), Luca Frosini (ISTI-CNR)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]toByteArray(InputStream input) Gets the contents of anInputStreamas abyte[].static byte[]toByteArray(Object obj) Converts an object to an array of bytestoObject(byte[] data) Converts the array of bytes into an object.static <T> TtoObject(InputStream inputStream, Class<T> class1) Converts an input stream to an object.static StringtoString(byte[] bytes) Converts a byte array to a string.
-
Constructor Details
-
ContentUtils
public ContentUtils()
-
-
Method Details
-
toByteArray
Converts an object to an array of bytes- Parameters:
obj- the object to convert- Returns:
- the bytes
- Throws:
IOException- if an I/O error occurs
-
toObject
public static <T> T toObject(InputStream inputStream, Class<T> class1) throws IOException, ClassNotFoundException Converts an input stream to an object.- Type Parameters:
T- the type of the object- Parameters:
inputStream- the input streamclass1- the class of the object- Returns:
- an instance of type "type"
- Throws:
IOException- if an I/O error occursClassNotFoundException- if the class of a serialized object cannot be found
-
toObject
Converts the array of bytes into an object.- Parameters:
data- the byte array to convert- Returns:
- the object
- Throws:
IOException- if an I/O error occursClassNotFoundException- if the class of a serialized object cannot be found
-
toByteArray
Gets the contents of anInputStreamas abyte[].- Parameters:
input- theInputStreamto read from- Returns:
- the requested byte array
- Throws:
NullPointerException- if the input is nullIOException- if an I/O error occurs
-
toString
Converts a byte array to a string.- Parameters:
bytes- the byte array to convert- Returns:
- the string
-