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) Deprecated, for removal: This API element is subject to removal in a future version.the Java serialization of data received from a service is unsafe: exchange JSON insteadstatic <T> TtoObject(InputStream inputStream, Class<T> class1) Deprecated, for removal: This API element is subject to removal in a future version.the Java serialization of data received from a service is unsafe: exchange JSON insteadstatic 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
@Deprecated(forRemoval=true) public static <T> T toObject(InputStream inputStream, Class<T> class1) throws IOException, ClassNotFoundException Deprecated, for removal: This API element is subject to removal in a future version.the Java serialization of data received from a service is unsafe: exchange JSON insteadConverts an input stream to an object, with the Java serialization. The stream may hold only an instance of the given class and the types ofjava.lang,java.utilandjava.time: any other class is rejected.- 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 foundInvalidClassException- if the stream holds a class that is not accepted
-
toObject
@Deprecated(forRemoval=true) public Object toObject(byte[] data) throws IOException, ClassNotFoundException Deprecated, for removal: This API element is subject to removal in a future version.the Java serialization of data received from a service is unsafe: exchange JSON insteadConverts the array of bytes into an object, with the Java serialization. The bytes may hold only the types ofjava.lang,java.utilandjava.time: any other class is rejected.- 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 foundInvalidClassException- if the bytes hold a class that is not accepted
-
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
-