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