Class StandardConversions

java.lang.Object
org.infinispan.commons.dataconversion.StandardConversions

public final class StandardConversions extends Object
Utilities to convert between text/plain, octet-stream, java-objects and url-encoded contents.
Since:
9.2
  • Constructor Details

    • StandardConversions

      public StandardConversions()
  • Method Details

    • convertTextToText

      public static Object convertTextToText(Object source, MediaType sourceType, MediaType destinationType)
      Convert text content to a different encoding.
      Parameters:
      source - The source content.
      sourceType - MediaType for the source content.
      destinationType - the MediaType of the converted content.
      Returns:
      content conforming to the destination MediaType.
    • convertTextToOctetStream

      @Deprecated(forRemoval=true) public static byte[] convertTextToOctetStream(Object source, MediaType sourceType)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, without replacement.
      Converts text content to binary.
      Parameters:
      source - The source content.
      sourceType - MediaType for the source content.
      Returns:
      content converted as octet-stream represented as byte[].
      Throws:
      EncodingException - if the source cannot be interpreted as plain text.
    • convertTextToObject

      public static String convertTextToObject(Object source, MediaType sourceType)
      Converts text content to the Java representation (String).
      Parameters:
      source - The source content
      sourceType - the MediaType of the source content.
      Returns:
      String representation of the text content.
      Throws:
      EncodingException - if the source cannot be interpreted as plain text.
    • convertTextToUrlEncoded

      @Deprecated(forRemoval=true) public static String convertTextToUrlEncoded(Object source, MediaType sourceType)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, without replacement.
      Convert text format to a URL safe format.
      Parameters:
      source - the source text/plain content.
      sourceType - the MediaType of the source content.
      Returns:
      a String with the content URLEncoded.
      Throws:
      EncodingException - if the source format cannot be interpreted as plain/text.
    • convertOctetStreamToText

      @Deprecated(forRemoval=true) public static byte[] convertOctetStreamToText(byte[] source, MediaType destination)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, without replacment.
      Converts generic byte[] to text.
      Parameters:
      source - byte[] to convert.
      destination - MediaType of the desired text conversion.
      Returns:
      byte[] content interpreted as text, in the encoding specified by the destination MediaType.
    • convertOctetStreamToJava

      @Deprecated(forRemoval=true) public static Object convertOctetStreamToJava(byte[] source, MediaType destination, Marshaller marshaller)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, without replacement.
      Converts an octet stream to a Java object
      Parameters:
      source - The source to convert
      destination - The type of the converted object.
      Returns:
      an instance of a java object compatible with the supplied destination type.
    • convertJavaToOctetStream

      @Deprecated(forRemoval=true) public static byte[] convertJavaToOctetStream(Object source, MediaType sourceMediaType, Marshaller marshaller) throws IOException, InterruptedException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, with no replacement.
      Converts a java object to a sequence of bytes applying standard java serialization.
      Parameters:
      source - source the java object to convert.
      sourceMediaType - the MediaType matching application/x-application-object describing the source.
      Returns:
      byte[] representation of the java object.
      Throws:
      EncodingException - if the sourceMediaType is not a application/x-java-object or if the conversion is not supported.
      IOException
      InterruptedException
    • convertJavaToProtoStream

      public static byte[] convertJavaToProtoStream(Object source, MediaType sourceMediaType, org.infinispan.protostream.ImmutableSerializationContext ctx) throws IOException, InterruptedException
      Converts a java object to a sequence of bytes using a ProtoStream ImmutableSerializationContext.
      Parameters:
      source - source the java object to convert.
      sourceMediaType - the MediaType matching application/x-application-object describing the source.
      Returns:
      byte[] representation of the java object.
      Throws:
      EncodingException - if the sourceMediaType is not a application/x-java-object or if the conversion is not supported.
      IOException
      InterruptedException
    • convertJavaToText

      @Deprecated(forRemoval=true) public static byte[] convertJavaToText(Object source, MediaType sourceMediaType, MediaType destinationMediaType)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0 without replacement.
      Converts a java object to a text/plain representation.
      Parameters:
      source - Object to convert.
      sourceMediaType - The MediaType for the source object.
      destinationMediaType - The required text/plain specification.
      Returns:
      byte[] with the text/plain representation of the object with the requested charset.
    • decodeObjectContent

      @Deprecated(forRemoval=true) public static Object decodeObjectContent(Object content, MediaType contentMediaType)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, without replacement.
      Decode UTF-8 as a java object. For this conversion, the "type" parameter is used in the supplied MediaType. Currently supported types are primitives and String, plus a special "ByteArray" to describe a sequence of bytes.
      Parameters:
      content - The content to decode.
      contentMediaType - the MediaType describing the content.
      Returns:
      instance of Object according to the supplied MediaType "type" parameter, or if no type is present, the object itself.
      Throws:
      EncodingException - if the provided type is not supported.
    • convertCharset

      public static byte[] convertCharset(Object content, Charset fromCharset, Charset toCharset)
      Convert text content.
      Parameters:
      content - Object to convert.
      fromCharset - Charset of the provided content.
      toCharset - Charset to convert to.
      Returns:
      byte[] with the content in the desired charset.
    • decodeOctetStream

      @Deprecated(forRemoval=true) public static byte[] decodeOctetStream(Object input, MediaType octetStream)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, without replacement.
      Decode a octet-stream content that is not a byte[]. For this, it uses a special param called "encoding" in the "application/octet-stream" MediaType. The "encoding" param supports only the "hex" value that represents an octet-stream as a hexadecimal representation, for example "0xdeadbeef". In the absence of the "encoding" param, it will assume base64 encoding.
      Parameters:
      input - Object representing the binary content.
      octetStream - The MediaType describing the input.
      Returns:
      a byte[] with the decoded content.
    • bytesToHex

      @Deprecated(forRemoval=true) public static String bytesToHex(byte[] bytes)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • hexToBytes

      @Deprecated(forRemoval=true) public static byte[] hexToBytes(String hex)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • convertUrlEncodedToObject

      @Deprecated(forRemoval=true) public static Object convertUrlEncodedToObject(Object content)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 13.0 without replacement.
      Handle x-www-form-urlencoded as single values for now. Ideally it should generate a Map<String, String>
    • convertUrlEncodedToText

      @Deprecated(forRemoval=true) public static Object convertUrlEncodedToText(Object content, MediaType destinationType)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0 without replacement.
    • convertUrlEncodedToOctetStream

      @Deprecated(forRemoval=true) public static Object convertUrlEncodedToOctetStream(Object content)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0 without replacement.
    • urlEncode

      @Deprecated(forRemoval=true) public static String urlEncode(Object content, MediaType mediaType)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0 without replacement.
    • urlDecode

      @Deprecated(forRemoval=true) public static Object urlDecode(Object content)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0, without replacement.
    • convertOctetStreamToUrlEncoded

      @Deprecated(forRemoval=true) public static Object convertOctetStreamToUrlEncoded(Object content, MediaType contentType)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 13.0 without replacement.