Class ContentUtils

java.lang.Object
org.gcube.common.gxhttp.util.ContentUtils

public final class ContentUtils extends Object
Manipulation of a response's content.
Author:
Manuele Simi (ISTI CNR), Luca Frosini (ISTI-CNR)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Gets the contents of an InputStream as a byte[].
    static byte[]
    Converts an object to an array of bytes
    toObject(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 instead
    static <T> T
    toObject(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 instead
    static String
    toString(byte[] bytes)
    Converts a byte array to a string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ContentUtils

      public ContentUtils()
  • Method Details

    • toByteArray

      public static byte[] toByteArray(Object obj) throws IOException
      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 instead
      Converts an input stream to an object, with the Java serialization. The stream may hold only an instance of the given class and the types of java.lang, java.util and java.time: any other class is rejected.
      Type Parameters:
      T - the type of the object
      Parameters:
      inputStream - the input stream
      class1 - the class of the object
      Returns:
      an instance of type "type"
      Throws:
      IOException - if an I/O error occurs
      ClassNotFoundException - if the class of a serialized object cannot be found
      InvalidClassException - 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 instead
      Converts the array of bytes into an object, with the Java serialization. The bytes may hold only the types of java.lang, java.util and java.time: any other class is rejected.
      Parameters:
      data - the byte array to convert
      Returns:
      the object
      Throws:
      IOException - if an I/O error occurs
      ClassNotFoundException - if the class of a serialized object cannot be found
      InvalidClassException - if the bytes hold a class that is not accepted
    • toByteArray

      public static byte[] toByteArray(InputStream input) throws IOException
      Gets the contents of an InputStream as a byte[].
      Parameters:
      input - the InputStream to read from
      Returns:
      the requested byte array
      Throws:
      NullPointerException - if the input is null
      IOException - if an I/O error occurs
    • toString

      public static String toString(byte[] bytes)
      Converts a byte array to a string.
      Parameters:
      bytes - the byte array to convert
      Returns:
      the string