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 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

      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 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
    • toObject

      public Object toObject(byte[] data) throws IOException, ClassNotFoundException
      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 occurs
      ClassNotFoundException - if the class of a serialized object cannot be found
    • 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